{ "course": "Algorithms-Design_and_Analysis", "course_id": "CO3031", "schema_version": "material.v1", "slides": [ { "page_index": 0, "chapter_num": 0, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_001.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_001.png", "page_index": 0, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:33:12+07:00" }, "raw_text": "Ho Chi Minh City University of Technology BK Faculty of Computer Science and Engineering TP.HCM 1 Design Algorithms s Analysis s and (C03031) Computer Science Program Instructor: Assoc. Prof. Dr. Vo Thi Ngoc Chau Email: chauvtn@hcmut.edu.vn Semester 2 - 2022-2023" }, { "page_index": 1, "chapter_num": 0, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_002.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_002.png", "page_index": 1, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:33:16+07:00" }, "raw_text": "BK Course Learning Outcomes TP.HCM 1. Able to analyze the complexity of the algorithms (recursive or iterative) and estimate the efficiency of the algorithms. 2. Improve the ability to design algorithms in different areas s by decomposing a computing problem into advanced algorithm design strategies. 3. Able to discuss NP-completeness. 2" }, { "page_index": 2, "chapter_num": 0, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_003.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_003.png", "page_index": 2, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:33:19+07:00" }, "raw_text": "BK References TP.HCM [1] Cormen, T. H., Leiserson, C. E, and Rivest, R. L. Introduction to Algorithms, The MiT Press, 2009. [2] Levitin, A., Introduction to the Design and Analysis of Algorithms, 3rd Edition, Pearson, 2012. [3] Sedgewick, R., A/gorithms in C++, Addison-Wesley 1998. [4] Weiss, M.A., Data Structures and Algorithm Analysis in C, TheBenjamin/Cummings Publishing, 1993. 3" }, { "page_index": 3, "chapter_num": 0, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_004.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_004.png", "page_index": 3, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:33:24+07:00" }, "raw_text": "BK Course Outline TP.HCM Chapter 1. Fundamentals 0 C Chapter 2. Divide-and-Conquer Strategy 0 Chapter 3. Decrease-and-Conquer Strategy 0 C Chapter 4. Transform-and-Conquer Strategy 0 Chapter 5. Dynamic Programming and Greedy 0 1 Strategies Chapter 6. Backtracking and Branch-and-Bound Chapter 7. NP-completeness 0 Chapter 8. Approximation Algorithms 0 1 4" }, { "page_index": 4, "chapter_num": 0, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_005.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_005.png", "page_index": 4, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:33:28+07:00" }, "raw_text": "Chapter 1 BK TP.HCM Fundamentals 1.1. Recursion and recurrence relations 0 1.2. Analysis of algorithms 1.3. Analysis of iterative algorithms 0 1.4. Analysis of recursive algorithms 1.5. Algorithm design strategies 0 1.6. Brute-force algorithm design 5" }, { "page_index": 5, "chapter_num": 0, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_006.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_006.png", "page_index": 5, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:33:32+07:00" }, "raw_text": "Chapter 2. BK Divide-and-Conquer TP.HCM Strategy 2.1. Divide-and-conquer strategy 0 2.2. Quicksort 0 2.3. Mergesort 0 2.4. External sorting 0 2.5. Binary search tree 0 6" }, { "page_index": 6, "chapter_num": 0, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_007.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_007.png", "page_index": 6, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:33:36+07:00" }, "raw_text": "Chapter 3. BK TP.HCM Decrease-and-Conguer Strategy 3.1. Decrease- and-conquer strategy 0 3.2. Insertion sort 0 3.3. Graph traversal algorithms 0 3.4. Topological sorting 0 3.5. Generating all permutations from a set 0 7" }, { "page_index": 7, "chapter_num": 0, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_008.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_008.png", "page_index": 7, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:33:39+07:00" }, "raw_text": "Chapter 4. BK TP.HCM Transform-and-Conguer Strategy 4.1. Transform-and-conquer strategy 4.2. Gaussian Elimination for solving a system of linear equations 4.3. Heaps and heapsort 4.4. Horner's rule for polynomial evaluation 4.5. String matching by Rabin-Karp algorithm 8" }, { "page_index": 8, "chapter_num": 0, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_009.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_009.png", "page_index": 8, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:33:44+07:00" }, "raw_text": "Chapter 5. BK TP.HCM Dynamic Programming and Greedy Strategies 5.1. Dynamic Programming 0 5.1.1. Matrix-chain multiplication 5.1.2. Longest common subsequence 5.1.3. (0-1) Knapsack problem 5.1.4. Warshall algorithm to find transitive closure 5.1.5. Floyd algorithm for the all-pairs shortest path problem 5.2. Greedy Algorithms 5.2.1. Activity-selection problem 5.2.2. Fractional knapsack problem 5.2.3. Huffman codes 5.2.4. Graph coloring 9" }, { "page_index": 9, "chapter_num": 0, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_010.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_010.png", "page_index": 9, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:33:48+07:00" }, "raw_text": "Chapter 6. BK TP.HCM Backtracking and Branch-and-Bound 6.1. Backtracking algorithms 6.1.1. The Knight's Tour problem 6.1.2. The Eight Queens problem 6.2. Branch-and-Bound algorithms 6.2.1. Traveling Salesman problem 10" }, { "page_index": 10, "chapter_num": 0, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_011.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_011.png", "page_index": 10, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:33:52+07:00" }, "raw_text": "Chapter 7. BK TP.HCM Np-completeness Z.1. Deterministic and Nondeterministic 0 Polynomial-time algorithms 7.2. NP-completeness 0 7.3. Cook's theorem 0 7.4. The halting problem 0 7.5. Some NP-complete problems 7.6. Some approaches to cope with 0 NP-complete problems 11" }, { "page_index": 11, "chapter_num": 0, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_012.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_012.png", "page_index": 11, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:33:56+07:00" }, "raw_text": "Chapter 8. BK Approximation Algorithms TP.HCM 8.1. Why approximation algorithms? 0 8.2. Vertex cover problem 0 8.3. Set cover problem 0 8.4. Traveling Salesman problem 8.5. Scheduling Independent tasks 0 8.6. Bin Packing problem 12" }, { "page_index": 12, "chapter_num": 0, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_013.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_013.png", "page_index": 12, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:34:00+07:00" }, "raw_text": "BK Grading Scheme TP.HCM Midterm exam: 40% Weekly in-class activities: 10% Group and individual tasks > Special situation : Weekly e-learning activities Midterm in-class exam: 30% References in one A4 sheet Final exam : 60% References in one A4 sheet 13" }, { "page_index": 13, "chapter_num": 0, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_014.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_014.png", "page_index": 13, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:34:03+07:00" }, "raw_text": "BK Grading TP.HCM Never copy from the others Never let the others copy from you Never be absent from class if not necessary In-class time less than 75% is not allowed! Never be absent from examination 14" }, { "page_index": 14, "chapter_num": 0, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_015.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_015.png", "page_index": 14, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:34:06+07:00" }, "raw_text": "BK Contact TP.HCM Assoc. Prof. Dr. Vo Thi Ngoc Chau o Email : chauvtn@hcmut.edu.vn Office hours: Thursday, 09:00-11:50 By appointment 15" }, { "page_index": 15, "chapter_num": 0, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_016.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_0/slide_016.png", "page_index": 15, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:34:09+07:00" }, "raw_text": "Algorithms Analysis and Design BK TP.HCM (C03031) gues uestior wstin questi answer question wuest quest tion question quest 16" }, { "page_index": 16, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_001.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_001.png", "page_index": 16, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:34:12+07:00" }, "raw_text": "Ho Chi Minh City University of Technology BK Faculty of Computer Science and Engineering TP.HCM Chapter 1: Fundamentals Algorithms Analysis Design and (C03031) Instructor: Assoc. Prof. Dr. Vo Thi Ngoc Chau Email: chauvtn@hcmut.edu.vn Semester 2 - 2022-2023" }, { "page_index": 17, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_002.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_002.png", "page_index": 17, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:34:16+07:00" }, "raw_text": "BK Course Learning Outcomes TP.HCM 1. Able to analyze the complexity of the algorithms (recursive or iterative) and estimate the efficiency of the algorithms. 2. Improve the ability to design algorithms in different areas s by decomposing a computing problem into advanced algorithm design strategies. 3. Able to discuss NP-completeness. 2" }, { "page_index": 18, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_003.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_003.png", "page_index": 18, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:34:20+07:00" }, "raw_text": "BK References TP.HCM [1] Cormen, T. H., Leiserson, C. E, and Rivest, R. L. Introduction to Algorithms, The MiT Press, 2009. [2] Levitin, A., Introduction to the Design and Analysis of Algorithms, 3rd Edition, Pearson, 2012. [3] Sedgewick, R., A/gorithms in C++, Addison-Wesley 1998. [4] Weiss, M.A., Data Structures and Algorithm Analysis in C, TheBenjamin/Cummings Publishing, 1993. 3" }, { "page_index": 19, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_004.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_004.png", "page_index": 19, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:34:26+07:00" }, "raw_text": "BK Course Outline TP.HCM Chapter 1. Fundamentals 0 Chapter 2. Divide-and-Conquer Strategy 0 Chapter 3. Decrease-and-Conquer Strategy 0 C Chapter 4. Transform-and-Conquer Strategy 0 Chapter 5. Dynamic Programming and Greedy 0 1 Strategies Chapter 6. Backtracking and Branch-and-Bound Chapter 7. NP-completeness 0 Chapter 8. Approximation Algorithms 0 1 4" }, { "page_index": 20, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_005.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_005.png", "page_index": 20, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:34:30+07:00" }, "raw_text": "Chapter 1 BK TP.HCM Fundamentals 1.1. Recursion and recurrence relations 0 1.2. Analysis of algorithms 1.3. Analysis of iterative algorithms 0 1.4. Analysis of recursive algorithms 1.5. Algorithm design strategies 0 1.6. Brute-force algorithm design 5" }, { "page_index": 21, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_006.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_006.png", "page_index": 21, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:34:34+07:00" }, "raw_text": "BK Quick Review TP.HCM What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any /egitimate input in a finite amount of time. problem algorithm input computer' output 6" }, { "page_index": 22, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_007.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_007.png", "page_index": 22, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:34:37+07:00" }, "raw_text": "BK Quick Review TP.HCM What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any /egitimate input in a finite amount of time. sorting problem algorithm Quicksort, Mergesort, .. input computer' output 5,3,2,8,1 1,2,3,5,8 7" }, { "page_index": 23, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_008.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_008.png", "page_index": 23, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:34:41+07:00" }, "raw_text": "BK Quick Review TP.HCM Iterative algorithms vs. Recursive algorithms 0 function factorial (N: integer): integer: N! = 1*2*3*...*(N-1)*N var i: integer: begin N! = N*(N-1) factorial := 1: for i:=2 to N do factorial := factorial*i: end; function factorial (N: integer): integer: begin if N = 0 then factorial := 1 else factorial := N*factorial (N-1) end; 8" }, { "page_index": 24, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_009.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_009.png", "page_index": 24, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:34:45+07:00" }, "raw_text": "BK Quick Review TP.HCM Iterative algorithms vs. Recursive algorithms 0 function factorial (N: integer): integer: N! = 1*2*3*...*(N-1)*N var i: integer: begin N! = N*(N-1) factorial := 1: for i:=2 to N do factorial := factorial*i: end; function factorial (N: integer): integer: begin if N = 0 then factorial := 1 Which one do you prefer? else factorial := N*factorial (N-1 WHY? Time, Memory Space? end; 9" }, { "page_index": 25, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_010.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_010.png", "page_index": 25, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:34:49+07:00" }, "raw_text": "factorial(10) factorial(10) 3628800 Recursion path 10*factorial(9) 10*9* 8*7*6*5*4*3*2*1*1 9*factorial(8) 8*7*6*5*4*3*2*1*1 8*factorial(7) 8*7*6*5*4*3*2*1*1 7*factorial(6) 7*6*5*4*3*2*1*1 6*factorial(5) 6*5*4*3*2*1*1 5*factorial(4) 5*4*3*2*1*1 4*factorial(3) 4*3*2*1*1 3*factorial(2) 3*2*1*1 2*factorial(1) 2*1*1 Recursive cases with smaller sizes 1*factorial(0) 1*1 Return path 1*1 Base case" }, { "page_index": 26, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_011.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_011.png", "page_index": 26, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:34:54+07:00" }, "raw_text": "BK Quick Review TP.HCM List the sequence of Fibonacci numbers 1, 1, 2, 3, 5, 8, 13, 21, 34, ... function fibonacci r (N: integer): integer; begin if N<= 1 then fibonacci := 1 else fibonacci := fibonacci (N-1) + fibonacci (N-2): end; How about these functions? function fibonacci i (N: integer): integer; var i: integer; F: array [0..max] of integer; //max>=N begin F[0] := 1: F[1] := 1: for i := 2 to N do F[i] := F[i-1]+ Fi-2 fibonacci := F[N]; end; 11" }, { "page_index": 27, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_012.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_012.png", "page_index": 27, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:35:00+07:00" }, "raw_text": "BK Quick Review TP.HCM List the sequence of Fibonacci numbers 1, 1, 2, 3, 5, 8, 13, 21, 34, ... Recursive tree F6 F5 FA F3 F3 F2 Fs F2 F2 F1 F1 Fo F1 Fo F1 Fo F4 F2 F2 F1 F1 F1 Fo F1 Fo F2 F2 F3 There exist several redundant F1 computations when using the F1 Fo Fo F2 recursive function to compute F1 Fibonacci numbers!!! 12 F1 Fo" }, { "page_index": 28, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_013.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_013.png", "page_index": 28, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:35:06+07:00" }, "raw_text": "BK Quick Review TP.HCM Data structures Mathematics n n(n + 1) Array 2 i=1 n Linked list 6 i=1 Stack n 2i = 2n+1 -1 i=0 Queue E=o ai = if a>1 a-1 Heap 1 E=o ai = if 0 1-a n n Tree :> CXj = C Xi i=1 i=1 Graph n n n xi+yi Xi + yi i=1 i=1 i=1 13" }, { "page_index": 29, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_014.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_014.png", "page_index": 29, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:35:10+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Hanoi Tower Move disks from beg to end using aux as a temporary holding area in such a way that smaller disks are always on top of larger disks and one disk is moved at a time beg aux end Input: Output: n disks at beg n disks at end no disk at aux and end no disk at beg and aux How many moves are needed if n disks are given? 14" }, { "page_index": 30, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_015.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_015.png", "page_index": 30, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:35:14+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Hanoi Tower beg end beg aux aux end The number of moves: n=1 C1 = 1 15" }, { "page_index": 31, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_016.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_016.png", "page_index": 31, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:35:18+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce The number of moves: Hanoi Tower n>1, (1) Cn = 2Cn-1 + 1 (2) beg end beg end aux aux (3) beg end beg aux aux end 16" }, { "page_index": 32, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_017.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_017.png", "page_index": 32, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:35:23+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Hanoi Tower procedure hanoi(n, beg, aux, end); (1) begin if n= 1 then writeln(beg, end) (3) else begin hanoi(n-1, beg, end, aux) : writeln(beg, end); hanoi(n-1, aux, beg, end); (2) end end; beg end aux The number of moves : n=1, C1 = 1 n>1, Cn = 2Cn-1 + 1 17" }, { "page_index": 33, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_018.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_018.png", "page_index": 33, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:35:27+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrence Recurrence relation A function of integer parameters Derived as a complexity of a recursive algorithm The number of moves made by a recursive algorithm for Hanoi Tower: n=1, C = 1 n>1,Cn = 2Cn-1+ 1 18" }, { "page_index": 34, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_019.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_019.png", "page_index": 34, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:35:30+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Recurrence relation A function of integer parameters Derived as a complexity of a recursive algorithm Solved by substitution iteratively 19" }, { "page_index": 35, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_020.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_020.png", "page_index": 35, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:35:35+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Recurrence relation A function of integer parameters Derived as a complexity of a recursive algorithm Solved by substitution iteratively > Further reading : Appendix B. Short Tutorial on Recurrence Relations [2], pp. 473-485 20" }, { "page_index": 36, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_021.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_021.png", "page_index": 36, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:35:38+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Solve recurrence relations by substitution iteratively The number of moves in Hanoi Tower: n=1, C1 = 1 n>1, Cn = 2Cn-1 + 1 21" }, { "page_index": 37, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_022.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_022.png", "page_index": 37, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:35:42+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Solve recurrence relations by substitution iteratively The number of moves in Hanoi Tower: n=1, C1 = 1 n>1, Cn = 2Cn-1 + 1 Cn = 2(2Cn-2 + 1) + 1 22" }, { "page_index": 38, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_023.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_023.png", "page_index": 38, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:35:46+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Solve recurrence relations by substitution iteratively The number of moves in Hanoi Tower: n=1, C1 = 1 n>1, Cn = 2Cn-1 + 1 Cn = 2(2Cn-2 + 1) + 1 Cn = 22Cn-2 + 2 + 1 23" }, { "page_index": 39, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_024.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_024.png", "page_index": 39, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:35:49+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Solve recurrence relations by substitution iteratively The number of moves in Hanoi Tower: n=1, C1 = 1 n>1, Cn = 2Cn-1 + 1 Cn = 2(2Cn-2 + 1) + 1 Cn = 22Cn-2 + 2 + 1 Cn = 22(2Cn-3 + 1) + 2 + 1 C, = 2n - 1 24" }, { "page_index": 40, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_025.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_025.png", "page_index": 40, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:35:52+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrence Solve recurrence relations by substitution iteratively n=1, C1 = 1 n>1, 25" }, { "page_index": 41, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_026.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_026.png", "page_index": 41, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:35:55+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Solve recurrence relations by substitution iteratively n=1, C1 = 1 n>1, Cn = 4Cn/2 + n3 Supposed: n = 2k 26" }, { "page_index": 42, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_027.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_027.png", "page_index": 42, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:35:58+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Solve recurrence relations by substitution iteratively n=1, C1 = 1 n>1, Cn = 4Cn/2 + n3 Supposed: n = 2k Cn is rewritten as: 27" }, { "page_index": 43, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_028.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_028.png", "page_index": 43, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:36:02+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Solve recurrence relations by substitution iteratively n=1, C1 = 1 n>1, Cn = 4Cn/2 + n3 Supposed: n = 2k Cn is rewritten as: Simplified as : + 2k 2k 2k 28" }, { "page_index": 44, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_029.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_029.png", "page_index": 44, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:36:06+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Solve recurrence relations by substitution iteratively n=1, C1 = 1 n>1, Cn = 4Cn/2 + n3 Supposed: n = 2k Cn is rewritten as: Simplified as : + 2k 2k 2k C 2k 2C 2k-1 + 2k*2k 2k 2k-1 29" }, { "page_index": 45, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_030.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_030.png", "page_index": 45, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:36:10+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Solve recurrence relations by substitution iteratively n=1, C1 = 1 Start substitution : n>1 Cn = 4Cn/2 + n3 2C 2 k-2 2(k-1) * 2(k-1)) + 2k * 2k 2 2k 2k-2 Supposed: n = 2k Cn is rewritten as: Simplified as : 2k 2k 2k C 2k 2C 2k-1 2 + 2k* 2k 2k 2k-1 30" }, { "page_index": 46, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_031.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_031.png", "page_index": 46, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:36:16+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrence Solve recurrence relations by substitution iteratively n=1, C1 = 1 Start substitution : n>1, Cn = 4Cn/2 + n3 C 2k 2C + 2(k-1) * 2(k-1) + 2k* 2k 2k 2k-2 Supposed: n = 2k Cn is rewritten as: + 2k-1* 2k + 2k * 2k 2k 2k-2 Simplified as : + 2k 2k 2k C 2k 2C 2k-1 + 2k *2k 2k 2k-1 31" }, { "page_index": 47, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_032.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_032.png", "page_index": 47, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:36:21+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrence Solve recurrence relations by substitution iteratively n=1, C1 = 1 Start substitution : n>1, Cn = 4Cn/2 + n3 C 2k 2C k-2 2 + 2(k-1) * 2(k-1) +2k*2k 2k Supposed: n = 2k Cn is rewritten as: + 2k-1* 2k + 2k* 2k 2k 2C2k-3 C 2k Simplified as : + 2k-1*2k +2k*2k 22 2k 2k-3 + 2k 2k 2k C 2k 2C. 2k-1 +2k*2k 2k 2k-1 32" }, { "page_index": 48, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_033.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_033.png", "page_index": 48, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:36:27+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Solve recurrence relations by substitution iteratively n=1, C1 = 1 Start substitution : n>1, Cn = 4Cn/2 + n3 C 2k 2C k-2 2 +2(k-1) * 2(k-1) + 2k*2k 2k Supposed: n = 2k Cn is rewritten as: 2k-1* 2k + 2k * 2k 2k 2C2k-3 Simplified as : + 2k-1*2k+ 2k*2k 22 2k 2k-3 + + 2k-2* 2k + 2k-1*2k +2k*2k 2k 2k 2k 2k C 2k 2C. 2k-1 +2k*2k 2k 2k-1 33" }, { "page_index": 49, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_034.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_034.png", "page_index": 49, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:36:34+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Solve recurrence relations by substitution iteratively n=1, C1 = 1 Start substitution : n>1, Cn = 4Cn/2 + n3 2 + 2(k-1) * 2(k-1) + 2k* 2k 2k 2k-2 Supposed: n = 2k C 2k Cn is rewritten as: k-2 + 2k-1* 2k +2k*2k 2k 2C k-3 22 k-2 + 2k-1* 2k + 2k* 2k 2k 2k-3 Simplified as : 23Czk-3 + 2k-2* 2k+ 2k-1* 2k+2k * 2k 2k 2k-3 + 2k 2k 2k 2kC2k-k C 2k 2C 2k-1 +2k* 2k 2k 2k-k 2k 2k-1 34" }, { "page_index": 50, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_035.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_035.png", "page_index": 50, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:36:42+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Solve recurrence relations by substitution iteratively n=1, C1 = 1 Start substitution : n>1, Cn = 4Cn/2 + n3 2 + 2(k-1) * 2(k-1) + 2k* 2k 2k 2k-2 Supposed: n = 2k C 2k Cn is rewritten as: k-2 + 2k-1* 2k +2k*2k 2k 2k-2 2C k-3 k-2 + 2k-1* 2k + 2k* 2k 22 2 2k 2k-3 Simplified as: 23 C zk-3 + 2k-2* 2k+ 2k-1* 2k+2k * 2k 2k 2k-3 + 2k 2k 2k 2kC2k-k C 2k +2k* 2k 2k 2k-k 2k 2k-1 2k C1 + 21*2k +...+2k-2*2k + 2k-1* 2k +2k*2k 2k 20 35" }, { "page_index": 51, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_036.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_036.png", "page_index": 51, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:36:48+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Solve recurrence relations by substitution iteratively n=1, C1 = 1 Start substitution : n>1, Cn = 4Cn/2 + n3 2 + 2(k-1) * 2(k-1) + 2k* 2k 2k 2k-2 Supposed: n = 2k C 2k Cn is rewritten as: k-2 + 2k-1*2k +2k* 2k 2k 2k-2 2k C2 Simplified as : ok-k 2k 2k-k +21*2k+...+2k-2*2k+2k-1*2k+2k*2k + 2k 2k 2k 2k 20 C 2k 2C 2k-1 +2k* 2k 2k 2k 2k-1 36" }, { "page_index": 52, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_037.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_037.png", "page_index": 52, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:36:54+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Solve recurrence relations by substitution iteratively n=1, C1 = 1 Start substitution : n>1, Cn = 4Cn/2 + n3 2 + 2(k-1) * 2(k-1) + 2k* 2k 2k 2k-2 Supposed: n = 2k C 2k Cn is rewritten as: k-2 + 2k-1*2k +2k* 2k 2k 2k-2 2k C2k-k Simplified as : 2k 2k-k +21*2k+...+2k-2*2k+2k-1*2k+2k*2k + 2k 2k 2k 2k 20 C 2k 2C 2k-1 +2k* 2k 2k 2k 2k-1 2k 37" }, { "page_index": 53, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_038.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_038.png", "page_index": 53, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:37:00+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Solve recurrence relations by substitution iteratively n=1, C1 = 1 Start substitution : n>1, Cn = 4Cn/2 + n3 2 + 2(k-1) * 2(k-1) + 2k* 2k 2k 2k-2 Supposed: n = 2k C 2k Cn is rewritten as: k-2 + 2k-1* 2k +2k*2k 2k 2k-2 k k-k 2k 2k-k Simplified as: 2k C1 +21* 2k +...+2k-2 * 2k +2k-1* 2k +2k*2k 2k 20 + 2k 2k 2k C 2k =2k +21*2k+...+2k-2*2k +2k-1* 2k +2k* 2k 2k C 2k +2k* 2k 2k 2k-1 38" }, { "page_index": 54, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_039.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_039.png", "page_index": 54, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:37:07+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Solve recurrence relations by substitution iteratively n=1, C1 = 1 Start substitution : n>1, Cn = 4Cn/2 + n3 2 + 2(k-1) * 2(k-1) + 2k* 2k 2k 2k-2 Supposed: n = 2k C 2k Cn is rewritten as: k-2 + 2k-1* 2k +2k*2k 2k 2k-2 k k-k 2k 2k-k Simplified as: 2k C1 +21* 2k+ ...+2k-2. * 2k +2k-1* 2k +2k*2k 2k 20 + 2k 2k 2k C 2k =2k +21*2k+...+2k-2*2k +2k-1* 2k +2k* 2k 2k C 2k +2k*2k 2k 2k-1 2k 39" }, { "page_index": 55, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_040.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_040.png", "page_index": 55, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:37:11+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrence Your turn: Solve recurrence relations by substitution iteratively (1.1.1) Cn = C + Cn-1 when n>1 C1 = d (1.1.2) Cn = 2Cn/2 + n2 when nz2 C1 = 1 (1.1.3) Cn = 2Cn/3 + 1 when nz2 C1 = 1 40" }, { "page_index": 56, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_041.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_041.png", "page_index": 56, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:37:16+07:00" }, "raw_text": "1.1. Recursion and BK TP.HCM relations recurrehce Your turn: Solve recurrence relations by substitution iteratively (1.1.1) Cn = C + Cn-1 when n>1 C1 = d (1.1.2) Cn = 2Cn/2 + n2 when nz2 C1 = 1 Cn = n(2n - 1) = 2n2 - n (1.1.3) Cn = 2Cn/3 + 1 when nz2 C1 = 1 41" }, { "page_index": 57, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_042.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_042.png", "page_index": 57, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:37:19+07:00" }, "raw_text": "BK 1.2. Analysis of algorithms TP.HCM Analysis of an algorithm: estimate the resources used by that algorithm. Memory space Resources: Computational time 42" }, { "page_index": 58, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_043.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_043.png", "page_index": 58, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:37:22+07:00" }, "raw_text": "BK 1.2. Analysis of algorithms TP.HCM Analysis of an algorithm: estimate the resources used by that algorithm. Memory space Resources: Computational time 43" }, { "page_index": 59, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_044.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_044.png", "page_index": 59, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:37:26+07:00" }, "raw_text": "BK 1.2. Analysis of algorithms TP.HCM Step 1: Characterize the data which is to be used 0 as input to the algorithm and to decide what type of analysis is appropriate. Worst, Average, Best cases Step 2: identify abstract operation upon which the algorithm is based. The number of abstract operations depends on a few quantities. Step 3: Proceed to the mathematical analysis to 0 find the values for each of the fundamental quantities. 44" }, { "page_index": 60, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_045.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_045.png", "page_index": 60, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:37:32+07:00" }, "raw_text": "BK 1.2. Analysis of algorithms TP.HCM Efficiency classes 0 Class Name Comments 1 constant Abstract operation is done a few times. A Iogarithmic algorithm does not take all the input logn logarithmic Into account. Abstract operation is done whenever the algorithm n linear scans the input of size n one by one. Divide-and-conquer algorithms with division by 2 : nlogn n-log-n Quicksort, Mergesort in the average case Algorithms with two embedded loops. Abstract n2 quadratic operation is done in the most inner loop. n3 cubic Algorithms with three embedded loops Typical for algorithms that generate all subsets of 2n exponential an n-element set Typical for algorithms that generate all permutations n! factorial of an n-element set." }, { "page_index": 61, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_046.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_046.png", "page_index": 61, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:37:42+07:00" }, "raw_text": "1E+158 9E+157 BK 8E+157 -logn TP.HCM 7E+157 n 6E+157 -nlogn 5E+157 -n2 4E+157 n3 3E+157 2E+157 en 1E+157 n! 0 10 100 1000 10000 100000 1000000 1.2E+18 1E+18 -logn 8E+17 n 6E+17 nlogn 4E+17 -n2 n3 2E+17 0 10 100 1000 10000 100000 1000000 logn nlogn n n n2 n3 en n! 10 3.321928 10 33.21928 100 1000 22026.47 3628800 100 6.643856 100 664.3856 10000 1000000 2.69E+43 9.3E+157 1000 9.965784 1000 9965.784 1000000 1E+09 10000 13.28771 10000 132877.1 1E+08 1E+12 100000 16.60964 100000 1660964 1E+10 1E+15 1000000 19.93157 1000000 19931569 1E+12 1E+18 46" }, { "page_index": 62, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_047.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_047.png", "page_index": 62, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:37:52+07:00" }, "raw_text": "30000 BK 25000 TP.HCM -logn 20000 n 15000 nlogn 10000 -n2 n3 5000 0 5 10 15 20 25 30 1000 900 800 700 -logn 600 500 n 400 nlogn 300 -n2 200 100 0 5 10 15 20 25 30 logn n n nlogn n2 n3 en n! S 2.321928 5 11.60964 25 125 148.4132 120 10 3.321928 10 33.21928 100 1000 22026.47 3628800 15 3.906891 15 58.60336 225 3375 20 4.321928 20 86.43856 400 8000 25 4.643856 25 116.0964 625 15625 30 4.906891 30 147.2067 900 27000 47" }, { "page_index": 63, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_048.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_048.png", "page_index": 63, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:37:56+07:00" }, "raw_text": "BK 1.2. Analysis of algorithms TP.HCM Big O's definition: A function.f(n) is said to be O(g(n)) if there exist positive constants c and no such that f(n) is less than or equal to cg(n) for all n no. f(n) = O(g(n)) if f(n) < cg(n),Vn no,no>0,c>0 cg(n) f(n) 1 1 n no fn=0gn) 48" }, { "page_index": 64, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_049.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_049.png", "page_index": 64, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:38:02+07:00" }, "raw_text": "There exists a positive constant c There exist positive constants c and c, such that there is a positive constant no such that there is a positive constant no such that .. cg(n) such that . . crg(n) f(n) f(n) C1g(n) n n no f(n) = O(g(n)) f(n) = O(g(n)) There exists a positive constant c such that there is a positive constant no such that ... f(n) cg(n) n no f(n) = Q( g(n)) 49" }, { "page_index": 65, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_050.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_050.png", "page_index": 65, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:38:08+07:00" }, "raw_text": "THEOREM If t1(n) e O(g1(n)) and t2(n) e 0(g2(n)),then t1(n} +t2(n) e O(max{81(n),82(n)}). (The analogous assertions are true for the 2 and @ notations as well.) Using limits for comparing orders of growth: 0 implies that t (n) has a smaller order of growth than g(n) t(n) lim implies that t (n) has the same order of growth as g(n) c > 11-00 g(n) implies that t(n) has a larger order of growth than g(n 8 Note that the first two cases mean that t(n) e O(g(n), the last two mean that t(n) e S2(g(n)), and the second case means that t(n) e @(g(n)). L'Hpital's rule t(n) t'(n) lim lim 11-7X g(n) 1-7X g'(n) [2] Levitin, A., Introduction to the Design and Analysis of Algorithms Addison Wesley, 2003, pp. 57 50" }, { "page_index": 66, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_051.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_051.png", "page_index": 66, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:38:11+07:00" }, "raw_text": "BK 1.2. Analysis of algorithms TP.HCM 1.1. Identify the upper bound of the time complexity of algorithm A which is: f(n) = 3n2/4 + 1. a. 3/4 b.n c.3n + 1 d. n2 f(n) = 3n2/4 + 1 = O(n2) 51" }, { "page_index": 67, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_052.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_052.png", "page_index": 67, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:38:15+07:00" }, "raw_text": "BK 1.2. Analysis of algorithms TP.HCM 1.1. Identify the upper bound of the time complexity of algorithm A which is: f(n) = 3n2/4 + 1. a. 3/4 b.n c.3n + 1 d.n2 f(n) = 3n2/4 + 1 = O(n2) Because: choose: c = 1, no = 2, g(n) = n2 3n2/4 + 1 n2 <>4 n2 a/ways true Vn > no <> f(n) < cg(n), Vn Z no-> f(n) = O(g(n)) = O(n2) 52" }, { "page_index": 68, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_053.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_053.png", "page_index": 68, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:38:19+07:00" }, "raw_text": "BK 1.2. Analysis of algorithms TP.HCM 1.1. Identify the upper bound of the time complexity of algorithm A which is: f(n) = 3n2/4 + 1. a. 3/4 b.n c.3n + 1 d.n2 f(n) = 3n2/4 + 1 = O(n2) Because: 3n2 +1 3n/2 3 lim 4 lim >f(n) = O(n2) f(n) = O(n2) n2 2n 4 n->0o n->0o 53" }, { "page_index": 69, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_054.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_054.png", "page_index": 69, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:38:23+07:00" }, "raw_text": "1.3. Analysis of BK TP.HCM iterative algorithms Given an iterative algorithm that finds the largest element in an array of n elements procedure MAX(A, n, max) /* Set max to the maximum of A(1:n) */ begin integer i, n; max := A[1]; for i:= 2 to n do if A[i]>max then max := A[i] end 54" }, { "page_index": 70, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_055.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_055.png", "page_index": 70, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:38:27+07:00" }, "raw_text": "1.3. Analysis of BK TP.HCM iterative algorithms Step 1: Characterize the data: one input parameter n Type of analysis: all cases s (worst, average, best) Step 2: 0 Abstract operation: comparison Step 3: How many times is comparison done when the algorithm runs on the input of n elements? > Your answer is ... 55" }, { "page_index": 71, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_056.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_056.png", "page_index": 71, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:38:31+07:00" }, "raw_text": "1.3. Analysis of BK TP.HCM iterative algorithms Given an iterative algorithm that finds the largest element in an array of n elements procedure MAX(A, n, max) /* Set max to the maximum of A(1:n) */ begin integer i, n; max := A[1] for i:= 2 to n do ifAi]>max then max := A[i] end The number of comparisons in all cases = the number of iterations of \"for\" loop n-1 56" }, { "page_index": 72, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_057.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_057.png", "page_index": 72, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:38:36+07:00" }, "raw_text": "1.3. Analysis of BK TP.HCM iterative algorithms Given an iterative algorithm that finds the largest element in an array of n elements procedure MAX(A, n, max) /* Set max to the maximum of A(1:n) */ begin integer i, n; max := A[1] for i:= 2 to n do ifAi>max then max := A[i] end The number of comparisons in all cases = the number of iterations of \"for\" loop = n-1 > f(n) = n-1 = O(n) 57" }, { "page_index": 73, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_058.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_058.png", "page_index": 73, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:38:42+07:00" }, "raw_text": "1.3. Analysis of BK TP.HCM iterative a algorithms Given the following program, what is its complexity in the 0 case when all the elements are unigue or when the two last elements are the same? It is supposed that comparison is chosen as abstract operation. function UniqueElements s(A,n) 3 8 true 2 4 0 1 begin false 5 2 1 3 7 7 for i:= 1 to n -1 do 2 9 3 false 1 1 8 4 7 6 4 5 false for j:= i + 1 to n do if A[i] = A[j] return false How many comparisons need to be done? return true end 58" }, { "page_index": 74, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_059.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_059.png", "page_index": 74, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:38:48+07:00" }, "raw_text": "1.3. Analysis of BK TP.HCM iterative a algorithms Given the following program, what is its complexity in the 0 case when all the elements are unigue or when the two last elements are the same? It is supposed that comparison is chosen as abstract operation. Step 1: one parameter n, function UniqueElements s(A,n) analysis case given (worst begin average, best?) for i:= 1 to n -1 do Step 2: abstract operation for j:= i + 1 to n do = comparison if A[i]=A[j] return false Step 3: how many comparisons have been return true done in this case? end 59" }, { "page_index": 75, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_060.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_060.png", "page_index": 75, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:38:54+07:00" }, "raw_text": "1.3. Analysis of BK TP.HCM iterative a algorithms Given the following program, what is its complexity in the 0 case when all the elements are unigue or when the two last elements are the same? It is supposed that comparison is chosen as abstract operation. Step 3: how many cmps? function UniqueElements s(A,n) i = 1, j = 2..n: n-1 cmps begin i = 2, j = 3..n: n-2 cmps for i:= 1 to n -1 do i = n-2, j = n-1..n: 2 cmps for j:= i + 1 to n do i = n-1, j = n..n: 1 cmps if A[i]=A[j] return false (n-1) + (n-2) + .. + 2 + 1 return true = n(n-1)/2 cmps Cn = n(n-1)/2 = O(n2) end 60" }, { "page_index": 76, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_061.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_061.png", "page_index": 76, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:38:59+07:00" }, "raw_text": "1.3. Analysis of BK TP.HCM iterative a algorithms Given the following program, what is its complexity in the 0 case when all the elements are unigue or when the two last elements are the same? It is supposed that comparison is chosen as abstract operation. Step 1: one parameter n, function UniqueElements s(A,n) analysis case given (worst begin average, best?) for i:= 1 to n -1 do Step 2: abstract operation for j:= i + 1 to n do = comparison if A[i]=A[j] return false Step 3: how many comparisons in this case? return true Cn = n(n-1)/2 = O(n2) end 61" }, { "page_index": 77, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_062.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_062.png", "page_index": 77, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:39:02+07:00" }, "raw_text": "1.3. Analysis of BK TP.HCM iterative algorithms Your turn : Algorithm for what problem = ? ALGORITHM GE(A[0..n -1, 0..n]) //Input: An n-by-n + 1 matrix A[0..n - 1, 0..n] of real numbers for i <- 0 to n -- 2 do for j - i +1to n -1do for k i to n do A[j,k]1, Cn = 2Cn-1 + 1 particular number? 65" }, { "page_index": 81, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_066.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_066.png", "page_index": 81, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:39:19+07:00" }, "raw_text": "1.4. Analysis of BK TP.HCM recursive algorithms Solve recurrence relations by substitution iteratively The number of moves in Hanoi Tower: n=1, C1 = 1 n>1, Cn = 2Cn-1 + 1 Cn = 2(2Cn-2 + 1) + 1 Cn = 22Cn-2 + 2 + 1 Cn = 22(2Cn-3 + 1) + 2 + 1 Cn = 23Cn-3 + 22 + 2 + 1 C, = 2n - 1 = O(2) 66" }, { "page_index": 82, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_067.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_067.png", "page_index": 82, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:39:23+07:00" }, "raw_text": "1.4. Analysis of BK TP.HCM recursive algorithms Given a following recursive algorithm, what is its complexity? Supposed that multiplication is abstract operation. algorithm S(n) // input: a positive integer n begin if n = 1 then return 1; else return S(n-1) + n*n*nj end return S(n) = 1 + 23 + 33 + .. + (n-1)3 + n3 67" }, { "page_index": 83, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_068.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_068.png", "page_index": 83, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:39:27+07:00" }, "raw_text": "1.4. Analysis of BK TP.HCM recursive algorithms Given a following recursive algorithm, what is its complexity? Supposed that multiplication is abstract operation. algorithm S(n) Base case: // input: a positive integer n no multiplication begin > C1 = 0 if n = 1 then return 1: else return S(n-1) + n*n*n end return S(n) = 1 + 23 + 33 + .. + (n-1)3 + n3 68" }, { "page_index": 84, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_069.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_069.png", "page_index": 84, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:39:32+07:00" }, "raw_text": "1.4. Analysis of BK TP.HCM recursive algorithms Given a following recursive algorithm, what is its complexity? Supposed that multiplication is abstract operation. algorithm S(n) Recursive case: // input: a positive integer n multiplications in S(n-1) begin and n*n*n > Cn = Cn-1 + 2 when n>1 if n = 1 then return 1; else return S(n-1) + n*n*n end return S(n) = 1 + 23 + 33 + .. + (n-1)3 + n3 69" }, { "page_index": 85, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_070.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_070.png", "page_index": 85, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:39:36+07:00" }, "raw_text": "1.4. Analysis of BK TP.HCM recursive algorithms Given a following recursive algorithm, what is its complexity? Supposed that multiplication is abstract operation. algorithm S(n) // input: a positive integer n begin if n = 1 then return 1; else return S(n-1) + n*n*nj end recurrence C1 = 0, relation + 2 when n> 1 70" }, { "page_index": 86, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_071.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_071.png", "page_index": 86, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:39:39+07:00" }, "raw_text": "1.4. Analysis of BK TP.HCM recursive algorithms Solve recurrence relations by substitution iteratively n=1, C1 = 0 n>1, 71" }, { "page_index": 87, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_072.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_072.png", "page_index": 87, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:39:42+07:00" }, "raw_text": "1.4. Analysis of BK TP.HCM recursive algorithms Solve recurrence relations by substitution iteratively n=1, C1 = 0 n>1, Cn = Cn-1 + 2 Cn = (Cn-2 + 2) + 2 72" }, { "page_index": 88, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_073.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_073.png", "page_index": 88, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:39:46+07:00" }, "raw_text": "1.4. Analysis of BK TP.HCM recursive algorithms Solve recurrence relations by substitution iteratively n=1, C1 = 0 n>1, Cn = Cn-1+ 2 Cn = (Cn-2 + 2) + 2 Cn = Cn-2 + 2*2 73" }, { "page_index": 89, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_074.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_074.png", "page_index": 89, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:39:49+07:00" }, "raw_text": "1.4. Analysis of BK TP.HCM recursive algorithms Solve recurrence relations by substitution iteratively n=1, C1 = 0 n>1, Cn = Cn-1+ 2 Cn = (Cn-2 + 2) + 2 Cn = Cn-2 + 2*2 Cn = (Cn-3 + 2) + 2*2 74" }, { "page_index": 90, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_075.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_075.png", "page_index": 90, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:39:52+07:00" }, "raw_text": "1.4. Analysis of BK TP.HCM recursive algorithms Solve recurrence relations by substitution iteratively n=1, C1 = 0 n>1, Cn = Cn-1 + 2 Cn = (Cn-2 + 2) + 2 Cn = Cn-2 + 2*2 Cn = (Cn-3 + 2) + 2*2 75" }, { "page_index": 91, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_076.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_076.png", "page_index": 91, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:39:56+07:00" }, "raw_text": "1.4. Analysis of BK TP.HCM recursive algorithms Solve recurrence relations by substitution iteratively n=1, C1 = 0 n>1, Cn = Cn-1 + 2 Cn = (Cn-2 + 2) + 2 Cn = Cn-2 + 2*2 Cn = (Cn-3 + 2) + 2*2 76" }, { "page_index": 92, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_077.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_077.png", "page_index": 92, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:39:59+07:00" }, "raw_text": "1.4. Analysis of BK TP.HCM recursive algorithms Solve recurrence relations by substitution iteratively n=1, C1 = 0 n>1, Cn = Cn-1 + 2 Cn = (Cn-2 + 2) + 2 Cn = Cn-2 + 2*2 Cn = (Cn-3 + 2) + 2*2 Cn = Cn-3 + 3*2 Cn = C1 + (n-1)*2 77" }, { "page_index": 93, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_078.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_078.png", "page_index": 93, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:40:03+07:00" }, "raw_text": "1.4. Analysis of BK TP.HCM recursive algorithms Solve recurrence relations by substitution iteratively n=1, C1 = 0 n>1, Cn = Cn-1 + 2 Cn = (Cn-2 + 2) + 2 Cn = Cn-2 + 2*2 Cn = (Cn-3 + 2) + 2*2 Cn = Cn-3 + 3*2 Cn = C1 + (n-1)*2 Cn = 2*(n-1) 78" }, { "page_index": 94, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_079.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_079.png", "page_index": 94, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:40:06+07:00" }, "raw_text": "1.4. Analysis of BK TP.HCM recursive algorithms Solve recurrence relations by substitution iteratively n=1, C1 = 0 n>1, Cn = Cn-1 + 2 Cn = (Cn-2 + 2) + 2 Cn = Cn-2 + 2*2 Cn = (Cn-3 + 2) + 2*2 Cn = Cn-3 + 3*2 Cn = C1 + (n-1)*2 Cn = 2*(n-1) = O(n) 79" }, { "page_index": 95, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_080.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_080.png", "page_index": 95, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:40:11+07:00" }, "raw_text": "1.4. Analysis of BK TP.HCM recursive algorithms Your turn: Abstract operation ? Complexity = ? ALGORITHM Minl(A[0..n - 1]) //Input: An array A[0..n - 1] of real numbers if n = 1 return A[0] else temp <- Minl(A[0..n - 2] if temp < A[n - 1]return temp else return A[n - 1] ALGORITHIM Min2(Al..r if [ = r return A[7] else temp1<- Min2(A[..1(l + r)/2]] temp2<-Min2(A[L(l +r)/2]+1.r] if temp1 < temp2 return temp1 eise return temp2 80" }, { "page_index": 96, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_081.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_081.png", "page_index": 96, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:40:17+07:00" }, "raw_text": "1.4. Analysis of BK TP.HCM recursive algorithms Your turn: Abstract operation ? Complexity = ? ALGORITHM Minl(A[0..n -1] Comparison //Input: An array A[0..n - 1] of real numbers if n = 1 return A[0] Cn = Cn-1+ 1,n>1 else temp <- Minl(A[0..n - 2]) C1 = 0 if temp A[n - 1]return temp Cn = n-1 = O(n) else return A[n - 1] ALGORITHIM Min2(A[l..rD if [ =r return A[7] elsetemp1 <- Min2(A[.L(l + r)/2]] Cn = 2Cn/2 + 1,n>1 temp2K K Average-case BK algorithm analysis TP.HCM For average-case algorithm analysis, we have to characterize the inputs to the algorithm calculate the average number of times the abstract operation is executed calculate the average time complexity of the algorithm But Average-case algorithm analysis requires detailed mathematical arguments. It's difficult to characterize the input data encountered in practice 82" }, { "page_index": 98, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_083.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_083.png", "page_index": 98, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:40:25+07:00" }, "raw_text": "k >K K Average-case BK algorithm TP.HCM analysis Steps for average-case analysis of an algorithm A: 1. Determine the sampling space which represents the possible cases of input data (of size n). Assume: the sampling space S = {I1, I,..., Ik} 2. Determine a probability distribution p in S which represents the likelihood that each case I; (i=1..k) of the input data may occur. 3. Calculate the total number of times for abstract operation that the algorithm A excecutes to deal with a case I; of input data in S. Let v() denote the total number of times abstract operation is executed by the algorithm A when input data belong to the case I. 4. Calculate the average of the total number of times for abstract operation by using the following formula: 83" }, { "page_index": 99, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_084.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_084.png", "page_index": 99, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:40:30+07:00" }, "raw_text": "K k >K Average-case BK algorithm TP.HCM analysis l c Given an array A with n elements, find the location where the given value X occurs in array A. Algorithm Find(A, n, i) begin i := 1: while i<= n and X <> A[i] do < abstract i :- i+1: operation = end comparison A 5 2 0 3 8 9 7 1 4 6 x 3 return = 4 84" }, { "page_index": 100, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_085.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_085.png", "page_index": 100, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:40:34+07:00" }, "raw_text": "k >K K Average-case BK algorithm analysis TP.HCM In the case that X is available in the array, assume that the probability of the first match occurring in the i-th position of the array is the same for every i (i=1..n) and that probability is p = 1/n. The number of comparisons to find X at the 1st position is 1. The number of comparisons to find X at the 2nd position is 2 The number of comparisons to find X at the n-th position is n Therefore, the total number of comparisons in the average case is: Cn = 1.(1/n) + 2.(1/n) + ...+ n.(1/n) = (1 + 2 + ...+ n).(1/n) = (1+2+...+n)/n = n(n+1)/2.(1/n) = (n+1)/2 85" }, { "page_index": 101, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_086.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_086.png", "page_index": 101, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:40:38+07:00" }, "raw_text": "k >K K Average-case BK algorithm analysis TP.HCM In the case that X is available in the array, assume that the probability of the first match occurring in the i-th position of the array is the same for every i (i=1..n) and that probability is p = 1/n. The number of comparisons to find X at the 1st position is 1. The number of comparisons to find X at the 2nd position is 2 The number of comparisons to find X at the n-th position is n Therefore, the total number of comparisons in the average case is: Cn = 1.(1/n) + 2.(1/n) + ...+ n.(1/n) = (1 + 2 + ...+ n).(1/n) = (1+2+...+n)/n = n(n+1)/2.(1/n) = (n+1)/2 = O(n) 86" }, { "page_index": 102, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_087.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_087.png", "page_index": 102, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:40:42+07:00" }, "raw_text": "k >k >K Average-case BK algorithm TP.HCM analysis 1 Your turn: Extension: Analyze the complexity of FindO algorithm in the average case when we include the situtation where X is not found in A. Given the following program, what is its complexity in the average case if comparison is chosen as abstract operation? It is supposed that n = 3. procedure MAXMIN(A, n, max, min) /* Set max to the maximum and min to the minimum of A(1 :n) _ */ begin integer i, n; max := A[1]; min:= A[1] for i:= 2 to n do if A[i]> max then max := A[i] else if A[i] < min then min := A[i] end 87" }, { "page_index": 103, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_088.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_088.png", "page_index": 103, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:40:47+07:00" }, "raw_text": "K K K Average-case BK algorithm TP.HCM analysis g Your turn: Given the following program, what is its complexity in the average case if comparison is chosen as abstract operation? function UniqueElements s(A,n) begin for i:= 1 to n -1 do for j:= i + 1 to n do if A[i] = A[j] return false return true end 88" }, { "page_index": 104, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_089.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_089.png", "page_index": 104, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:40:51+07:00" }, "raw_text": "K K K Average-case BK algorithm TP.HCM analysis Your turn : Given the following program, what is its complexity in the average case if comparison is chosen as abstract operation? Algorithm closest-pair(X[1..n] An array X[1..n] of n real numbers begin Quicksort(X[1..n] for j := 2 to n do D[j-1]:= X[j] - X[j-1] min := 1; for j := 2 to n-1 do if D[j] < D[min] then min := j; write/n(X[min], X[min+1] end; 89" }, { "page_index": 105, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_090.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_090.png", "page_index": 105, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:40:56+07:00" }, "raw_text": "BK 1.5. Algorithm design strategies TP.HCM An Algorithm Design Strategy is a general approach to solving problems algorithmically that is applicable to a variety of problems from different areas of computing. Learning these strategies is very important for the following reasons: They provide guidance for designing algorithms for new problems. Algorithms are the cornerstone of computer science. Algorithm design strategies make it possible to classify and study algorithms. 90" }, { "page_index": 106, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_091.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_091.png", "page_index": 106, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:41:00+07:00" }, "raw_text": "BK 1.5. Algorithm design strategies TP.HCM Brute force Greedy approach 0 Naive string matching Graph coloring Divide-and-conquer Dynamic programming 0 Quicksort (0-1) Knapsack Decrease-and-conquer Backtracking Insertion sort Knight's tour Transform-and-conguer Branch and bound 0 Heapsort Traveling salesman problem 91" }, { "page_index": 107, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_092.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_092.png", "page_index": 107, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:41:04+07:00" }, "raw_text": "BK 1.6. Brute-force algorithm design TP.HCM Brute-force is a straightforward approach 0 to solving a problem, usually directly based on the problem statement and definitions of the concepts involved. Just do it\" the easiest to understand and the easiest to implement 92" }, { "page_index": 108, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_093.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_093.png", "page_index": 108, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:41:08+07:00" }, "raw_text": "BK 1.6. Brute-force algorithm design TP.HCM String matching: find al/ the occurrences of a pattern P in a text T. A text T of n characters: T[1..n] A pattern P of m characters: P[1..m] m < n A shift s shows that P occurs in 7 from s+1 T[s+1..s+m] = P[1..m] with ITl = n, lPl = m, and 0 < s < n - m Input: T = abcdefabaadef Input: T = abcdefabaadef P1 = def P2 = ab Output: P1 occurs with shifts: 3, 10. Output: P2 occurs with shifts: 0, 6. 93" }, { "page_index": 109, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_094.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_094.png", "page_index": 109, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:41:12+07:00" }, "raw_text": "BK 1.6. Brute-force algorithm design TP.HCM Input: T = abcdefabaadef Input: T = abcdefabaadef ??? P1 = def ??? P2 = ab Output: P1 occurs with shifts: 3, 10 Output: P2 occurs with shifts: 0, 6 abcdefabaadef Where is P1? Where is P2? Where is P..? 94" }, { "page_index": 110, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_095.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_095.png", "page_index": 110, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:41:17+07:00" }, "raw_text": "BK 1.6. Brute-force algorithm design TP.HCM Input: T = abcdefabaadef Input: T = abcdefabaadef ??? P1 = def ??? P2 = ab Output: P1 occurs with shifts: 3, 10 Output: P2 occurs with shifts: 0, 6 abcdefabaadef s = 0 s = 1 s = 2s = s = AOUND! s = n-$n=1n-m A sliding g window of size m (P1D) Check if subtext matches P1 iteratively 95" }, { "page_index": 111, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_096.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_096.png", "page_index": 111, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:41:20+07:00" }, "raw_text": "BK 1.6. Brute-force algorithm design TP.HCM procedure NAIVE-STRING-MATCHING (T, P); begin n: =T; m: = P: for s:= 0 to n - m do if P[1..m] = T[s+1,..,s+m] then end Input: T = abcdefabaadef P1 = def Output: P1 occurs with shifts: 3, 10 96" }, { "page_index": 112, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_097.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_097.png", "page_index": 112, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:41:23+07:00" }, "raw_text": "BK 1.6. Brute-force algorithm design TP.HCM begin n: = T m: = P: for s:= 0 to n - m do begin exit:= false: k:=1: while k m and not exit do if P[k] T[s+k] then exit := true Ino matching else k:= k+1; if not exit then end end 97" }, { "page_index": 113, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_098.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_098.png", "page_index": 113, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:41:27+07:00" }, "raw_text": "BK 1.6. Brute-force algorithm design TP.HCM Analysis of Naive-String-Matching Step 1: Characterize the data: one input parameter n for T and one input parameter m for p Type of analysis: all cases (worst, average, best) Step 2: Abstract operation: comparison Step 3: How many times is comparison done when the algorithm runs on T and P? > Your answer is ... 98" }, { "page_index": 114, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_099.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_099.png", "page_index": 114, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:41:31+07:00" }, "raw_text": "BK 1.6. Brute-force algorithm design TP.HCM begin Number of comparisons n: = TC m: = P = the total number of iterations for s:= 0 to n - m do = for iterations * while iterations begin = (n-m+1) * m exit:= false: k:=1: = 0((n-m+1)*m) while k < m and not exit do if P[k] T[s+k] thea cxit := true Ino matching else k:= k+1: if not exit then end end 99" }, { "page_index": 115, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_100.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_100.png", "page_index": 115, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:41:35+07:00" }, "raw_text": "BK 1.6. Brute-force algorithm design TP.HCM Analysis of Naive-String-Matching Step 1: Characterize the data: one input parameter n for T and one input parameter m for p Type of analysis: all cases (worst, average, best) Step 2: Abstract operation: comparison Step 3: How many times is comparison done when the algorithm runs on T and P? >Your answer is ... (n-m+1)*m = O((n-m+1)*m) 100" }, { "page_index": 116, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_101.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_101.png", "page_index": 116, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:41:39+07:00" }, "raw_text": "BK 1.6. Brute-force algorithm design TP.HCM Your turn : Design and analyze a brute-force algorithm for each following problem: Problem 1 : Given a weighted directed graph G of v vertices and E edges, find the least weighted path between vertex s and vertex t in G. Problem 2 : Given a list of T transactions each of which is made by a customer, a transaction includes some items in I, which is a finite list of all the items distinct in T. You are asked to find all the 3-item combinations that are bought by at least 50% customers. 101" }, { "page_index": 117, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_102.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_102.png", "page_index": 117, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:41:43+07:00" }, "raw_text": "BK Summary TP.HCM Understand the problem Decide on: computational means exact vs. approximate solving. data structure(s) algorithm design technigue Design an algorithm Prove correctness Figure 1.2. Algorithm design Analyze the algorithm and analysis process [2], pp. 10. Code the algorithm 102" }, { "page_index": 118, "chapter_num": 1, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_103.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_1/slide_103.png", "page_index": 118, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:41:48+07:00" }, "raw_text": "Algorithms Analysis and Design BK TP.HCM (C03031 uol guest questior Chapter 1. Fundamentals questi answer question tion vestm question que 1.1. Recursion and recurrence relations 1.2. Analysis of algorithms 1.3. Analysis of iterative algorithms 1.4. Analysis of recursive algorithms 1.5. Algorithm design strategies 1.6. Brute-force algorithm design 103" }, { "page_index": 119, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_001.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_001.png", "page_index": 119, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:41:52+07:00" }, "raw_text": "Ho Chi Minh City University of Technology BK Faculty of Computer Science and Engineering TP.HCM Chapter 2: Divide-and-conquer Algorithms Analysis Design and (C03031) Instructor: Assoc. Prof. Dr. Vo Thi Ngoc Chau Email: chauvtn@hcmut.edu.vn Semester 2 - 2022-2023" }, { "page_index": 120, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_002.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_002.png", "page_index": 120, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:41:57+07:00" }, "raw_text": "BK Course Learning Outcomes TP.HCM 1. Able to analyze the complexity of the algorithms (recursive or iterative) and estimate the efficiency of the algorithms. 2. Improve the ability to design algorithms in different areas s by decomposing a computing problem into advanced algorithm design strategies. 3. Able to discuss NP-completeness. 2" }, { "page_index": 121, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_003.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_003.png", "page_index": 121, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:42:01+07:00" }, "raw_text": "BK References TP.HCM [1] Cormen, T. H., Leiserson, C. E, and Rivest, R. L. Introduction to Algorithms, The MiT Press, 2009. [2] Levitin, A., Introduction to the Design and Analysis of Algorithms, 3rd Edition, Pearson, 2012. [3] Sedgewick, R., A/gorithms in C++, Addison-Wesley 1998. [4] Weiss, M.A., Data Structures and Algorithm Analysis in C, TheBenjamin/Cummings Publishing, 1993. 3" }, { "page_index": 122, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_004.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_004.png", "page_index": 122, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:42:07+07:00" }, "raw_text": "BK Course Outline TP.HCM Chapter 1. Fundamentals 0 1 2. Divide-and-Conquer Strategy Chapter 0 Chapter 3. Decrease-and-Conquer Strategy 0 C Chapter 4. Transform-and-Conquer Strategy 0 Chapter 5. Dynamic Programming and Greedy 0 1 Strategies Chapter 6. Backtracking and Branch-and-Bound Chapter 7. NP-completeness 0 Chapter 8. Approximation Algorithms 0 1 4" }, { "page_index": 123, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_005.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_005.png", "page_index": 123, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:42:11+07:00" }, "raw_text": "Chapter 2. BK Divide-and-Conquer TP.HCM Strategy 2.1. Divide-and-conquer strategy 0 2.2. Quicksort 0 2.3. Mergesort 0 2.4. External sorting 0 2.5. Binary search tree 0 5" }, { "page_index": 124, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_006.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_006.png", "page_index": 124, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:42:15+07:00" }, "raw_text": "BK 2.1. Divide-and-conquer s strategy TP.HCM problem of size n divide subproblem 2 subproblem 1 of size n/2 of size n/2 W Solution to Solution to subproblem 1 conquer subproblem 2 Solution to the original problem Divide-and-conguer Figure 4.1, [2l, pp. 124. 6" }, { "page_index": 125, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_007.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_007.png", "page_index": 125, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:42:19+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM The basic algorithm of Quicksort was invented in 1960 by C. A. R. Hoare. Quicksort is a \"divide-and-conquer\" method for sorting by partitioning the input file into two parts, then sorting each part independently. Partitioning rearranges the array to make the following three conditions hold: i. the element a[k] sorted in its final place in the array for some k ii. all the elements in a[left], .., a[k-1] less than or equal to a[k] iii. all the elements in a[k+1], ..., a[right] greater than or equal to a[k] 7" }, { "page_index": 126, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_008.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_008.png", "page_index": 126, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:42:23+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM 2.1. Quicksort - pivot = leftmost 0 8 8 9 2 0 0 6 11 9 2 0 0 2 4 6 7 8 8 9 9 11 8" }, { "page_index": 127, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_009.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_009.png", "page_index": 127, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:42:27+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM 2.1. Quicksort - pivot = leftmost 0 procedure quicksort (left, right:integer): var i: integer: begin if right > left then begin k := partitioning (left, right): quicksort (left, k-1); quicksort (k+1, right): end: end; 9" }, { "page_index": 128, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_010.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_010.png", "page_index": 128, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:42:34+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM 2.1. Quicksort - pivot = leftmost 0 8 8 9 2 1 0 0 6 11 4 9 Partitioning 8 8 9 2 1 0 0 7 6 11 4 9 Red: pivot From left to right Blue: j, Partitioning From right to left: Green: k, jk: swap (a[k], pivot 11" }, { "page_index": 130, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_012.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_012.png", "page_index": 130, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:42:43+07:00" }, "raw_text": "BK 2.2.Quicksort TP.HCM 2.1. Quicksort - pivot = leftmost 0 8 8 9 2 0 0 1 6 11 4 9 Partitioning 8 8 9 2 1 0 0 7 6 11 4 9 Red: pivot j -> From left to right: Blue: j, From right to left Green: k, jk: swap (a[k], pivot 12" }, { "page_index": 131, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_013.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_013.png", "page_index": 131, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:42:48+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM 2.1. Quicksort - pivot = leftmost 0 8 8 9 2 0 0 1 6 11 4 9 Partitioning 8 8 9 2 1 0 0 7 6 11 4 9 Red: pivot j -> k From left to right: Blue: j, From right to left Green: k, j k From left to right: 0 0 Blue: j, 8 4 9 2 7 6 11 8 9 From right to left Green: k, jk: swap (a[k], pivot 14" }, { "page_index": 133, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_015.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_015.png", "page_index": 133, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:43:00+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM 2.1. Quicksort - pivot = leftmost 0 8 8 9 2 0 0 1 6 11 4 9 Partitioning 8 8 9 2 1 0 0 7 6 11 4 9 Red: pivot j -> k From left to right: 0 0 Blue: j, 8 9 2 7 6 11 8 9 j -> From right to left Green: k, jk: swap (a[k], pivot 15" }, { "page_index": 134, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_016.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_016.png", "page_index": 134, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:43:07+07:00" }, "raw_text": "BK 2.2.Quicksort TP.HCM 2.1. Quicksort - pivot = leftmost 0 8 8 9 2 0 0 1 6 11 4 9 Partitioning 8 8 9 2 1 0 0 7 6 11 4 9 Red: pivot j -> k From left to right: 0 0 Blue: j, 8 9 2 7 6 11 8 9 j -> From right to left k Green: k, jk: swap (a[k], pivot 16" }, { "page_index": 135, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_017.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_017.png", "page_index": 135, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:43:15+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM 2.1. Quicksort - pivot = leftmost 0 8 9 2 1 0 0 8 6 11 4 9 Partitioning 8 8 9 2 1 0 0 7 6 11 4 9 Red: pivot j -> k From left to right: 0 0 Blue: j, 8 4 9 2 7 6 11 8 9 j -> From right to left: k Green: k, 8 4 6 2 1 0 0 7 9 11 8 9 j k From left to right 0 0 Blue: j, 8 4 9 2 7 6 11 8 9 j -> From right to left: k Green: k, 8 4 6 2 0 0 1 7 9 11 8 9 jk: swap (a[k], pivot 18" }, { "page_index": 137, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_019.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_019.png", "page_index": 137, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:43:29+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM 2.1. Quicksort - pivot = leftmost 0 8 9 2 0 0 8 1 6 11 4 9 Partitioning 9 2 0 0 8 8 1 7 6 11 4 9 Red: pivot j -> k From left to right 0 0 Blue: j, Z 8 4 9 2 7 6 11 8 9 j -> From right to left: k Green: k, 8 4 6 2 0 0 1 7 9 11 8 9 jk: swap (a[k], pivot 19" }, { "page_index": 138, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_020.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_020.png", "page_index": 138, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:43:38+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM 2.1. Quicksort - pivot = leftmost 0 8 9 2 1 0 0 8 6 11 4 9 Partitioning 9 2 0 0 8 8 1 7 6 11 4 9 Red: pivot j -> k From left to right 0 0 Blue: j, 8 4 9 2 1 7 6 11 8 9 j -> From right to left: k Green: k, 8 4 6 2 1 0 0 7 9 11 8 9 jk: swap (a[k], pivot 7 100 8 4 6 2 9 11 8 9 20" }, { "page_index": 139, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_021.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_021.png", "page_index": 139, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:43:47+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM 2.1. Quicksort - pivot = leftmost 0 8 9 2 1 0 0 8 6 11 4 9 Partitioning 8 9 2 0 0 8 1 7 6 11 4 9 Red: pivot j -> k From left to right 8 0 0 Blue: j, 4 9 2 1 7 6 11 8 9 j -> From right to left: k Green: k, 8 4 6 2 0 0 1 7 9 11 8 9 jk: swap (a[k], pivot 7 4 6 2 1 0 0 8 9 11 8 9 Unsorted Sorted Unsorted left 21 right" }, { "page_index": 140, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_022.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_022.png", "page_index": 140, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:43:54+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM 2.1. Quicksort - pivot = leftmost 0 8 9 2 1 0 0 8 6 11 4 9 Partitioning 8 9 2 0 0 8 1 7 6 11 4 9 Red: pivot j -> k From left to right 8 0 0 Blue: j, 4 9 2 1 7 6 11 8 9 j -> From right to left: k Green: k, 8 4 6 2 0 0 1 7 9 11 8 9 jk: swap (a[k], pivot 7 4 6 2 1 0 0 8 9 11 8 9 Unsorted Sorted Unsorted left => Quicksort right 22" }, { "page_index": 141, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_023.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_023.png", "page_index": 141, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:44:02+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM 2.1. Quicksort - pivot = leftmost 0 8 9 2 1 0 0 8 6 11 4 9 Partitioning 8 9 2 0 0 8 1 7 6 11 4 9 Red: pivot j -> k From left to right 8 0 0 Blue: j, 4 9 2 1 7 6 11 8 9 j -> From right to left: k Green: k, 8 4 6 2 1 0 0 7 9 11 8 9 j Quicksort" }, { "page_index": 142, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_024.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_024.png", "page_index": 142, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:44:10+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM 2.1. Quicksort - pivot = leftmost 0 8 9 2 1 0 0 8 6 11 4 9 Partitioning 8 9 2 0 0 8 1 7 6 11 4 9 Red: pivot j -> k From left to right 8 0 0 Blue: j, 4 9 2 1 7 6 11 8 9 j -> From right to left: k Green: k, 8 4 6 2 0 0 1 7 9 11 8 9 j left then begin j:=left; k:=right+1 repeat //start partitioning repeat j:=j+1 until a[j] >= a[left]; repeat k:=k-1 until a[k]<= a[left] if j< k then swap(a[j],a[k] until j>=k; swap(a[left],a[k]; //finish partitioning quicksort (left,k-1); quicksort (k+1,right) end; end; 25" }, { "page_index": 144, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_026.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_026.png", "page_index": 144, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:44:18+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM Time complexity for sorting n elements Abstract operation : comparison Best case: Average case: Worst case : Cn = (n2 + 3n - 4)/2 = O(n2) 26" }, { "page_index": 145, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_027.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_027.png", "page_index": 145, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:44:22+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM Time complexity for sorting n elements Abstract operation: comparison Best case : left pivot right Partitioning gives two halves of similar size: n/2. C1 = 0 2Cn/2 (n+1) or h Sort left Partitioning Sort left Partitioning + Sort right when j crosses k + Sort right when j & k coincide 27" }, { "page_index": 146, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_028.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_028.png", "page_index": 146, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:44:26+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM Time complexity for sorting n elements Abstract operation : comparison Best case: left pivot right Partitioning gives two halves of similar size: n/2. C1 = 0 or 28" }, { "page_index": 147, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_029.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_029.png", "page_index": 147, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:44:29+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM Time complexity for sorting n elements Abstract operation : comparison Best case: left pivot right Partitioning gives two halves of similar size: n/2. C1 = 0 or 29" }, { "page_index": 148, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_030.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_030.png", "page_index": 148, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:44:35+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM Time complexity for sorting n elements Abstract operation: comparison Average case: pivot right k=1 Partition split can k=2 left pivot right happen in k=3 left pivot right each position k=n-1 left pivot right (1 nCn = n(n +1) + Ek=1(Ck-1+ Cn-k) > (n -1)Cn-1 = (n -1)n + Ek=1(Ck-1 + Cn-1-k) 31" }, { "page_index": 150, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_032.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_032.png", "page_index": 150, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:44:43+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM Time complexity for sorting n elements Abstract operation: comparison Average case: Partition split can happen in each positions (1kn) with the same probability 1/n Co = C1 = 0 n 1Ek=1(Ck-1+ Cn-k) Cn = n +1 + n > nCn - (n -1)Cn-1 = n(n + 1) - (n -1)n + Cn-1+ Cn-1 > nCn =(n+1)Cn-1+ 2n Divide both sides by n(n + 1) 32" }, { "page_index": 151, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_033.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_033.png", "page_index": 151, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:44:49+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM Time complexity for sorting n elements Abstract operation : comparison Average case: Partition split can happen in each positions (1k nCn =(n+1)Cn-1+ 2n Cn 1 3 21 lnn + 1+ n+1-2 n + 1 Cn 2nlnn 1.38nlog2n 34" }, { "page_index": 153, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_035.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_035.png", "page_index": 153, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:44:56+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM Time complexity for sorting n elements Abstract operation: comparison Average case: Partition split can happen in each positions (1k nCn =(n+1)Cn-1+ 2n Cn 1 3 21 lnn + 1+ n+1-2 n + 1 Cn 2nlnn 1.38nlog2n 35" }, { "page_index": 154, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_036.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_036.png", "page_index": 154, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:45:00+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM Time complexity for sorting n elements Abstract operation: comparison Worst case : pivot right left pivot or Partitioning gives one empty and another of size n-1. Cn = (n+1) + n + (n-1) + + ... + 3 Cn = (n+1)(n+2)/2 - 3 Cn =(n2 + 3n - 4)/2 36" }, { "page_index": 155, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_037.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_037.png", "page_index": 155, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:45:03+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM Time complexity for sorting n elements Abstract operation: comparison Worst case : pivot right left pivot or Partitioning gives one empty and another of size n-1. Cn = (n+1) + n + (n-1) + + ... + 3 Cn = (n+1)(n+2)/2 - 3 Cn =(n2 + 3n - 4)/2 37" }, { "page_index": 156, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_038.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_038.png", "page_index": 156, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:45:07+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM Your turn: 2.2.1. Trace by hand Quicksort with pivot = leftmost 23,7,92, 6, 12, 24, 40,44, 20, 21 2.2.1.1) 44, 30, 50, 22, 60,55, 77, 55 2.2.1.2 2,4,6,8,10,10 (2.2.1.3) 2.2.1.4) 13,11,7,7,3,2,1 38" }, { "page_index": 157, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_039.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_039.png", "page_index": 157, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:45:10+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM Your turn : 2.2.2. Redesign Quicksort for pivot = rightmost. Is your Quicksort more efficient than original Quicksort? 2.2.3. Trace by hand your Quicksort with pivot = rightmost 23,7, 92, 6, 12, 24,40,44, 20, 21 2.2.3.1 44,30, 50,22, 60,55,77, 55 2.2.3.2) 2, 4, 6,8,10, 10 (2.2.3.3) 13, 11, 7, 7, 3, 2, 1 2.2.3.4 39" }, { "page_index": 158, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_040.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_040.png", "page_index": 158, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:45:13+07:00" }, "raw_text": "BK 2.2. Quicksort TP.HCM Your turn : 2.2.4. Design and analyze an algorithm A to find a median in an unsorted array of n elements 2.2.5. Combine algorithm A with Quicksort to achieve a new algorithm to sort an array of n elements. Is it more efficient than original Quicksort? Why? 40" }, { "page_index": 159, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_041.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_041.png", "page_index": 159, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:45:17+07:00" }, "raw_text": "BK 2.3. Mergesort TP.HCM To sort a given array of n elements, divide it in half, sort the two halves (recursively), and then merge the two halves together. Merging: given two sorted arrays a[1..M] and b[1..N] c[1..M+N] i:- 1: j :=1; for k:= 1 to M+N do if a[i]0 then begin m:=(right+left)/2; mergesort(left,m); mergesort(m+1,right): for i := m downto left do b[i] := a[i]; for j :=m+1 to right do b[right+m+1-j] := a[j]; //i := left: j := right; for k :=left to right do Merging on b: if b[i]2 +n NOTE: Mergesort needs memory space of n elements for merging! 44" }, { "page_index": 163, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_045.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_045.png", "page_index": 163, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:45:41+07:00" }, "raw_text": "BK 2.3. Mergesort TP.HCM Your turn: 2.3.1. Trace by hand Mergesort 23, 7, 92, 6, 12, 24,40,44, 20, 21 2.3.1.1 44, 30, 50, 22, 60, 55,77, 55 2.3.1.2) 2,4,6, 8,10,10 (2.3.1.3) 13, 11,7,7, 3, 2,1 2.3.1.4 45" }, { "page_index": 164, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_046.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_046.png", "page_index": 164, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:45:47+07:00" }, "raw_text": "BK 2.3. Mergesort TP.HCM Your turn : Algorithm secret(a[1..M1, b[1..N], c[1..M+N /a and b are sorted arrays begin 2.3.2. Given i:=1; j:=1; k:=1; whiIe i<=M and j<=N do secret, what does begin the algorithm if a[i] < b[j] then begin perform? If c[k] := a[i] ; i := i+1; comparison is an end else abstract operation, begin what is its complexity c[k] := b[j]; j:= j+1 end; in the best, worst, k := k+1; and average cases? end; f i = M+1 then for k1 := k+1 to M+N do begin c[k1] := b[j]; j:= j+1 end if j = N+1 then for k1 := k+1 to M+N do begin c[k1] := a[i]; i:= i+1 end; end; 46" }, { "page_index": 165, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_047.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_047.png", "page_index": 165, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:45:50+07:00" }, "raw_text": "BK 2.4. External sorting TP.HCM Sorting the large files stored in secondary storage is called external sorting. External sorting is very important in database management systems. When estimating the computational time of the algorithms that work on files in hard disks, we must consider the number of times we read a block to main Such operation is called block access or disk access. 47" }, { "page_index": 166, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_048.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_048.png", "page_index": 166, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:45:54+07:00" }, "raw_text": "BK 2.4. External sorting TP.HCM The most commonly used technique for external sorting is the external sort-merge algorithm. This external sorting method has two stages. create runs: b, = number of blocks, M = buffer size [b,/Mruns from any in-place in-memory sorting algorithm merge runs: one block for output, each block of the rest for each input run 48" }, { "page_index": 167, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_049.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_049.png", "page_index": 167, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:45:57+07:00" }, "raw_text": "BK 2.4. External sorting TP.HCM create runs: b./M runs from in-place in-memory sorting i = 0; repeat read M blocks of the file, or the rest of the file, whichever is smaller; sort the in-memory part of the file; write the sorted data to the run file R : i := i+1: until the end of the file: 49" }, { "page_index": 168, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_050.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_050.png", "page_index": 168, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:46:01+07:00" }, "raw_text": "BK 2.4. External sorting TP.HCM create runs: b./M runs from in-place in-memory sorting merge runs: one block for output, each block of the rest for each merging phase read one block of each of the N1 files R; into the buffer; //N1 <= M-1 repeat choose the first tuple (in sort order) among all buffer pages; write the tuple to the output and delete it from the buffer page; if the buffer page of any run R is empty and not end-of-file(Ri) then read the next block of R: into the buffer page; until all buffer pages are empty; 50" }, { "page_index": 169, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_051.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_051.png", "page_index": 169, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:46:05+07:00" }, "raw_text": "BK 2.4. External sorting TP.HCM g File: 2,3,9,1,5,6, 0,9,10,16,8,11,2, 15,9,4,2,0, 7,4, 5,3,12,13,1, 0 1 record/block, 26 records => br=26 blocks o M = 4 blocks Number of runs s =1br/M1= 7 Number of merging phases=logM-1br/MTl=2 2,3,9,1,5,6,0,9,10,16,8,11,2,15,9,4,2,0,7,4,5,3,12,13,1,0 Generate runs 1,2,3,9,0,5,6,9,8,10,11,16,2,4,9,15,0,2,4,7,3,5,12,13,0,1 51" }, { "page_index": 170, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_052.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_052.png", "page_index": 170, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:46:09+07:00" }, "raw_text": "BK 2.4. External sorting TP.HCM File: 2,3,9,1, 5,6,0, 9,10,16, 8, 11,2,15, 9,4,2,0, 7,4, 0 5,3, 12,13, 1, 0 1 record/block, 26 records => br=26 blocks M = 4 blocks 01 Number of runs =b/Ml= 7 0 Number of merging phases =logm-1br/MTl = 2 1,2,3,9,0,5,6,9,8,10,11,16,2,4,9,15,0,2,4,7,3,5,12,13,0,1 Merge in phase 1 0,1,2,3,5,6,8,9,9,10,11,16,0,2,2,3,4,4,5,7,9,12,13,15, 0,1 IMerge in phase 2 0,0,0,1,1,2,2,2,3,3,4,4,5,5,6,7,8,9,9,9,10,11,12,13,15,16 52" }, { "page_index": 171, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_053.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_053.png", "page_index": 171, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:46:12+07:00" }, "raw_text": "BK 2.4. External sorting TP.HCM Time complexity Abstract operation: b/ock access All the cases: 2b, log M-1 2b.+ 2b.log lb,/M17= 2 [b,/M]1+1 br = number of blocks, run merging M = buffer size rum generation 53" }, { "page_index": 172, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_054.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_054.png", "page_index": 172, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:46:16+07:00" }, "raw_text": "BK 2.4. External sorting TP.HCM Your turn: 2.4.1. Given the data file of 25 records with the following keys: 28, 3, 93, 10, 54, 65, 30, 90, 10, 69,8,22, 31, 5, 96,40, 85, 9, 39, 13, 8, 77, 10, 2, 9. Assume that one record fits in a block and memory buffer holds at most three page frames (3 blocks). During the merge stage, two page frames are used for input and one for output. Trace by hand the external sorting (external sort-merge) for the above data file. 54" }, { "page_index": 173, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_055.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_055.png", "page_index": 173, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:46:21+07:00" }, "raw_text": "BK 2.5.Binary search tree TP.HCM A binary search tree is a binary tree whose nodes contain elements of a set of orderable items, one element per node. K K 5 5 X s K K < X X < K K < X 4 10 4 10 1 30 30 22 31 22 30 15 15 22 20 55" }, { "page_index": 174, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_056.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_056.png", "page_index": 174, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:46:27+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM type link = 1 node; Insertion of a key node = record key, info: integer; into a binary search tree I, r: link end: var t, head, z: link: procedure tree_insert (v: integer; x: link): link: var p: link: begin repeat p: = x, if v < xT.key then x: = xT.l else x: = xT.r until x = z; /* z is a pseudo node for nil */ new(x); xT.key: = v; xT.1 := z; xT.r := z; /* create a new node */ if v< pT.key then pT.l := x /* p denotes the parent of the new node */ else pT.r := x; tree insert := x end 56" }, { "page_index": 175, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_057.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_057.png", "page_index": 175, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:46:31+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM K Insertion of a key, 3, into a binary search tree 5 X < K K < X 4 10 30 1 22 31 5 3 < 5 15 4 10 22 30 22 31 15 22 57" }, { "page_index": 176, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_058.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_058.png", "page_index": 176, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:46:36+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM K Insertion of a key, 3, into a binary search tree 5 X < K K < X 4 10 30 1 22 31 5 3 < 4 15 10 V 22 30 22 31 15 22 58" }, { "page_index": 177, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_059.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_059.png", "page_index": 177, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:46:40+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM K Insertion of a key, 3, into a binary search tree 5 X < K K < X 4 10 30 1 22 31 5 1 < 3 15 10 22 30 22 31 15 22 59" }, { "page_index": 178, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_060.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_060.png", "page_index": 178, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:46:44+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM K Insertion of a key, 3, into a binary search tree 5 X < K K < X 4 10 30 1 22 31 5 Insertion 15 of 3 10 22 30 22 31 3 15 22 60" }, { "page_index": 179, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_061.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_061.png", "page_index": 179, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:46:48+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM Searching in a binary search tree /* search for the node with key v in the binary search tree x */ function treesearch (v: integer, x: link): link; begin while v <> x1.key and x<> z do begin if v < xT.key then x := xT.I else x := xT.r end; treesearch := x end; 61" }, { "page_index": 180, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_062.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_062.png", "page_index": 180, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:46:52+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM When we need to search for an element of a given value v in a binary search tree, we do it recursively in the following manner. If the tree is empty, the search ends in failure. If the tree is not empty, we compare v with the tree's root K(r). If f they match, a desired element is found and the search can be stopped. Otherwise, we continue with the search in the Ieft subtree of the root if v < K(r) and in the right subtree if v > K(r). 62" }, { "page_index": 181, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_063.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_063.png", "page_index": 181, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:46:56+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM v = 15, is it in the following tree? 5 10 4 30 22 31 15 22 63" }, { "page_index": 182, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_064.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_064.png", "page_index": 182, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:46:59+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM v = 15, is it in the following tree? 5 5=15 ? 10 4 30 22 31 15 22 64" }, { "page_index": 183, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_065.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_065.png", "page_index": 183, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:47:02+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM v = 15, is it in the following tree? 5 5<15 10 4 30 22 31 15 22 65" }, { "page_index": 184, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_066.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_066.png", "page_index": 184, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:47:06+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM v = 15, is it in the following tree? 5 10=15 ? 10 4 30 22 31 15 22 66" }, { "page_index": 185, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_067.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_067.png", "page_index": 185, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:47:10+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM v = 15, is it in the following tree? 5 10 4 10<15 30 22 31 15 22 67" }, { "page_index": 186, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_068.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_068.png", "page_index": 186, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:47:13+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM v = 15, is it in the following tree? 5 10 4 30 30=15 ? 22 31 15 22 68" }, { "page_index": 187, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_069.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_069.png", "page_index": 187, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:47:17+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM v = 15, is it in the following tree? 5 10 4 30 15<30 22 31 15 22 69" }, { "page_index": 188, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_070.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_070.png", "page_index": 188, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:47:20+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM v = 15, is it in the following tree? 5 10 4 30 22 31 22=15 ? 15 22 70" }, { "page_index": 189, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_071.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_071.png", "page_index": 189, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:47:24+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM v = 15, is it in the following tree? 5 10 4 30 22 31 15<22 15 22 71" }, { "page_index": 190, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_072.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_072.png", "page_index": 190, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:47:27+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM v = 15, is it in the following tree? 5 10 4 30 22 31 15 15=15 ? FOUND 22 72" }, { "page_index": 191, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_073.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_073.png", "page_index": 191, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:47:31+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM Time complexity for searching the tree of n keys for a given query key Abstract operation: comparison Best case : Average case: 2Inn = 1.38logzn = O(logzn) Worst case: 73" }, { "page_index": 192, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_074.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_074.png", "page_index": 192, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:47:37+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM Time complexity for searching the tree of n keys for a given query key Abstract operation : comparison Average case: 2lnn = 1.38log,n = O(logzn) 5 5 5 A 10 4 10 4 10 30 30 1 30 22 31 22 31 22 31 Find 5: path(5) + 1 cmps Find 1: path(1) + 1 cmps Find 10: path(10) + 1 cmps 74" }, { "page_index": 193, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_075.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_075.png", "page_index": 193, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:47:43+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM Time complexity for searching the tree of n keys for a given query key Abstract operation : comparison Average case: 2Inn = 1.38log,n = O(logzn) A query key can be found at any node k in 5 the binary search tree. Each case has a 4 10 probability of 1/n and costs path(k) + 1. n n 1 1 1 30 (path(k) + 1) = - n + path(k) Cn = n n 22 31 k=1 k=1 lengths from the root to node k in the binary search tree of n nodes. Find 10: path(10) + 1 cmps 75" }, { "page_index": 194, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_076.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_076.png", "page_index": 194, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:47:50+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM Time complexity for searching the tree of n keys for a given query key Abstract operation : comparison Average case: A query key can be found at any node k in the binary search tree. Each case has a probability of 1/n and costs path(k) + 1. n n 1 (path(k) +1) = =(n + path(k) = 1 + n n. n k=1 k=1 k in the binary search tree of n nodes. n n 1 Dn path(k) = (Di-1 + (i - 1) + Dn-i + (n - i)) n 76 k=1 i=1" }, { "page_index": 195, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_077.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_077.png", "page_index": 195, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:47:56+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM Time complexity for searching the tree of n keys for a given query key Abstract operation : comparison Average case : A query key can be found at any node k in the binary search tree. Each case has a probability of 1/n and costs path(k) + 1. n n 1 (path(k) +1) = =( n + path(k) = 1 + n n n k=1 k=1 n n 1 Dn j (Di-1 + (i -1) + Dn-i + (n - i)) path(k) = n k=1 i=1 n cases of root i Left of root i Right of root i 77" }, { "page_index": 196, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_078.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_078.png", "page_index": 196, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:48:02+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM Time complexity for searching the tree of n keys for a given query key Abstract operation : comparison Average case: A query key can be found at any node k in the binary search tree. Each case has a probability of 1/n and costs path(k) + 1. n n 1 (path(k) +1) = =( n + path(k) = 1 + n n n k=1 k=1 n n 1 Dn path(k) = (Di-1 + (i -1) + Dn-i + (n - i)) n k=1 i=1 Dn n n 78" }, { "page_index": 197, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_079.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_079.png", "page_index": 197, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:48:08+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM Time complexity for searching the tree of n keys for a given query key Abstract operation : comparison Average case: A query key can be found at any node k in the binary search tree. Each case has a probability of 1/n and costs path(k) + 1. n n 1 7 D. (path(k) + 1) =- n + path(k) = 1 + - 1 n n n k=1 k=1 Dj +n-1 for n>1,D1 = 0 Y n nDn =2Et=1Di+ n(n -1) n-2 (n -1)Dn-1= 2 Di +(n -1)(n - 2) 79" }, { "page_index": 198, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_080.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_080.png", "page_index": 198, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:48:13+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM Time complexity for searching the tree of n keys for a given query key Abstract operation : comparison Average case : A query key can be found at any node k in the binary search tree. Each case has a probability of 1/n and costs path(k) + 1. n n 1 D. (path(k) + 1) = - 1 n + path(k) = 1 + n n n k=1 k=1 nDn -(n -1)Dn-1 = 2Dn-1 + 2(n -1) = 2Dn-1+ 2n nDn =(n+1)Dn-1 + 2n 80 Dn 2nlnn" }, { "page_index": 199, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_081.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_081.png", "page_index": 199, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:48:19+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM Time complexity for searching the tree of n keys for a given query key Abstract operation : comparison Average case: A query key can be found at any node k in the binary search tree. Each case has a probability of 1/n and costs path(k) + 1. n n 1 (path(k) +1) = =( n + path(k) = 1 + n n n n k=1 k=1 Dn ==Et=1(Di-1+ Dn-i+ (n -1)) 2 n n Dn 2nlnn Cn 1 + 2lnn = 2lnn = 1.38log2n = 0(log2n) 81" }, { "page_index": 200, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_082.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_082.png", "page_index": 200, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:48:25+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM Time complexity for searching the tree of n keys for a given query key Abstract operation : comparison Average case: A query key can be found at any node k in the binary search tree. Each case has a probability of 1/n and costs path(k) + 1. n n 1 (path(k) +1) = =( n + path(k) = 1 + n n n n k=1 k=1 Dn ==Et=1(Di-1+ Dn-i+ (n -1)) 2 n n Dn 2nlnn Cn 1 + 2lnn = 2lnn = 1.38log2n = 0(log2n) 82" }, { "page_index": 201, "chapter_num": 2, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_083.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_2/slide_083.png", "page_index": 201, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:48:30+07:00" }, "raw_text": "BK 2.5. Binary search tree TP.HCM Time complexity for searching the tree of n keys for a given query key Abstract operation: comparison Worst case: = n = O(n) A binary search tree is deformed as a linked list. 2 8 3 6 2,3,4,5 8,6,4,2 4 4 Insertion from left to right) Insertion from left to right) X 2 16" }, { "page_index": 221, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_017.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_017.png", "page_index": 221, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:50:21+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 8 8 9 9 9 > 2 17" }, { "page_index": 222, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_018.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_018.png", "page_index": 222, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:50:25+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 8 8 8 9 8 > 2 18" }, { "page_index": 223, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_019.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_019.png", "page_index": 223, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:50:30+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 & 8 8 9 8 > 2 19" }, { "page_index": 224, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_020.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_020.png", "page_index": 224, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:50:34+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 20" }, { "page_index": 225, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_021.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_021.png", "page_index": 225, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:50:39+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 2 8 8 9 9 > 1 21" }, { "page_index": 226, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_022.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_022.png", "page_index": 226, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:50:43+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 2 8 8 9 9 9 > 1 22" }, { "page_index": 227, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_023.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_023.png", "page_index": 227, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:50:48+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 2 8 & 8 9 8 > 1 23" }, { "page_index": 228, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_024.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_024.png", "page_index": 228, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:50:53+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 2 & 8 8 9 8 > 1 24" }, { "page_index": 229, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_025.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_025.png", "page_index": 229, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:50:58+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 2 2 8 8 9 2 > 1 25" }, { "page_index": 230, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_026.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_026.png", "page_index": 230, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:51:03+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 26" }, { "page_index": 231, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_027.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_027.png", "page_index": 231, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:51:10+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 1 2 8 8 9 9 > O 27" }, { "page_index": 232, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_028.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_028.png", "page_index": 232, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:51:15+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 1 2 8 8 9 9 9 > 0 28" }, { "page_index": 233, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_029.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_029.png", "page_index": 233, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:51:21+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 1 2 8 8 8 9 8 > 0 29" }, { "page_index": 234, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_030.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_030.png", "page_index": 234, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:51:26+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 1 2 & 8 8 9 8 > 0 30" }, { "page_index": 235, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_031.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_031.png", "page_index": 235, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:51:32+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 1 2 2 8 8 9 2 > 0 31" }, { "page_index": 236, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_032.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_032.png", "page_index": 236, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:51:38+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 1 1 2 8 8 9 1 > 0 32" }, { "page_index": 237, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_033.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_033.png", "page_index": 237, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:51:43+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 1 2 8 8 9 33" }, { "page_index": 238, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_034.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_034.png", "page_index": 238, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:51:49+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 O 1 2 8 8 9 0 1 2 8 8 9 9 9 > 0 34" }, { "page_index": 239, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_035.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_035.png", "page_index": 239, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:51:55+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending j order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 O 1 2 8 8 9 0 1 2 8 & 8 9 8 > 0 35" }, { "page_index": 240, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_036.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_036.png", "page_index": 240, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:52:02+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 O 1 2 8 8 9 0 1 2 8 8 8 9 8 > 0 36" }, { "page_index": 241, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_037.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_037.png", "page_index": 241, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:52:09+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 O 1 2 8 8 9 0 1 2 2 8 8 9 2 > 0 37" }, { "page_index": 242, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_038.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_038.png", "page_index": 242, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:52:15+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 O 1 2 8 8 9 0 1 1 2 8 8 9 1 > 0 38" }, { "page_index": 243, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_039.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_039.png", "page_index": 243, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:52:22+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 1 2 8 8 9 0 O 1 2 8 8 9 0 < 0 39" }, { "page_index": 244, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_040.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_040.png", "page_index": 244, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:52:29+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 O 1 2 8 8 9 O 1 2 8 8 9 0 0 1 2 8 8 9 9 9 > 7 40" }, { "page_index": 245, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_041.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_041.png", "page_index": 245, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:52:35+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 1 2 8 8 9 O 1 2 8 8 9 0 0 1 2 8 & 8 9 8 > 7 41" }, { "page_index": 246, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_042.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_042.png", "page_index": 246, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:52:42+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 1 2 8 8 9 O 1 2 8 8 9 0 0 1 2 & 8 8 9 8 > 7 42" }, { "page_index": 247, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_043.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_043.png", "page_index": 247, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:52:48+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 O 1 2 8 8 9 O 1 2 8 8 9 0 1 2 7 8 8 9 2 < 7 43" }, { "page_index": 248, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_044.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_044.png", "page_index": 248, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:52:55+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 1 2 8 8 9 0 O 1 2 8 8 9 0 0 1 2 7 8 8 9 0 1 2 6 7 8 8 9 44" }, { "page_index": 249, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_045.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_045.png", "page_index": 249, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:53:03+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 1 2 8 8 9 0 O 1 2 8 8 9 0 0 1 2 7 8 8 9 0 0 1 2 6 7 8 8 9 0 0 1 2 6 7 8 8 9 11 45" }, { "page_index": 250, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_046.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_046.png", "page_index": 250, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:53:13+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 1 2 8 8 9 0 O 1 2 8 8 9 0 0 1 2 7 8 8 9 0 1 2 6 7 8 8 9 0 0 1 2 6 7 8 8 9 11 0 0 1 2 4 6 7 8 8 9 11 46" }, { "page_index": 251, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_047.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_047.png", "page_index": 251, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:53:26+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Insertion sort - ascending order 8 8 9 2 1 0 0 7 6 11 4 9 8 8 8 8 8 9 2 8 8 9 1 2 8 8 9 1 2 8 8 9 0 1 2 8 8 9 0 0 1 2 7 8 8 9 0 1 2 6 7 8 8 9 0 0 1 2 6 7 8 8 9 11 0 1 2 4 6 7 8 8 9 11 0 0 1 2 4 6 7 8 8 9 9 11 47" }, { "page_index": 252, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_048.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_048.png", "page_index": 252, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:53:32+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM procedure insertion; var i; j; v:integer: begin for i:=2 to N do begin v:=a[i]; j:= i; while a[j-1]> v do begin a[j] := a[j-1]; //shift j:= j-1; end; a[j]:=v; end; end; 48" }, { "page_index": 253, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_049.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_049.png", "page_index": 253, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:53:36+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Time complexity for sorting n elements Abstract operation : comparison Best case : Average case: Cn = n(n-1)/4 = O(n2) Worst case: 49" }, { "page_index": 254, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_050.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_050.png", "page_index": 254, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:53:42+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Time complexity for sorting n elements Abstract operation: comparison Best case: 8 8 9 Best case when n elements are in order 0 cmps 8 Each of the 2nd to n-th elements needs 1 1 cmps 8 8 comparison to identify its position in a 8 8 9 1 cmps sorted array. Cn = n-1 = O(n) 50" }, { "page_index": 255, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_051.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_051.png", "page_index": 255, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:53:48+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Time complexity for sorting n elements Abstract operation: comparison Best case: 8 8 9 Best case when n elements are in order 0 cmps 8 Each of the 2nd to n-th elements needs 1 1 cmps 8 8 comparison to identify its position in a 8 8 9 1 cmps sorted array. Cn = n-1 = O(n) 51" }, { "page_index": 256, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_052.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_052.png", "page_index": 256, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:54:01+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Time complexity for sorting n elements Abstract operation: comparison Average case: a[i] can be inserted at any 8 8 9 2 1 0 0 7 position from 1 to i with 0 cmps 8 the same probability 1/i 1 cmps 8 8 At: i: 1 cmps 1 cmps 8 8 9 3 cmps 2 8 8 9 i-1: 2 cmps 4 cmps 1 2 8 8 9 5 cmps 0 1 2 8 8 9 1 : i-1 cmps 6 cmps O 0 1 2 8 8 9 n 4 cmps 0 0 1 2 7 8 8 9 Cn (1 + 2 +.. + (i - 1)) 52 i=2" }, { "page_index": 257, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_053.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_053.png", "page_index": 257, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:54:17+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Time complexity for sorting n elements Abstract operation: comparison Average case: a[i] can be inserted at any 8 8 9 2 1 0 0 7 position from 1 to i with 0 cmps 8 the same probability 1/i 1 cmps 8 8 n 1 cmps 8 8 9 Cn = 3 cmps 2 8 8 9 4 cmps i=2 1 2 8 8 9 n 5 cmps - 1 n(n - 1) 0 1 2 8 8 9 Cn = 6 cmps 0 0 1 2 8 8 9 2 2 * 2 i=2 4 cmps 0 0 1 2 7 8 8 9 = 0(n2) 53" }, { "page_index": 258, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_054.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_054.png", "page_index": 258, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:54:29+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Time complexity for sorting n elements Abstract operation: comparison Average case: a[i] can be inserted at any 8 8 9 2 1 0 0 7 position from 1 to i with 0 cmps 8 the same probability 1/i 1 cmps 8 8 n 1 cmps 8 8 9 Cn = 3 cmps 2 8 8 9 4 cmps i=2 1 2 8 8 9 n 5 cmps - 1 n(n - 1) 0 1 2 8 8 9 Cn = 6 cmps 0 0 1 2 8 8 9 2 2 * 2 i=2 4 cmps 0 0 1 2 7 8 8 9 = 0(n2) 54" }, { "page_index": 259, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_055.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_055.png", "page_index": 259, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:54:37+07:00" }, "raw_text": "BK 3.2. Insertion TP.HCM sort Time complexity for sorting n elements Abstract operation: comparison Worst case: Worst case when n elements are in 9 2 1 0 reverse order 0 cmps 9 Each of the 2nd to n-th elements needs 1 cmps 2 9 i-1 comparisons to identify its position 2 cmps 1 2 9 at the first position in the array. n 0 1 2 9 3 cmps n(n - 1) 2= 0(n2) Cn i (i - 1) = 2 i=2 55" }, { "page_index": 260, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_056.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_056.png", "page_index": 260, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:54:46+07:00" }, "raw_text": "BK 3.2. Insertion TP.HCM sort Time complexity for sorting n elements Abstract operation: comparison Worst case: Worst case when n elements are in 9 2 1 0 reverse order 0 cmps 9 Each of the 2nd to n-th elements needs 1 cmps 2 9 i-1 comparisons to identify its position 2 cmps 1 2 9 at the first position in the array. n 0 1 2 9 3 cmps n(n - 1) 2= 0(n2) Cn = (i - 1) = 2 i=2 56" }, { "page_index": 261, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_057.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_057.png", "page_index": 261, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:54:52+07:00" }, "raw_text": "BK 3.2. Insertion sort TP.HCM Your turn : 3.2.1. Trace by hand Insertion sort 23,7, 92, 6, 12, 24,40,44, 20, 21 (3.2.1.1) 44,30, 50, 22,60, 55, 77,55 (3.2.1.2) 2,4, 6, 8, 10, 10 (3.2.1.3) 13,11,7,7,3,2,1 (3.2.1.4) 3.2.2. What is Insertion sort's complexity for shifts? 57" }, { "page_index": 262, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_058.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_058.png", "page_index": 262, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:55:08+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM B A F D A 1 G Graph modeling to represent direct connections A B C D F G 1 A: -B A 1 1 0 0 0 0 0 B: -A-C-F B 1 1 1 0 1 0 0 C: -B-F F D: -I c 0 1 1 0 1 0 0 G F: -B-C-G D 0 0 0 1 0 0 1 G: -F F 0 1 1 0 1 1 0 I: -D G 0 0 0 0 1 1 0 1 0 0 0 1 0 0 1 Adjacency lists/matrix A map Graph representation in our real world in the computer's world 58" }, { "page_index": 263, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_059.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_059.png", "page_index": 263, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:55:24+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Time complexity for checking if an edge between vertex u and vertex v exists in a graph of V vertices and E edges Abstract operation: comparison Adjacency list: O(vD in the worst case Adjacency matrix: O(1) in all the cases A B C D F G I Adjacency matrix Adjacency lists A: -B A 1 1 0 0 0 0 0 B: -A-C-F B 1 1 1 0 1 0 0 C: -B-F D: -I c 0 1 1 0 1 0 0 F: -B-C-G D 0 0 0 1 0 0 1 G: -F F 0 1 1 0 1 1 0 I: -D G 0 0 0 0 1 1 0 1 0 0 0 1 0 0 1 59" }, { "page_index": 264, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_060.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_060.png", "page_index": 264, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:55:29+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Graph traversal: to \"visit\" every vertex and check every edge in the graph systematically. depth-first search (DFS) Recursive visits Stack-based visits breadth-first search (BFS) Queue-based visits 60" }, { "page_index": 265, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_061.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_061.png", "page_index": 265, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:55:38+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM type link = node Depth-first search node = record v: integer; next: link end; with recursive visits procedure list-dfs: var id, k: integer; val: array[1..maxV] of integer procedure visit (k: integer); var t: link: begin id:= id + 1; val[k]:= id; /* change the status of k to \"visited\" */ t:= adj[k]; / * find the neighbors of the vertex k */ while t<>z do /*z= empty*/ begin val[1..V : status of V vertices if val[tT.v] = 0 then visit(t.v) t:= tT.next val[k] = 0 if vertex k has not yet been visited end val[k] 0 if vertex k has already been visited end; begin val[k] := j implies that vertex k is the j-th visited vertex id:= 0: for k:= 1 to V do val[k]:= 0; /*initialize the status of all vertices */ for k:= 1 to V do if val[k] = 0 then visit(k) end; 61" }, { "page_index": 266, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_062.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_062.png", "page_index": 266, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:55:44+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Depth-first search with recursive visits 0 B D Starting at F: ??? A F G Graph A: -B B: -A-C-F C: -B-F D: -I F: -B-C-G G: -F I: -D Adjacency lists 62" }, { "page_index": 267, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_063.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_063.png", "page_index": 267, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:55:52+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Depth-first search with recursive visits 0 Starting at F: B D A F Visit F, check F's list: -B-C-G B D G A F Graph G A: -B B: -A-C-F Visit B, check B's list: -A-C-F C: -B-F D: -I B D F: -B-C-G A F G: -F I: -D C G Adjacency lists 63" }, { "page_index": 268, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_064.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_064.png", "page_index": 268, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:56:00+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Depth-first search with recursive visits 0 1 B Visit B, check B's list: -A-C-F D A F B A F G Graph G Visit A, check A's list: -B, check B's list: -A-C-F A: -B B: -A-C-F B C: -B-F D D: -I A F F: -B-C-G G: -F I: -D G Adjacency lists 64" }, { "page_index": 269, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_065.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_065.png", "page_index": 269, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:56:10+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Depth-first search with recursive visits 0 1 Visit A, check A's list: -B, check B's list: -A-C-F B D A F B D A F G Graph G Visit C, check C's list: -B-F, check B's list: -A-C-F A: -B B:-A-C-F check F's list: -B-C-G C: -B-F D: -I B F: -B-C-G A F G: -F I: -D G Adjacency lists 65" }, { "page_index": 270, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_066.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_066.png", "page_index": 270, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:56:19+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Depth-first search with recursive visits 0 1 Visit C, check C's list: -B-F, check B's list: -A-C-F B D check F's list: -B-C-G A F B D G A F Graph G Visit G, check G's list: -F A: -B B:-A-C-F C: -B-F B D D: -I F: -B-C-G A F G: -F I: -D Adjacency lists 66" }, { "page_index": 271, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_067.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_067.png", "page_index": 271, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:56:30+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Depth-first search with recursive visits 0 Visit G, check G's list: -F B D A F B A F G Graph Visit D, check D's list: -I A: -B B: -A-C-F C: -B-F B D D: -I F: -B-C-G A F G: -F I: -D Adjacency lists 67" }, { "page_index": 272, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_068.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_068.png", "page_index": 272, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:56:40+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Depth-first search with recursive visits 0 Visit D, check D's list: -I B D A F B A F G Graph Visit I, check I's list: -D A: -B B: -A-C-F C: -B-F B D D: -I F: -B-C-G A F G: -F I: -D I C Adjacency lists 68" }, { "page_index": 273, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_069.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_069.png", "page_index": 273, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:56:47+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Depth-first search with recursive visits 0 B D Starting at F : A F Visit F, check F's list Visit B, check B's list G Visit A, check A's list, B's list Graph Visit C, check C's list, B's list, F's list A: -B Visit G, check G's list B: -A-C-F C: -B-F Visit D, check D's list D: -I F: -B-C-G Visit I, check I's list G: -F I: -D Adjacency lists 69" }, { "page_index": 274, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_070.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_070.png", "page_index": 274, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:56:53+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM procedure dfs: Depth-first search procedure visit(n:vertex): with stack-based visits begin add n to the ready stack. while the ready stack is not empty do get a vertex from the stack, process it. and add any neighbor vertex that has not been processed to the stack if a vertex has already appeared in the stack, there is no need to push it to the stack end; begin Initialize status: for each vertex, say n, in the graph do if the status of n is \"not yet visited\" then visit(n) end; 70" }, { "page_index": 275, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_071.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_071.png", "page_index": 275, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:57:00+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Depth-first search with stack-based visits 0 B D Starting at F: ??? ??? A F G Graph stack A: -B B:-A-C-F C: -B-F D: -I F: -B-C-G G: -F I: -D Adjacency lists 71" }, { "page_index": 276, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_072.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_072.png", "page_index": 276, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:57:08+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Depth-first search with stack-based visits Starting at F : B D A F Push F into stack G Graph stack A: -B Visit F, Check F's list, Push B, C, G into stack B: -A-C-F C: -B-F B D: -I G F: -B-C-G A C G: -F B I: -D stack G Adjacency lists 72" }, { "page_index": 277, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_073.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_073.png", "page_index": 277, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:57:18+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Depth-first search with stack-based visits 0 Visit F, Check F's list, Push B, C, G into stack B D A F B D G A F C G B Graph stack G A: -B Visit G, Check G's list B: -A-C-F C: -B-F B D 1r D: -I C F: -B-C-G A F B G: -F I: -D stack G Adjacency lists 73" }, { "page_index": 278, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_074.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_074.png", "page_index": 278, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:57:29+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Depth-first search with stack-based visits 0 Visit G, Check G's list B D A F B D c 1F A F B G Graph stack G A: -B Visit C, Check C's list B: -A-C-F C: -B-F B D: -I B F: -B-C-G A F G: -F I: -D C stack G Adjacency lists 74" }, { "page_index": 279, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_075.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_075.png", "page_index": 279, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:57:36+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Depth-first search with stack-based visits 0 B D Visit C, Check C's list A F B D A F G Graph stack A: -B Visit B, Check B's list, Push A into stack B: -A-C-F C: -B-F B D: -I F: -B-C-G A F G: -F I: -D C stack G Adjacency lists 75" }, { "page_index": 280, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_076.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_076.png", "page_index": 280, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:57:46+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Depth-first search with stack-based visits 0 B D Visit B, Check B's list, Push A into stack A F B D A F G Graph stack G A: -B Visit A, Check A's list B: -A-C-F C: -B-F B D: -I F: -B-C-G A F G: -F I: -D C stack G Adjacency lists 76" }, { "page_index": 281, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_077.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_077.png", "page_index": 281, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:57:55+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Depth-first search with stack-based visits 0 Visit A, Check A's list B D A F B D A F G C Graph stack G A: -B Push D into stack B:-A-C-F C: -B-F B D: -I F: -B-C-G A F G: -F I: -D C stack G Adjacency lists 77" }, { "page_index": 282, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_078.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_078.png", "page_index": 282, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:58:03+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Depth-first search with stack-based visits 0 Push D into stack B D A F B D A F G C Graph stack G A: -B Visit D, Check D's list, Push I into stack B:-A-C-F C: -B-F B D D: -I F: -B-C-G A F G: -F I: -D C stack G Adjacency lists 78" }, { "page_index": 283, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_079.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_079.png", "page_index": 283, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:58:12+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Depth-first search with stack-based visits 0 Visit D, Check D's list, Push I into stack B D A F B D A F G C Graph stack G A: -B Visit I, Check I's list B: -A-C-F C: -B-F B D D: -I F: -B-C-G A F G: -F I: -D C stack G Adjacency lists 79" }, { "page_index": 284, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_080.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_080.png", "page_index": 284, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:58:20+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Depth-first search with stack-based visits B D Starting at F: ??? A F Visit F, Push B, C, G G Visit G Graph Visit C stack Visit B, Push A A: -B B: -A-C-F C: -B-F Visit A D: -I F: -B-C-G Visit D, Push I G: -F I: -D Visit 1 Adjacency lists 80" }, { "page_index": 285, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_081.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_081.png", "page_index": 285, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:58:27+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM procedure bfs; Breadth-first search 0 procedure visit(n: vertex): with queue-based visits begin add n to the ready queue; while the ready queue is not empty do get a vertex from the queue, process it, and add any neighbor vertex that has not been processed to the queue and change their status to ready end; begin Initialize status: for each vertex, say n, in the graph if the status of n is \"not yet visited\" then visit(n) end; 81" }, { "page_index": 286, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_082.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_082.png", "page_index": 286, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:58:34+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Breadth-first search with c queue-based visits B D Starting at F: ??? ??? A F G Graph A: -B B: -A-C-F queue C: -B-F D: -I F: -B-C-G G: -F I: -D Adjacency lists 82" }, { "page_index": 287, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_083.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_083.png", "page_index": 287, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:58:44+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Breadth-first search with queue-based visits Starting at F : B D A F Enqueue F F G Graph queue A: -B B: -A-C-F Visit F, Check F's list, Enqueue B, C, G C: -B-F D: -I B D B F: -B-C-G C A F G: -F G I: -D C G Adjacency lists queue 83" }, { "page_index": 288, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_084.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_084.png", "page_index": 288, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:58:54+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Breadth-first search 1 with c queue-based visits B D Visit F, Check F's list, Enqueue B, C, G A F B B C A G G Graph G queue A: -B B: -A-C-F Visit B, Check B's list, Enqueue A C: -B-F D: -I B D C F: -B-C-G G A F G: -F A I: -D C G Adjacency lists queue 84" }, { "page_index": 289, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_085.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_085.png", "page_index": 289, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:59:04+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Breadth-first search 1 with c queue-based visits B D Visit B, Check B's list, Enqueue A A F B C G A G A Graph G queue A: -B B: -A-C-F Visit C, Check C's list C: -B-F D: -I B D G F: -B-C-G A F A G: -F I: -D C G Adjacency lists queue 85" }, { "page_index": 290, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_086.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_086.png", "page_index": 290, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:59:14+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Breadth-first search 1 with c queue-based visits B D Visit C, Check C's list A F B G A A G Graph G queue A: -B B: -A-C-F Visit G, Check G's list C: -B-F D: -I B D A F: -B-C-G A F G: -F I: -D Adjacency lists queue 86" }, { "page_index": 291, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_087.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_087.png", "page_index": 291, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:59:23+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Breadth-first search 1 with c queue-based visits B D Visit G, Check G's list A F B 0 A A F G C Graph G queue A: -B B: -A-C-F Visit A, Check A's list C: -B-F D: -I B D F: -B-C-G A F G: -F I: -D C Adjacency lists queue 87" }, { "page_index": 292, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_088.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_088.png", "page_index": 292, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:59:30+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Breadth-first search 1 with c queue-based visits B Visit A, Check A's list D A F B D A F G Graph G queue A: -B B: -A-C-F Enqueue D C: -B-F D: -I B D D F: -B-C-G A F G: -F I: -D Adjacency lists queue 88" }, { "page_index": 293, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_089.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_089.png", "page_index": 293, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:59:38+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Breadth-first search with c 1 queue-based visits B D Enqueue D A F B D A G Graph G queue A: -B B: -A-C-F Visit D, Check D's list, Enqueue I C: -B-F D: -I B D F: -B-C-G A F G: -F I: -D C Adjacency lists queue 89" }, { "page_index": 294, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_090.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_090.png", "page_index": 294, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:59:48+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Breadth-first search 1 with c queue-based visits B D Visit D, Check D's list, Enqueue I A F B A F G C Graph G queue A: -B B: -A-C-F Visit I, Check I's list C: -B-F D: -I B D F: -B-C-G A F G: -F I: -D I C Adjacency lists queue 90" }, { "page_index": 295, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_091.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_091.png", "page_index": 295, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T16:59:55+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Breadth-first search 1 with c queue-based visits B D Starting at F: N ??? A F Visit F, Enqueue B, C, G C G Visit B, Enqueue A Graph Visit C Visit G A: -B B: -A-C-F queue C: -B-F Visit A D: -I F: -B-C-G Visit D, Enqueue I G: -F I: -D Visit I Adjacency lists 91" }, { "page_index": 296, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_092.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_092.png", "page_index": 296, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:00:03+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Time complexity of graph traversal on a graph of V vertices and E edges represented by adjacency lists o OOEl+lVD represented by an adjacency matrix o O(V2) 92" }, { "page_index": 297, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_093.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_093.png", "page_index": 297, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:00:09+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Time complexity of graph traversal on a graph of V vertices and E edges represented by adjacency lists o O(El+lVD Initialization : OVD Visit: All V vertices are processed: O(IVI) One vertex is linked to its neighbors. All E edges are accessed via adjacency lists for processing O(EI) 93" }, { "page_index": 298, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_094.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_094.png", "page_index": 298, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:00:14+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM Time complexity of graph traversal on a graph of V vertices and E edges represented by an adjacency matrix e O(1Vl2) Initialization: OVD) Visit: All V vertices are processed: O(VD) One vertex is linked to its neighbors. = All E edges are accessed via V-by-V matrix for processing. O(IVI2) 94" }, { "page_index": 299, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_095.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_095.png", "page_index": 299, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:00:22+07:00" }, "raw_text": "BK 3.3. Graph traversal algorithms TP.HCM g Your turn: 3.3.1. Traverse each following graph with vertex a as a starting vertex 3.3.1.1. Depth-First Search (DFS) using stack 3.3.1.2. Depth-First Search (DFS) using recursion 3.3.1.3. Breadth-First Search (BFS) using queue d d C d C a b a b g a b a e e e (G1) (G2) (G3) (G4) 95" }, { "page_index": 300, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_096.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_096.png", "page_index": 300, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:00:29+07:00" }, "raw_text": "BK 3.4. Topological s sorting TP.HCM Given a directed acyclic graph G, a topological sort T of G is a linear ordering that respects the partial ordering embedded in the vertex set V of the graph That means: if u < v in V (i.e. if there exists a path from u to v in G), then u appears before v in the linear ordering T. u: predecessor of v ... u...V.. before after v: successor of u Linear ordering T Applications of topological sorting : Find a sequence of courses for prerequisite requirements Model an assembly line ... and many ... with precedence relationships in domains 96" }, { "page_index": 301, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_097.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_097.png", "page_index": 301, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:00:37+07:00" }, "raw_text": "BK 3.4. Topological s sorting TP.HCM B Topological sorting T: A F A, B, G, F, C, D, I C Graph before after A: -B B: -C-F Find a topological sorting in a graph: C: D: -I F: -C DFS-based method G: -F I: - Source removal method Adjacency lists 97" }, { "page_index": 302, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_098.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_098.png", "page_index": 302, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:00:42+07:00" }, "raw_text": "BK 3.4. Topological s sorting TP.HCM DFS-based method Start with vertices with no predecessor, put them in the stack. while the stack is not empty do if the vertex at top of the stack has some successors then push all its successors (not yet processed) onto the stack else pop it from the stack, remove it from the graph and add it to the list Reverse the list to get the topological sorting 98" }, { "page_index": 303, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_099.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_099.png", "page_index": 303, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:01:02+07:00" }, "raw_text": "BK 3.4. Topological s sorting TP.HCM DFS-based method Starting at vertices with indegree = 0: B D c A F F F G G G G G C D D D D D G A A A A A stack stack stack stack stack Graph Push A, D, G Push F Push C Pop C Pop F ITITIT A: -B 1 B: -C-F D D D B C: - A A A A A A D: -I F: -C stack stack stack stack stack stack stack G: -F Pop G Push I Pop I Pop D Push B Pop B Pop A I: - DFS result: C, F, G,I, D, B,A Adjacency lists Topological sorting : A, B, D,I,G,F,C 99" }, { "page_index": 304, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_100.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_100.png", "page_index": 304, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:01:10+07:00" }, "raw_text": "BK 3.4. Topological s sorting TP.HCM Source removal method Start with vertices with no predecessor, put them in the queue. while the queue is not empty do remove the front vertex N of the queue for each neighbor vertex M of vertex N do delete the edge from N to M if the vertex M has no predecessor then add M to the rear of the queue endfor endwhile 100" }, { "page_index": 305, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_101.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_101.png", "page_index": 305, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:01:22+07:00" }, "raw_text": "BK 3.4. Topological s sorting TP.HCM Source removal method Starting at vertices with indegree = 0: B D A F A D D G G D G G B B G B 1 G queue queue queue queue queue Graph Enqueue A, D, G Dequeue A Enqueue B Dequeue D Enqueue I A: -B B 1 F C B: -C-F 1 F C: - D: -I F: -C G: -F queue queue queue queue queue queue queue I: - Dequeue G Dequeue B Enqueue F Dequeue I Dequeue F Enqueue C Dequeue C Adjacency lists Topological sorting : A, D, G, B, I, F, C 101" }, { "page_index": 306, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_102.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_102.png", "page_index": 306, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:01:32+07:00" }, "raw_text": "BK 3.4. Topological s sorting TP.HCM Source removal method Remove A B D B D (Dequeue A) A F F A D C G G D G G B Graph T Graph queue queue A: -B A: -B B: -C-F B: -C-F Topological sorting : C: - C: - D: -I D: -I A F: -C F: -C G: -F G: -F I: - I: - Adjacency lists Adjacency lists 102" }, { "page_index": 307, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_103.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_103.png", "page_index": 307, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:01:42+07:00" }, "raw_text": "BK 3.4. Topological s sorting TP.HCM Source removal method Remove D B B Dequeue D F F D G C G G G B B 1 Graph Graph queue queue A: -B A: -B B: -C-F B: -C-F Topological sorting : C: - C: - D: -I D: -I A, D F: -C F: -C G: -F G: -F I: - I: - Adjacency lists Adjacency lists 103" }, { "page_index": 308, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_104.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_104.png", "page_index": 308, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:01:50+07:00" }, "raw_text": "BK 3.4. Topological s sorting TP.HCM Source removal method Remove G B B Dequeue G F F G B C G B 1 1 Graph Graph queue queue A: -B A: -B B: -C-F B: -C-F Topological sorting : C: - C: - D: -I D: -I A, D, G F: -C F: -C G: -F G: -F I: - I: - Adjacency lists Adjacency lists 104" }, { "page_index": 309, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_105.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_105.png", "page_index": 309, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:01:59+07:00" }, "raw_text": "BK 3.4. Topological s sorting TP.HCM Source removal method Remove B B Dequeue B F F B 1 1 F Graph Graph queue queue A: -B A: -B B: -C-F B: -C-F Topological sorting : C: - C: - D: -I D: -I A,D, G, B F: -C F: -C G: -F G: -F I: - I: - Adjacency lists Adjacency lists 105" }, { "page_index": 310, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_106.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_106.png", "page_index": 310, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:02:06+07:00" }, "raw_text": "BK 3.4. Topological s sorting TP.HCM Source removal method Remove I Dequeue I F F 1 F F Graph Graph queue queue A: -B A: -B B: -C-F B: -C-F Topological sorting : C: - C: - D: -I D: -I Az D, G, B, I F: -C F: -C 6: -F G: -F I: - : Adjacency lists Adjacency lists 106" }, { "page_index": 311, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_107.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_107.png", "page_index": 311, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:02:13+07:00" }, "raw_text": "BK 3.4. Topological s sorting TP.HCM Source removal method Remove F (Dequeue F) F F c Graph Graph queue queue A: -B A: -B B: -C-F B: -C-F Topological sorting : C: - C: - D: -I D: -I Az D, G,B, I,F F: -C F: -C G: -F G: -F 1: : Adjacency lists Adjacency lists 107" }, { "page_index": 312, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_108.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_108.png", "page_index": 312, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:02:21+07:00" }, "raw_text": "BK 3.4. Topological s sorting TP.HCM Source removal method Remove c Dequeue C c Graph Graph queue queue A: -B A: -B B: -C-F B: -C-F Topological sorting : C: - C: D: -1 D: -I Az D, G, B,I, F, C F: -C F: -C 6: F G: -F 1: - : Adjacency lists Adjacency lists 108" }, { "page_index": 313, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_109.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_109.png", "page_index": 313, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:02:27+07:00" }, "raw_text": "BK 3.4. Topological s sorting TP.HCM Time complexity of finding topological sorting in a directed acyclic graph of V vertices and E edges, represented by adjacency lists Both DFS-based and source removal methods o(V 1EI l + 109" }, { "page_index": 314, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_110.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_110.png", "page_index": 314, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:02:36+07:00" }, "raw_text": "BK 3.4. Topological s sorting TP.HCM Your turn: 3.4.1. Find topological sorting in each graph 3.4.1.1. Stack-based DFS 3.4.1.2. Queue-based source remova a + C d g h t a b a b b W d S e e (G1) (G2) (G3) (G4) 110" }, { "page_index": 315, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_111.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_111.png", "page_index": 315, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:02:41+07:00" }, "raw_text": "BK 3.4. Topological s sorting TP.HCM Your turn : 3.4.2. Design and analyze an algorithm to find source vertices which have indegree = 0 in a graph represented by : 3.4.2.1. Adjacency matrix 3.4.2.2. Adjacency lists 3.4.3. Design and analyze an algorithm based on topological sorting to check if a graph has a cycle 111" }, { "page_index": 316, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_112.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_112.png", "page_index": 316, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:02:49+07:00" }, "raw_text": "3.5. Generating BK TP.HCM all from a set permutations Given a set of n elements A= {a1, az....,a,}, we want to generate all n! different permutations from that set. A smal/er instance of this problem is generating (n-1)! permutations for a subset with n -1 elements from the set A. Assume that this smaller problem has been already solved, we can solve the original problem by inserting the last remaining element into every possible position in each generated permutation of the subset with n-1 elements. 112" }, { "page_index": 317, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_113.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_113.png", "page_index": 317, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:02:55+07:00" }, "raw_text": "3.5. Generating BK TP.HCM all from a set permutations o PERM Algorithm 1. Set j:= 1 and write down the permutation <1> 2. set j:= j+1 do 4. 5. for i:= j-1 downto 1 do 6. set P:= P with the values assigned to positions i and i+1 switched and list P // end for loop at step 3 7. if j < n, then go to step 2 else stop. 113" }, { "page_index": 318, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_114.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_114.png", "page_index": 318, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:03:04+07:00" }, "raw_text": "3.5. Generating BK TP.HCM all from a set permutations For the convenience, assume that the set A is a set of n elements. This permutation set can be viewed as the set of all indices of the set of n elements s {a1,az....,an}. An example for a set of 3 elements: Initially 1 Insert 2 12 21 right to left Insert 3 123 132 312 213 231 321 right to left right to left 114" }, { "page_index": 319, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_115.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_115.png", "page_index": 319, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:03:12+07:00" }, "raw_text": "3.5. Generating BK TP.HCM all from a set permutations Time complexity for generating all permutations from a set of n elements Abstract operation: insertion of the remaining element to generate a permutation Stirling's formula n! can be approximated by the function 2IIn (n/e) 115" }, { "page_index": 320, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_116.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_116.png", "page_index": 320, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:03:20+07:00" }, "raw_text": "3.5. Generating BK TP.HCM all from a set permutations Your turn: 3.5.1. Given an array A of 4 elements 10, 7, 9, 5}, generate all the permutations of the elements in A. 3.5.2. Given HeapPermute, trace by hand this algorithm for n=2, 3, 4 Can the algorithm generate all the permutations? What is its complexity? ALGORITHIM HeapPermute(n) //Implements Heap's algorithm for generating permutations //Input: A positive integer n and a global array A[1..n] //Output: All permutations of elements of A if n = 1 write A else for i - 1 to n do HeapPermute(n - 1) if n is odd swap A[1]and A[n] else swap A[i] and A[n] 116" }, { "page_index": 321, "chapter_num": 3, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_117.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_3/slide_117.png", "page_index": 321, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:03:26+07:00" }, "raw_text": "Algorithms Analysis and Design BK TP.HCM (C03031) gues questior Chapter 3. Decrease-and-conquer questi answer question west qaesti tion question question ques 3.1. Decrease- and-conquer strategy 3.2. Insertion sort 3.3. Graph traversal algorithms 3.4. Topological sorting 3.5. Generating all permutations from a set 117" }, { "page_index": 322, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_001.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_001.png", "page_index": 322, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:03:30+07:00" }, "raw_text": "Ho Chi Minh City University of Technology BK Faculty of Computer Science and Engineering TP.HCM Chapter 4: Transform-and-conquer Algorithms Analysis Design and (C03031) Instructor: Assoc. Prof. Dr. Vo Thi Ngoc Chau Email: chauvtn@hcmut.edu.vn Semester 2 - 2022-2023" }, { "page_index": 323, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_002.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_002.png", "page_index": 323, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:03:35+07:00" }, "raw_text": "BK Course Learning Outcomes TP.HCM 1. Able to analyze the complexity of the algorithms (recursive or iterative) and estimate the efficiency of the algorithms. 2. Improve the ability to design algorithms in different areas s by decomposing a computing problem into advanced algorithm design strategies. 3. Able to discuss NP-completeness. 2" }, { "page_index": 324, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_003.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_003.png", "page_index": 324, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:03:40+07:00" }, "raw_text": "BK References TP.HCM [1] Cormen, T. H., Leiserson, C. E, and Rivest, R. L. Introduction to Algorithms, The MiT Press, 2009. [2] Levitin, A., Introduction to the Design and Analysis of Algorithms, 3rd Edition, Pearson, 2012. [3] Sedgewick, R., A/gorithms in C++, Addison-Wesley 1998. [4] Weiss, M.A., Data Structures and Algorithm Analysis in C, TheBenjamin/Cummings Publishing, 1993. 3" }, { "page_index": 325, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_004.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_004.png", "page_index": 325, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:03:47+07:00" }, "raw_text": "BK Course Outline TP.HCM Chapter 1. Fundamentals 0 Chapter 2. Divide-and-Conquer Strategy 0 Chapter 3. Decrease-and-Conquer Strategy 0 Chapter 4. Transform-and-Conquer Strategy 0 Chapter 5. Dynamic Programming and Greedy 0 1 Strategies Chapter 6. Backtracking and Branch-and-Bound Chapter 7. NP-completeness 0 Chapter 8. Approximation Algorithms 0 1 4" }, { "page_index": 326, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_005.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_005.png", "page_index": 326, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:03:52+07:00" }, "raw_text": "Chapter 4. BK TP.HCM Transform-and-Conguer Strategy 4.1. Transform-and-conquer strategy 4.2. Gaussian Elimination for solving a system of linear equations 4.3. Heaps and heapsort 4.4. Horner's rule for polynomial evaluation 4.5. String matching by Rabin-Karp algorithm 5" }, { "page_index": 327, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_006.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_006.png", "page_index": 327, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:03:59+07:00" }, "raw_text": "4.1. Transform-and-conquer BK TP.HCM strategy Transform-and-conguer works in a two-stage procedure. Transformation: the problem's instance is modified to be more amenable to solution. Conguer: the modified instance is solved. Three major variations: Instance simplification: transformation to a simpler or more convenient instance of the same problem Representation change: transformation to a different representation of the same instance Problem reduction: transformation to an instance of a different problem for which an algorithm is already available 6" }, { "page_index": 328, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_007.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_007.png", "page_index": 328, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:04:08+07:00" }, "raw_text": "4.1. Transform-and-conguer BK TP.HCM strategy Three major variations: Instance simplification: Gaussian elimination to solve a system of linear equations, AVL tree Representation change: heapsort, Horner's rule to evaluate polynomials, Rabin-Karp for string matching, B-tree Problem reduction: an algorithm for computing the least common multiple by using Euclid's algorithm for finding the greatest common divisor, graph coloring for edges using the algorithm for vertices simpler instance or problem's solution another representation instance or another problem's instance Transform-and-conquer Figure 6.1, [2], pp. 197 7" }, { "page_index": 329, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_008.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_008.png", "page_index": 329, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:04:15+07:00" }, "raw_text": "4.2. Gaussian Elimination for BK TP.HCM solving a system of linear e equations Gaussian Elimination algorithm helps us solve a system of n linear equations in n unknowns. transform a system of n linear equations in n unknowns to an equivalent system (i.e., a system with the same solution as the original one) with an upper-triangular coefficient matrix, a matrix with all zeros below its main diagonal > Instance simplification of the problem > The system with an upper-triangular coefficient matrix is then easily solved by backward substitutions. 8" }, { "page_index": 330, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_009.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_009.png", "page_index": 330, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:04:20+07:00" }, "raw_text": "4.2. Gaussian Elimination for BK TP.HCM solving g a system of linear e equations Given a system of n linear equations in n unknowns a11X1 + a1zX2 + ... + a1nXn = b1 A b 1 an1X1 + an2Xz + ... + annXn = bn Gaussian Elimination a'11X1 + a'1zXz + ... + a'1nXn = b'1 0 a'nnXn = b'n 9" }, { "page_index": 331, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_010.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_010.png", "page_index": 331, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:04:25+07:00" }, "raw_text": "4.2. Gaussian Elimination for BK TP.HCM solving a system of linear e equations GaussElimination(A[1..n,1..n],b[1..n] 1 to n do A[i,n+1] := b[i]; for i := for i := 1 to n -1 do 1 /row i for j := i + 1 to n do /row i+1..n for k:= i to n+1 do /column i..n+1 A[j,k] := A[j,k]-A[i,k]*A[j,i]/A[i,i] Note: partial pivoting to deal with small [A[i,i]l 10" }, { "page_index": 332, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_011.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_011.png", "page_index": 332, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:04:35+07:00" }, "raw_text": "4.2. Gaussian Elimination for BK TP.HCM solving g a system of linear e equations Solve the following system of 3 linear equations 0 2x1 - Xz + X3 = 1 4x1 + Xz - X3 = 5 X1 + Xz + X3 = 0 2 -1 1 1 4 1 -1 5 row 2 - (4/2) row 1 1 1 1 0 row 3 - (1/2) row 1 2 -1 1 1 0 3 -3 3 row 3 - (1/2) row 2 0 3/2 1/2 -1/2 -> Backward substitution : 2 -1 1 1 X3 = (-2)/2 = -1 0 3 -3 3 x2 = (3-(-3).x3)/3 = 0 0 0 2 -2 x1 = (1-(1.x3+(-1).x,))/2 = 1 11" }, { "page_index": 333, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_012.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_012.png", "page_index": 333, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:04:45+07:00" }, "raw_text": "Elimination for 4.2. Gaussian BK TP.HCM solving g a system of linear e eguations Solve the following system of 3 linear equations 0 2x1 - Xz + X3 = 1 4x1 + Xz - X3 = 5 X1 + Xz + X3 = 0 row j ADj][i] A[i][i] row i 2 -1 1 1 4 1 -1 5 row 2 - (4/2) row 1 1 1 1 0 row 3 - (1/2) row 1 2 -1 1 0 3 -3 3 row 3 - (1/2) row 2 0 3/2 1/2 -1/2 -> Backward substitution : 2 -1 1 1 X3 = (-2)/2 = -1 0 3 -3 3 x2 = (3-(-3).x3)/3 = 0 0 0 2 -2 x1 = (1-(1.x3+(-1).x,))/2 = 1 12" }, { "page_index": 334, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_013.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_013.png", "page_index": 334, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:04:52+07:00" }, "raw_text": "4.2. Gaussian Elimination for BK TP.HCM solving a system of linear e eguations BetterGaussElimination(A[1..n,1..n],b[1..n] for i := 1 to n do A[i,n+1] := b[i]; for i := 1 to n -1 do pivotrow := i: for j := i+1 to n do if [A[j,i]l > lA[pivotrow,i]l then pivotrow:= j; for k:= i to n+1 do swap(A[i,k], A[pivotrow,k]); for j := i + 1 to n do temp:= A[j,i]/A[i,i]; for k:= i to n+1 do A[j,k] := A[j,k]-A[i,k]*temp; 13" }, { "page_index": 335, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_014.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_014.png", "page_index": 335, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:05:05+07:00" }, "raw_text": "Elimination for 4.2. Gaussian BK TP.HCM solving g a system of linear e eguations Solve the following system of 3 linear equations X2 + X3 = -1 pivoting => X2 + X3 = -1 2x1 - Xz + X3 = 1 4 1 -1 5 0 1 1 -1 row 2 - (0/4) row 1 2 -1 1 1 row 3 - (2/4) row 1 4 1 -1 l5 4 1 -1 5 pivoting 0 1 1 -1 => 0 -3/2 3/2 -3/2 row 3 - (1/(-3/2)) row 2 0 -3/2 3/2 -3/2 0 1 1 -1 - Backward substitution : X3 = (-2)/2 = -1 4 1 -1 5 x2 = ((-3/2)-(3/2).x3)/(-3/2) = 0 0 -3/2 3/2 -3/2 x1 = (5-((-1).x3+1.x,))/4 = 1 0 0 2 -2 14" }, { "page_index": 336, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_015.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_015.png", "page_index": 336, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:05:12+07:00" }, "raw_text": "4.2. Gaussian Elimination for BK TP.HCM solving a system of linear e eguations Time complexity to transform a system of n linear equations in n unknowns to an equivalent system with an upper-triangular coefficient matrix Abstract operation : multiplication Worst, Average, Best cases n(n -1)(2n + 5) = 0(n3) 6 15" }, { "page_index": 337, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_016.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_016.png", "page_index": 337, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:05:19+07:00" }, "raw_text": "4.2. Gaussian Elimination for BK TP.HCM solving g a system of linear equations Time complexity of Gaussian E Elimination GaussElimination(A[1..n,1..n],b[1..n]) for i := 1 to n do A[i,n+1] := b[i]; 1 to n -1 do for := for j := i + 1 to n do for k:= i to n+1 do A[j,k] := A[j,k]-A[i,k]*A[j,i]/A[i,i]; For all cases : n-1 n n+1 n-1 n n-1 n 2 1 = n+1- i+1) = (n - i + 2) i=1 j=i+1 k=i i=1 j=i+1 i=1 j=i+1 16" }, { "page_index": 338, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_017.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_017.png", "page_index": 338, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:05:28+07:00" }, "raw_text": "4.2. Gaussian Elimination for BK TP.HCM solving a system of linear e equations Time complexity of Gaussian E Elimination Abstract operation : multiplication Worst, Average, Best cases n(n - 1)(2n + 5) = 0(n3) 6 For all cases : n-1 n n+1 n-1 n n-1 n 1 n+ 1- i+1) = (n - i + 2) i=1 j=i+1 k=i i=1 j=i+1 i=1 j=i+1 n-1 n-1 2 (n - i + 2)(n - (i +1) +1) = i=1 i=1 (2n + 2)n(n - 1) (n - 1)n(2n - 1) Cn = (n2 + 2n)(n -1-1+1) - 2 6 17" }, { "page_index": 339, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_018.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_018.png", "page_index": 339, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:05:38+07:00" }, "raw_text": "4.2. Gaussian Elimination for BK TP.HCM solving a system of linear e equations Time complexity of Gaussian E Elimination Abstract operation : multiplication Worst, Average, Best cases n(n - 1)(2n + 5) = 0(n3) 6 For all cases : n-1 n n+1 n-1 n n-1 n Cn = (n+1- i + 1) = (n- i+ 2) i=1 j=i+1 k=i i=1 j=i+1 i=1 j=i+1 (2n + 2)n(n - 1) (n - 1)n(2n - 1) Cn = (n2 + 2n)(n -1 -1+1) - 2 6 (n - 1)(6n2 + 12n - 6n2 - 6n + 2n2 - n (n -1)(2n2 + 5n) = 0(n3) Ln i 6 6 18" }, { "page_index": 340, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_019.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_019.png", "page_index": 340, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:05:47+07:00" }, "raw_text": "4.2. Gaussian Elimination for BK TP.HCM solving a system of linear e equations Time complexity of Gaussian E Elimination Abstract operation : multiplication Worst, Average, Best cases n(n - 1)(2n + 5) = 0(n3) 6 For all cases : n-1 n n+1 n-1 n n-1 n Cn = 1 (n+1- i + 1) = (n - i + 2) i=1 j=i+1 k=i i=1 j=i+1 i=1 j=i+1 (2n + 2)n(n - 1) (n - 1)n(2n - 1) Cn = (n2+ 2n)(n -1 -1+1) - 2 6 (n - 1)(6n2 + 12n - 6n2 - 6n + 2n2 - n) n(n - 1)(2n + 5) = 0(n3) Cn 6 6 19" }, { "page_index": 341, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_020.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_020.png", "page_index": 341, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:05:54+07:00" }, "raw_text": "4.2. Gaussian Elimination for BK TP.HCM solving a system of linear e equations Your turn : 4.2.1. Solve each following system of 3 linear equations. 4.2.2. Write an algorithm for the back-substitution stage. What is its complexity? X1+ Xz + X3 = 2 2x1 + xz - 7x3 = -2 Xz + 2x3 = 5 X1 - 2xz + 4x3 = 4 2x1 - Xz + 6x3 = 1 X1 - Xz + 3x3 = 8 (S1) (S2) (S3) 20" }, { "page_index": 342, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_021.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_021.png", "page_index": 342, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:06:01+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Heap: a priority queue where the element with the highest priority is dequeued as needed. o Max-heap Array representation: a[1], a[2], .., a[n] a[i] > a[2i] and a[i] > a[2i+1] for each i>0 Tree representation : a nearly complete binary tree all its levels are full except possibly the last level, where only some rightmost leaves may be missing the key at each node is greater than or equal to the keys at its children. 21" }, { "page_index": 343, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_022.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_022.png", "page_index": 343, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:06:12+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM o Max-heap Array representation Tree representation 8 1 2 3 4 5 6 7 8 9 10 8 7 6 5 3 4 5 0 2 3 7 6 a 5 3 4 5 parents leaves 2 3 > parent at i leaves at 2i, 2i + 1 leaf at i 7 parent at i div 2 22" }, { "page_index": 344, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_023.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_023.png", "page_index": 344, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:06:15+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Operations on a heap of n elements Upheap: insertion of a new element into a heap Downheap: remove the minimum/maximum (top-priority) element from a heap 23" }, { "page_index": 345, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_024.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_024.png", "page_index": 345, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:06:20+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Upheap on a heap of n elements procedure upheap(k:integer) var v: integer, begin v :=a[k]; a[01:= maxint; whiIe a[k div 2]<= v do begin a[k]:= a[k div 2 ]; k:=k div 2 end; a[k]:= v end; procedure insert(v:integer): begin n:= n+1; a[n] := v ; upheap(n end; 24" }, { "page_index": 346, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_025.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_025.png", "page_index": 346, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:06:27+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Operations on a heap of n elements Insert 7 into this max-heap? 8 upheap 7 6 8 7 6 5 3 5 4 5 3 4 5 2 3 0 2 3 7 25" }, { "page_index": 347, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_026.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_026.png", "page_index": 347, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:06:34+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Operations on a heap of n elements Insert 7 into this max-heap? 8 7 6 upheap 8 5 3 4 5 7 6 3 2 7 5 7 4 5 2 3 3 26" }, { "page_index": 348, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_027.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_027.png", "page_index": 348, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:06:40+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Operations on a heap of n elements Insert 7 into this max-heap? 8 7 6 upheap 8 5 7 4 5 7 6 3 2 3 5 4 5 2 3 3 27" }, { "page_index": 349, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_028.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_028.png", "page_index": 349, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:06:46+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Operations on a heap of n elements Insert 7 into this max-heap? 8 6 upheap 8 5 7 4 5 7 6 3 2 3 5 4 5 2 3 3 28" }, { "page_index": 350, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_029.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_029.png", "page_index": 350, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:06:53+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Operations on a heap of n elements Insert 7 into this max-heap? 8 upheap 7 6 8 7 6 5 3 5 4 5 4 5 2 3 0 2 3 3 29" }, { "page_index": 351, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_030.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_030.png", "page_index": 351, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:07:00+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Downheap on a heap of n elements procedure downheap(k: integer); label 0 ; var i, v : integer: begin v:= a[k]; while k<= n div 2 do begin j:= 2*k; function remove: integer: if i < n then if a[j1< a[j+11 then begin j:=j+1; //a[j] is a larger child remove := a[1]; if v >= a[j] then go to update; a[11 := a[nl; n := n-1; a[k]:= a[j]; k:= j; downheap(1); end; end; update: a[k]: =v end; 30" }, { "page_index": 352, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_031.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_031.png", "page_index": 352, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:07:06+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Operations on a heap of n elements Remove the top-priority element, 8 8 from this max-heap? 7 6 8 5 3 5 4 7 6 0 2 3 5 3 4 5 2 3 ] 31" }, { "page_index": 353, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_032.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_032.png", "page_index": 353, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:07:15+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Operations on a heap of n elements Remove the top-priority element, 8 from this max-heap? 7 6 V downheap 3 5 3 5 4 7 6 2 3 0 5 3 4 5 2 3 32" }, { "page_index": 354, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_033.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_033.png", "page_index": 354, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:07:24+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Operations on a heap of n elements Remove the top-priority element, 8 L 3 from this max-heap? 7 downheap 5 3 4 5 3 6 0 2 3 5 3 4 5 2 33" }, { "page_index": 355, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_034.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_034.png", "page_index": 355, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:07:32+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Operations on a heap of n elements Remove the top-priority element, 8 from this max-heap? 7 3 0 downheap 5 3 4 5 5 6 0 2 3 3 4 5 2 34" }, { "page_index": 356, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_035.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_035.png", "page_index": 356, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:07:40+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Operations on a heap of n elements Remove the top-priority element, 8 8 from this max-heap? 7 6 5 3 5 4 5 6 2 3 0 3 3 4 5 2 35" }, { "page_index": 357, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_036.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_036.png", "page_index": 357, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:07:45+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Operations on a heap of n elements Upheap: insertion of a new element into a heap O(log,n) comparisons Downheap: remove the minimum/maximum (top-priority) element from a heap O(2log,n) comparisons 36" }, { "page_index": 358, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_037.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_037.png", "page_index": 358, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:07:52+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Heap construction from n elements Top-down heap construction Start with a null complete binary tree (array) Insert each element sequentially into the complete binary upheap < tree (array) Bottom-up heap construction Start with a complete binary tree (array) of all the n elements Adjust the complete binary tree (array) to make it a heap downheap From the bottom up to the top From the right to the left 37" }, { "page_index": 359, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_038.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_038.png", "page_index": 359, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:07:58+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Top-down heap construction Heap_construction (a, n) for k:=1 to n do insert (a[k]); /* insert a[k] into a heap */ 38" }, { "page_index": 360, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_039.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_039.png", "page_index": 360, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:08:06+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Top-down heap construction Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 upheap 4 4 4 5 5 3 3 5 3 4 3 4 2 5 5 5 6 3 4 5 4 5 4 5 5 2 5 2 3 2 3 2 3 4 39" }, { "page_index": 361, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_040.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_040.png", "page_index": 361, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:08:14+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Top-down heap construction Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 6 7 5 5 5 6 2 3 4 2 3 4 5 7 7 5 6 5 6 2 3 4 5 2 3 4 5 0 8 40" }, { "page_index": 362, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_041.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_041.png", "page_index": 362, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:08:21+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Top-down heap construction Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 8 5 6 7 6 2 3 4 5 5 3 5 8 2 41" }, { "page_index": 363, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_042.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_042.png", "page_index": 363, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:08:28+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Top-down heap construction Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 8 8 7 6 7 6 5 3 4 5 5 3 4 5 3 2 0 2 3 42" }, { "page_index": 364, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_043.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_043.png", "page_index": 364, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:08:33+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Top-down heap construction Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 6 5 3 4 5 3 2 43" }, { "page_index": 365, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_044.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_044.png", "page_index": 365, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:08:37+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Bottom-up heap construction o I Heap_construction (a, n) for k := n div 2 downto 1 do downheap (k); 44" }, { "page_index": 366, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_045.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_045.png", "page_index": 366, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:08:45+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Bottom-up heap construction o I Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 4 4 3 5 3 5 downheap 2 5 6 7 2 5 6 7 8 3 8 3 45" }, { "page_index": 367, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_046.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_046.png", "page_index": 367, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:08:53+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Bottom-up heap construction o I Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 4 4 3 5 3 5 downheap 2 5 6 7 2 5 6 7 8 3 8 3 46" }, { "page_index": 368, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_047.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_047.png", "page_index": 368, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:09:01+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Bottom-up heap construction o I Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 4 4 3 5 3 5 downheap 2 5 6 7 2 5 6 8 3 8 3 47" }, { "page_index": 369, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_048.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_048.png", "page_index": 369, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:09:07+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Bottom-up heap construction o I Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 4 4 downheap 3 5 3 5 2 5 6 7 2 5 6 7 8 3 8 3 48" }, { "page_index": 370, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_049.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_049.png", "page_index": 370, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:09:13+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Bottom-up heap construction o I Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 downheap 4 4 3 5 3 5 2 5 6 7 2 5 6 7 8 3 8 3 49" }, { "page_index": 371, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_050.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_050.png", "page_index": 371, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:09:21+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Bottom-up heap construction - Let's start .. o I Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 4 4 3 5 3 5 downheap 2 5 6 7 2 5 6 7 8 3 8 3 50" }, { "page_index": 372, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_051.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_051.png", "page_index": 372, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:09:30+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Bottom-up heap construction o I Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 4 4 3 5 3 5 2 5 6 7 2 5 6 7 8 3 8 3 51" }, { "page_index": 373, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_052.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_052.png", "page_index": 373, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:09:39+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Bottom-up heap construction o I Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 4 4 3 5 3 5 downheap 2 5 6 7 8 5 6 7 3 8 2 3 52" }, { "page_index": 374, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_053.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_053.png", "page_index": 374, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:09:44+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Bottom-up heap construction o I Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 4 4 3 5 3 5 8 5 6 7 8 5 6 7 3 2 3 2 53" }, { "page_index": 375, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_054.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_054.png", "page_index": 375, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:09:53+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Bottom-up heap construction o I Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 4 4 3 5 3 7 downheap 8 5 6 7 8 5 6 5 2 3 2 3 54" }, { "page_index": 376, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_055.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_055.png", "page_index": 376, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:09:59+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Bottom-up heap construction o I Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 4 4 3 7 3 7 8 5 6 5 8 5 6 5 2 3 3 2 55" }, { "page_index": 377, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_056.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_056.png", "page_index": 377, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:10:07+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Bottom-up heap construction o I Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 4 4 3 7 8 7 downheap 8 5 6 5 3 5 6 5 3 3 2 56" }, { "page_index": 378, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_057.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_057.png", "page_index": 378, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:10:16+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Bottom-up heap construction o I Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 4 4 8 7 8 7 3 5 6 5 3 5 6 5 3 3 2 2 57" }, { "page_index": 379, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_058.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_058.png", "page_index": 379, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:10:21+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Bottom-up heap construction o I Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 downheap 1 8 8 7 5 7 3 5 6 5 3 4 6 5 3 3 2 58" }, { "page_index": 380, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_059.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_059.png", "page_index": 380, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:10:30+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Bottom-up heap construction 01 Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 8 5 7 3 4 6 5 2 3 59" }, { "page_index": 381, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_060.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_060.png", "page_index": 381, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:10:36+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Heap construction Max-heap: 4, 3, 5, 2, 5, 6, 7, 0, 8, 3 8 8 7 6 5 7 5 3 5 3 4 6 5 4 2 3 3 2 Top-down Bottom-up 60" }, { "page_index": 382, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_061.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_061.png", "page_index": 382, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:10:44+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Time complexity of heap construction for a heap of n elements Abstract operation: comparison With top-down heap construction With bottom-up heap construction Cn = O(n) 61" }, { "page_index": 383, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_062.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_062.png", "page_index": 383, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:10:48+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Time complexity of heap construction for a heap of n elements Abstract operation: comparison With top-down heap construction for k:=1 to n do insert (a[k]); /* insert a[k] into a heap */ Cn = log22 + ...+ log2(n - 2) + log2(n - 1) + log2n Cn log2n + ...+ log2n + log2n+ log2n Cn nlog2n = O(nlog2n) 62" }, { "page_index": 384, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_063.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_063.png", "page_index": 384, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:10:56+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Time complexity of heap construction for a heap of n elements Abstract operation: comparison With top-down heap construction for k:=1 to n do insert (a[k]); /* insert a[k] into a heap */ Cn = log22 + ...+ log2(n - 2) + log2(n - 1) + log2n Cn log2n + ...+ log2n + log2n+ log2n Cn nlog2n = O(nlog2n) 63" }, { "page_index": 385, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_064.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_064.png", "page_index": 385, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:11:00+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Time complexity of heap construction for a heap of n elements Abstract operation: comparison With bottom-up heap construction Cn = O(n) for k := n div 2 downto 1 do downheap (k) n 2.lo922 + ...+ 4.2.lo92(n/4) + 2.2. lo92(n/2) + 1.2.log2n 2.2 Cn < 2n = O(n) 64" }, { "page_index": 386, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_065.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_065.png", "page_index": 386, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:11:10+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Time complexity of heap construction for a heap of n elements Abstract operation: comparison With bottom-up heap construction Cn = O(n) for k := n div 2 downto 1 do downheap (k): #subheap #cmps Height of subheap n 2.log22 + ...+ 4.2.lo92(n/4) + 2.2. log2(n/2) + 1.2. log2n 2.2 Cn 2n = O(n) 65" }, { "page_index": 387, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_066.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_066.png", "page_index": 387, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:11:15+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Time complexity of heap construction for a heap of n elements Abstract operation: comparison With bottom-up heap construction Cn = O(n) + 2.2.lo92 + 1.2.lo92n 2.2 Suppose: n = 2h, C, is rewritten as: ->Czh=2Czh-Czh 66" }, { "page_index": 388, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_067.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_067.png", "page_index": 388, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:11:23+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Time complexity of heap construction for a heap of n elements Abstract operation: comparison With bottom-up heap construction Cn = O(n) + 2.2.lo92 + 1.2.lo92n 2.2 Suppose: n = 2h, C, is rewritten as: 67" }, { "page_index": 389, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_068.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_068.png", "page_index": 389, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:11:29+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Time complexity of heap construction for a heap of n elements Abstract operation: comparison With bottom-up heap construction Cn = O(n) + 2.2.lo92 + 1.2.lo92n - 2.2 Suppose: n = 2h, C, is rewritten as: -> Cn = 2n - 2log2n - 4 2n = 0(n 68" }, { "page_index": 390, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_069.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_069.png", "page_index": 390, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:11:33+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Time complexity of heap construction for a heap of n elements Abstract operation: comparison With bottom-up heap construction Cn = O(n) for k := n div 2 downto 1 do downheap (k); n 2.lo922 + ...+ 4.2.lo92(n/4) + 2.2. lo92(n/2) + 1.2.log2n 2.2 Cn < 2n = O(n) 69" }, { "page_index": 391, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_070.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_070.png", "page_index": 391, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:11:38+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Heapsort Task: sort n elements in ascending order Steps : o Build a max-heap Remove the maximum element from the heap one by one Return n elements in ascending order Example: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 0,2,3,3,4,5,5,6,7,8 70" }, { "page_index": 392, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_071.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_071.png", "page_index": 392, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:11:44+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Heapsort Task: sort n elements in ascending order Steps : Build a max-heap Remove the maximum element from the heap one by one Return n elements in ascending order Heap_construction (a, n); for k := n downto 1 do a[k]:= remove; /*putting the removed element into array a*/ 71" }, { "page_index": 393, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_072.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_072.png", "page_index": 393, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:11:50+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 8 5 7 3 4 6 5 2 3 A max-heap of n given elements 72" }, { "page_index": 394, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_073.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_073.png", "page_index": 394, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:11:57+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 8 3 5 7 remove 8 5 7 3 4 5 3 4 6 5 6 0 2 3 2 8 73" }, { "page_index": 395, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_074.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_074.png", "page_index": 395, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:12:04+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 downheap 3 7 5 7 update 5 6 3 4 5 3 4 3 5 6 0 2 8 2 8 74" }, { "page_index": 396, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_075.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_075.png", "page_index": 396, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:12:10+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 7 2 5 6 remove 7 5 6 3 4 3 5 3 4 3 5 0 2 8 7 8 75" }, { "page_index": 397, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_076.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_076.png", "page_index": 397, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:12:15+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 downheap 2 6 5 6 update 5 5 3 4 3 5 3 4 3 2 0 7 8 7 8 76" }, { "page_index": 398, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_077.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_077.png", "page_index": 398, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:12:25+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 6 0 5 5 remove 6 5 5 3 4 3 2 3 4 3 2 7 8 6 7 8 77" }, { "page_index": 399, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_078.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_078.png", "page_index": 399, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:12:31+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 downheap 5 5 5 update 4 5 3 4 3 2 3 3 2 6 7 8 6 7 8 78" }, { "page_index": 400, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_079.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_079.png", "page_index": 400, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:12:37+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 5 2 4 5 remove 5 4 5 3 3 2 3 3 5 6 7 8 6 7 8 79" }, { "page_index": 401, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_080.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_080.png", "page_index": 401, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:12:43+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 downheap 2 5 4 5 update 4 3 3 3 5 3 2 5 6 7 8 6 7 8 80" }, { "page_index": 402, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_081.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_081.png", "page_index": 402, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:12:50+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 5 2 4 3 remove 5 4 3 3 2 5 3 5 5 6 7 8 6 7 8 81" }, { "page_index": 403, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_082.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_082.png", "page_index": 403, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:12:57+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 downheap 2 4 3 update 3 3 3 5 5 2 5 5 6 7 8 6 7 8 82" }, { "page_index": 404, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_083.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_083.png", "page_index": 404, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:13:03+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 4 3 3 remove 4 3 3 2 5 5 2 4 5 5 6 7 8 6 7 8 83" }, { "page_index": 405, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_084.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_084.png", "page_index": 405, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:13:10+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 downheap 0 3 3 3 update 2 3 2 4 5 5 4 5 5 6 7 8 6 7 8 84" }, { "page_index": 406, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_085.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_085.png", "page_index": 406, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:13:17+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 3 2 3 remove 3 2 3 4 5 5 3 4 5 5 6 7 8 6 7 8 85" }, { "page_index": 407, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_086.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_086.png", "page_index": 407, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:13:25+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 downheap 3 0 2 3 update 2 3 4 5 5 3 4 5 5 6 7 8 6 7 8 86" }, { "page_index": 408, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_087.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_087.png", "page_index": 408, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:13:33+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 3 2 0 2 3 remove 3 3 4 5 5 3 4 5 5 6 7 8 6 7 8 87" }, { "page_index": 409, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_088.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_088.png", "page_index": 409, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:13:44+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 downheap 0 2 2 3 update 3 0 3 4 5 5 3 4 5 5 6 7 8 6 7 8 88" }, { "page_index": 410, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_089.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_089.png", "page_index": 410, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:13:48+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 2 3 2 3 remove 2 3 4 5 5 3 4 5 5 6 7 8 6 7 8 89" }, { "page_index": 411, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_090.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_090.png", "page_index": 411, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:13:54+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Heapsort: 4, 3, 5, 2, 6, 5, 7, 0, 8, 3 2 3 3 4 5 5 6 7 8 Sorted array: 0, 2, 3, 3, 4, 5, 5, 6, 7, 8 90" }, { "page_index": 412, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_091.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_091.png", "page_index": 412, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:13:58+07:00" }, "raw_text": "BK 4.3.Heaps and heapsort TP.HCM Time complexity to sort n elements with a heap Abstract operation: comparison Using a heap built with top-down heap construction Using a heap built with bottom-up heap construction 91" }, { "page_index": 413, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_092.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_092.png", "page_index": 413, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:14:04+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM Your turn : 4.3.1. Trace by hand heapsort 23, 7, 92, 6, 12, 24,40,44, 20, 21 4.3.1.1 44,30, 50, 22,60, 55, 77,55 4.3.1.2) 2,4, 6,8, 10, 10 (4.3.1.3) 13, 11,7, 7,3, 2, 1 (4.3.1.4) 92" }, { "page_index": 414, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_093.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_093.png", "page_index": 414, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:14:11+07:00" }, "raw_text": "BK 4.3. Heaps and heapsort TP.HCM g Your turn: 4.3.2. Is it always true that the bottom-up and top- down heap-construction algorithms yield the same heap for the same input? Check the previous results. 4.3.3. Outline an algorithm for checking whether an array H[1..n] is a heap and determine its time efficiency - 4.3.4. Design an efficient algorithm for finding and deleting an element of the smallest value in a max heap and determine its time efficiency. 4.3.5. Design an efficient algorithm for finding and deleting an element of a given value v in a given heap H and determine its time efficiency. 93" }, { "page_index": 415, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_094.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_094.png", "page_index": 415, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:14:18+07:00" }, "raw_text": "4.4. Horner's rule for BK TP.HCM polynomial evaluation Consider the problem of computing the value of a polynomial of degree n + ... + ax + ao (4.1) at a given point x. G.H. Horner, the British mathematician, 150 years ago, proposed an efficient method for evaluating a polynomial of degree n. From (4.1), we can obtain a new formula by successively taking x as a common factor in the remaining polynomials of diminishing degrees. p(x) = (..(anx + an-1)x+...)x + ao (4.2) Horner's rule: representation change a polynomial of degree n > a polynomial of degree 1 94" }, { "page_index": 416, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_095.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_095.png", "page_index": 416, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:14:26+07:00" }, "raw_text": "4.4. Horner's rule for BK TP.HCM polynomial evaluation ALGORITHIM Horner(P[0..n], x //Evaluates a polynomial at a given point by Horner's rule //Input: An array P[0..n] of coefficients of a polynomial of degree n 11 (stored from the lowest to the highest) and a number x //Output: The value of the polynomial at x ps = ??? 101" }, { "page_index": 423, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_102.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_102.png", "page_index": 423, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:15:16+07:00" }, "raw_text": "4.5. String matching by BK TP.HCM Rabin-Karp algorithm String matching : finding all occurrences of a pattern P in a text 7 c A shift s shows that P occurs in T from s+1. T[s+1..s+m] = P[1..m] with Tl = n, lPl = m, and 0 < s < n - m 7= 2 3 5 9 0 23 1 4 1 52 6 3 5 9 0 2 1 oP = 3 5 9 O Rabin-Karp: elementary number-theoretic notions such as the equivalence of two >s = 1,13 numbers after we \"modulo\" the third number 102" }, { "page_index": 424, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_103.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_103.png", "page_index": 424, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:15:23+07:00" }, "raw_text": "4.5. String matching by BK TP.HCM Rabin-Karp algorithm Rabin-Karp algorithm Assume: = {0, 1, 2, ..., 9} and the elements of p and T are characters drawn from a finite alphabet E. In general, a character is a digit in radix-d notation where d = I2 l We can view a string of k consecutive characters as a length-k decimal number. Character string \"3590\" corresponds to decimal number 3,590 Given a pattern P[1..m], let p denote its corresponding decimal value. Given a text T[1..nl, let t. denote the decimal value of the length-m substring T[s+1...s+m], for s = 0, I, .., n-m. t, = p if and only if T[s+1..s+m] = P[1..m]. s is a valid shift if and only if t, = p. 103" }, { "page_index": 425, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_104.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_104.png", "page_index": 425, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:15:31+07:00" }, "raw_text": "matching by 4.5. String BK TP.HCM Rabin-Karp algorithm For P[1..m1, p is computed in O(m) with Horner's rule (P: a polynomial of degree m-1 and x=d=10) : p = ((.(P[1]*10 + P[2])*10 +..+ P[m-2])*10 +P[m-1])*10 +P[m] For T[1...m], t, = t, is similarly computed in O(m). 0. s=1..n-m: T= 23 5 9 023 141 526 3 5 902 1 P = 3 5 9 O For T[2..5], ts = t1 = 3590 For T[3..6], = 10(3590-1000*3) + 2 = 5902 1 7 T= 2 3 5 9 0 2 3 1 4 1 5 2 6 3 5 9 0 2 1 s = s = 2 7 T=2 3 59 0 2 314 152 63 5 9 02 1 104" }, { "page_index": 426, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_105.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_105.png", "page_index": 426, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:15:39+07:00" }, "raw_text": "4.5. String matching by BK TP.HCM Rabin-Karp algorithm In practice, p and t, may be too large. Fortunately, there is a simple cure for this problem. We compute p and the t, values modulo a suitable modulus q. The modulus q is chosen as a prime such that 10q just fits within a computer word for single-precision arithmetic. d-1}, we choose q such that dq fits within a computer word. 105" }, { "page_index": 427, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_106.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_106.png", "page_index": 427, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:15:47+07:00" }, "raw_text": "4.5. String matching by BK TP.HCM Rabin-Karp algorithm ts+1 1 is now computed from t, using \"modulo\": = (d(ts - hT[s+1]) + T[s+m+1]) mod q mod q where h = dm-1 t, = p mod q does not imply that t, = p. If t, + p mod q then definitely t, + p. Such a shift s is invalid. Any shift s for which t, = p mod q must be checked further to see if s is really a valid hit or just a spurious hit. 106" }, { "page_index": 428, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_107.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_107.png", "page_index": 428, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:15:54+07:00" }, "raw_text": "matching by 4.5. String BK TP.HCM Rabin-Karp algorithm procedure RABIN-KARP-MATCHER(T, P, d, q); /* T is the text, P is the pattern, d is the radix and q is the prime */ begin n: = ITl; m: = IPl; h: = dm-1 mod q; p: = 0; to : = 0; for i: = 1 to m do begin p: = (d*p + P[i])mod q; to: = (d*t, + T[i])mod q end for s: = 0 to n - m do begin if p = t, then /* there may be a hit */ if P[1..m] = T[s+1..s+m] then Print \"Pattern occurs with shift \"s. if s < n - m then ts+1: = (d(ts -T[s + 1]h) + T[s+m+1])mod q end end 107" }, { "page_index": 429, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_108.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_108.png", "page_index": 429, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:16:03+07:00" }, "raw_text": "4.5. String matching by BK TP.HCM Rabin-Karp algorithm procedure RABIN-KARP-MATCHER(T, P, d, q); /* T is the text, P is the pattern, d is the radix and q is the prime */ begin (a mod n) mod n = a mod n n: =Tl; m: = Pl: h: = dm-1 mod q; p: = 0; t, : = 0; (a+b) mod n = ((a mod n) + (b mod n)) mod n for i: = 1 to m do begin (ab) mod n = ((a mod n) (b mod n)) mod n p: = (d*p + P[i])mod q to: = (d*to + T[i])mod q h = dm-1 mod q = (d mod q) ((dm-2) mod q) end for s: = 0 to n - m do h = ((d mod q) (d mod q) .: (d mod q)) mod q begin if p = t, then /* there may be a hit */ if P[1..m] = T[s+1..s+m] then Print \"Pattern occurs with shift \"s. if s < n - m then ts+1: = (d(ts -T[s + 1]h) + T[s+m+1])mod q end end 108" }, { "page_index": 430, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_109.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_109.png", "page_index": 430, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:16:23+07:00" }, "raw_text": "4.5.String matching g by BK Rabin-Karp a TP.HCM algorithm T = 2 3 5 9 O 2 3 1 4 1 5 2 6 3 5 9 O 2 1 P = 3 5 9 0, q = 13,d = 10,h = dm-1mod q = 1000 mod 13 = 9 ts+1: = (d(ts -T[s + 1]h) + T[s+m+1])mod q Shift Pattern T[s+1] T[s+m+1] ts(=?p mod q = 2 Hit? True hit? 2359 1 1 6 FALSE 1 3590 2 2 TRUE yes 2 5902 3 2 FALSE 3 9023 5 3 1 FALSE 4 0231 9 1 10 FALSE 5 2314 4 FALSE 6 3141 2 1 8 FALSE 1415 3 5 11 FALSE 8 4152 1 2 5 FALSE 9 1526 4 6 5 FALSE 10 5263 1 3 11 FALSE 11 2635 5 5 9 FALSE 12 6359 2 2 TRUE no 13 3590 6 2 TRUE yes 14 5902 3 2 0 FALSE 15 9021 5 1 12 FALSE 109" }, { "page_index": 431, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_110.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_110.png", "page_index": 431, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:16:29+07:00" }, "raw_text": "4.5. String matching by BK TP.HCM Rabin-Karp algorithm Time complexity of Rabin-Karp for finding all the occurrences of a pattern P in a string T where lTl = n and d 1P1 = m Abstract operation : comparison Worst case when every shift is verified. O((n-m+1)m) Average to Best case when few (c shifts) are verified. O((n-m+1) + cm) = O(n+m) 110" }, { "page_index": 432, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_111.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_111.png", "page_index": 432, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:16:34+07:00" }, "raw_text": "4.5. String matching by BK TP.HCM Rabin-Karp algorithm g Your turn: 4.5.1. Use Rabin-Karp algorithm to determine the occurences of P in T in the decimal system. How many spurious matches are there? Given q = 11. How about q = 13? T = 3141592653589793 P = 26 111" }, { "page_index": 433, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_112.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_112.png", "page_index": 433, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:16:38+07:00" }, "raw_text": "4.5. String matching by BK TP.HCM Rabin-Karp algorithm g Your turn: 4.5.2. Use Rabin-Karp algorithm to determine the occurences of P in T in the hexadecimal system. How many spurious matches are there? Given q = 17. T = 31ABCEF926CEF9D897A P = CEF9 112" }, { "page_index": 434, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_113.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_113.png", "page_index": 434, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:16:43+07:00" }, "raw_text": "Chapter 4. Transform-and- BK Conquer TP.HCM Your turn: 4.5.3. Use Rabin-Karp algorithm to determine the occurences of P in T in the hexadecimal system. How many spurious matches are there? Given q = 23. T = A31AB7EF926ACEF9264 O P = F EF926. What if P = 1ABZE? 113" }, { "page_index": 435, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_114.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_114.png", "page_index": 435, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:16:53+07:00" }, "raw_text": "Chapter 4. Transform-and-Conquer BK TP.HCM Problem Reduction Your turn: (i) Consider the problem of finding, for a given positive 0 1 integer n, the pair of integers whose sum is n and whose product is as large as possible. Design an efficient algorithm for this problem and indicate its efficiency class. (ii) The graph-coloring problem is usually stated as the vertex-coloring problem: assign the smallest number of colors to vertices of a given graph so that no two adjacent vertices are the same color. Consider the edge-coloring problem : assign the smallest number of colors possible to edges of a given graph so that no two edges with the same endpoint are the same color. Explain how the edge-coloring problem can be reduced to a vertex-coloring problem. 114" }, { "page_index": 436, "chapter_num": 4, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_115.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_4/slide_115.png", "page_index": 436, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:16:59+07:00" }, "raw_text": "Algorithms Analysis and Design BK TP.HCM (C03031) Chapter 4. Transform-and-conquer gues questi answer question wuest ruests question question 4.1. Transform-and-conquer strategy 4.2. Gaussian Elimination for solving a system of linear equations 4.3. Heaps and heapsort 4.4. Horner's rule for polynomial evaluation 4.5. String matching by Rabin-Karp algorithm 115" }, { "page_index": 437, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_001.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_001.png", "page_index": 437, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:17:04+07:00" }, "raw_text": "Ho Chi Minh City University of Technology BK Faculty of Computer Science and Engineering TP.HCM Chapter 5: Dynamic Programming and Greedy Algorithms Algorithms Analysis Design and (C03031 Instructor: Assoc. Prof. Dr. Vo Thi Ngoc Chau Email: chauvtn@hcmut.edu.vn Semester 2 - 2022-2023" }, { "page_index": 438, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_002.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_002.png", "page_index": 438, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:17:11+07:00" }, "raw_text": "BK Course Learning Outcomes TP.HCM 1. Able to analyze the complexity of the algorithms (recursive or iterative) and estimate the efficiency of the algorithms. 2. Improve the ability to design algorithms in different areas by decomposing a computing problem into advanced algorithm design strategies. 3. Able to discuss Np-completeness. 2" }, { "page_index": 439, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_003.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_003.png", "page_index": 439, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:17:15+07:00" }, "raw_text": "BK References TP.HCM [1] Cormen, T. H., Leiserson, C. E, and Rivest, R. L. Introduction to Algorithms, The MiT Press, 2009. [2] Levitin, A., Introduction to the Design and Analysis of Algorithms, 3rd Edition, Pearson, 2012 [3] Sedgewick, R., A/gorithms in C++, Addison-Wesley. 1998. [4] Weiss, M.A., Data Structures and Algorithm Analysis in C, TheBenjamin/Cummings Publishing, 1993. 3" }, { "page_index": 440, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_004.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_004.png", "page_index": 440, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:17:23+07:00" }, "raw_text": "BK Course Oytline TP.HCM Chapter 1. Fundamentals 0 1 Chapter 2. Divide-and-Conquer Strategy Chapter r 3. Decrease-and-Conquer Strategy 0 1 Chapter 4. Transform-and-Conquer Strategy 0 1 Chapter 5. Dynamic Programming and 0 Greedy Strategies Chapter 6. Backtracking and Branch-and-Bound Chapter 7. NP-completeness 0 C Chapter 8. Approximation Algorithms 4" }, { "page_index": 441, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_005.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_005.png", "page_index": 441, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:17:33+07:00" }, "raw_text": "Chapter 5. BK TP.HCM Dynamic Programming and Greedy Strategies 5.1. Dynamic Programming 0 5.1.1. Matrix-chain multiplication 5.1.2. Longest common subsequence 5.1.3. (0-1) Knapsack problem 5.1.4. Transitive closure with Warshall's algorithm 5.1.5. The all-pairs shortest path problem with Floyd's algorithm 5.2. Greedy Algorithms 5.2.1. Activity-selection problem 5.2.2. Fractional knapsack problem 5.2.3. Huffman codes 5.2.4. Graph coloring 5" }, { "page_index": 442, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_006.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_006.png", "page_index": 442, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:17:42+07:00" }, "raw_text": "BK 5.1. Dynamic Programming TP.HCM Dynamic programming was invented by Richard 0 Bellman, a US mathematician, in 1950s as a general method for optimizing multistage decision processes. Programming Planning Dynamic programming is a technique for solving 0 problems with overlapping subproblems. The subproblems arise from a recurrence relating a solution to a given problem with solutions to its smaller subproblems of the same type. Rather than solving overlapping subproblems again and again, each of the smaller subproblems is solved only once and the result is recorded in a table from which we can then obtain a solution to the original problem. 6" }, { "page_index": 443, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_007.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_007.png", "page_index": 443, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:17:51+07:00" }, "raw_text": "BK 5.1. Dynamic Programming TP.HCM The development of a dynamic programming algorithm can be divided into a sequence of four steps 1. Characterize the structure of an optimal solution. 2. Recursively define the value of an optimal solution. Define the value of an optimal solution recursively in terms of the optimal solutions to subproblems. 3. Compute the value of an optimal solution in a bottom-up fashion 4. Construct the final optimal solution from computed information. 7" }, { "page_index": 444, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_008.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_008.png", "page_index": 444, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:17:58+07:00" }, "raw_text": "BK 5.1. Dynamic Programming TP.HCM 0 There are two key elements that an optimization problem must have for dynamic programming to be applicable: (1) optimal substructure 2) overlapping subproblems Optimal substructure (principle of optimality): The optimal solution for the problem contains within it optimal solutions to subproblems. Overlapping subproblems When a recursive algorithm revisits the same problem over and over again, we say that the optimization problem has overlapping subproblems. Dynamic programming algorithms take advantage of overlapping subproblems by solving each subproblem once and then storing the solution in a table where it can be looked up when needed, using constant time per lookup. Dynamic programming algorithms work in a bottom-up fashion. 8" }, { "page_index": 445, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_009.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_009.png", "page_index": 445, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:18:07+07:00" }, "raw_text": "BK 5.1. Dynamic Programming TP.HCM List the sequence of Fibonacci numbers 1, 1, 2, 3, 5, 8, 13, 21, 34, ... function fibonacci r (N: integer): integer: Recurrence relation begin Fn=Fn-1 +Fr N-2,N >2 if N<=1 then fibonacci := 1 Fo=F=1 else fibonacci := fibonacci (N-1) + fibonacci (N-2): end; The iterative Fibonacci function is designed with function fibonacci i (N: integer): integer; dynamic programming i: integer; var technique. F: array [0..max] of integer; //max>=N F: a table that stores the begin solutions of the F[0] := 1; F[1] := 1; overlapping subproblems. for i := 2 to N do F[i] := F[i-1]+ F[i-2]: fibonacci := F[N]; -> bottom-up fashion end; 9" }, { "page_index": 446, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_010.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_010.png", "page_index": 446, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:18:18+07:00" }, "raw_text": "BK 5.1. Dynamic Programming TP.HCM List the sequence of Fibonacci numbers 1, 1, 2, 3, 5, 8, 13, 21,,34, ... Recursive tree F6 F5 FA F3 F3 F2 Fs F2 F2 F1 F1 Fo F1 Fo F1 Fo F4 F2 F2 0 F1 F1 F1 Fo F1 Fo F2 F3 There exist several redundant F1 computations when using the F1 Fo Fo F2 recursive function to compute F1 Fibonacci numbers!!! 10 F1Fo" }, { "page_index": 447, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_011.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_011.png", "page_index": 447, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:18:28+07:00" }, "raw_text": "BK 5.1. Dynamic Programming TP.HCM List the sequence of Fibonacci numbers 1, 1, 2, 3, 5, 8, 13, 21, 34, ... function fibonacci r (N: integer): integer: Recurrence relation. begin Fn=Fn-1 +F N-2,N >2 if N<=1 then fibonacci := 1 Fo=F=1 else fibonacci := fibonacci (N-1) + fibonacci (N-2): end; The recursive function : function fibonacci i (N: integer): integer: N 1+ V5 i: integer; var 2 F: array [0..max] of integer; //max>=N begin The iterative function : F[0] := 1; F[1] := 1; for i := 2 to N do F[i] := F[i-1]+ F[i-2]: O(N) fibonacci := F[N]; end; 11" }, { "page_index": 448, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_012.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_012.png", "page_index": 448, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:18:35+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM A product of matrices is fully parenthesized if it is either a single matrix or the product of two fully-parenthesized matrix products, surrounded by parentheses. A1 Az A3 A4 can be fully parenthesized in 5 ways: (A1(Az(A3A4))) A1 10 x 5 (A1((A2A3)A4)) A2 5 x 15 ((A1A2)(A3A4)) A3 15 x 25 ((A1(A,A3))A4) A4 25 x 20 (((A1A2)A3)A4) 12" }, { "page_index": 449, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_013.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_013.png", "page_index": 449, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:18:41+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM The way we parenthesize a chain of matrices can have a dramatic impact on the cost of evaluating the product. For example: A1 10 x 100 0 A2 100 x 5 A3 5 x 50 ((AA2)A3)) needs 10.100.5 + 10.5.50 = 5000 + 2500 = 7500 scalar multiplications (A(A2A3)) needs 100.5.50 + 10.100.50 = 25000 + 50000 = 75000 scalar multiplications Computing the product according to the first parenthesization is 10 times faster. 13" }, { "page_index": 450, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_014.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_014.png", "page_index": 450, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:18:49+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM The matrix-chain multiplication problem is stated: parenthesize the product AA2 .. .A, in such a way that minimizes the number of scalar multiplications\". A1 Az A3 A4 can be fully parenthesized in 5 ways: (A1(Az(A3A4))) A1 10 x 5 Which way has the (A1((A2A3)A4) A2 5 x 15 smallest number of ((A1A2)(A3A4)) A3 15 x 25 ((A1(A,A3))A4 scalar mulitplications? A4 25 x 20 (((A1A2)A3)A4 14" }, { "page_index": 451, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_015.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_015.png", "page_index": 451, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:18:54+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM The matrix-chain multiplication problem is stated: \"Given a chain of n matrices, where for n parenthesize the product A A, .. .A, in such a way that minimizes the number of scalar multiplications\" Step 1: Characterize the structure of an optimal solution Step 2: Recursively define the value of an optimal solution Step 3: Compute the value of an optimal solution in a bottom-up fashion Step 4: Construct the.final optimal solution from computed information 15" }, { "page_index": 452, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_016.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_016.png", "page_index": 452, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:19:00+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM Step 1: Characterize the structure of an optimal solution Let A; : denote the matrix that is obtained from evaluating the product: A; A;+1...Aj An optimal parenthesization of the product A.A2. .. A, splits the product between A and Ak+1 for some integer k, 1 k < n. That is k+1..n and then multiply them together to produce the final product A AA...An =(A1...Ak)(Ak+1...An) for 1. The procedure uses table m[1..n, 1..n] for storing the cost m[i, j] and table s[1..n, 1..n] that records the best value k for the optimal cost of m[i, j]. For i j, the part of m above the main diagonal is used. MATRIX-CHAIN-ORDER returns two tables m and s. 20" }, { "page_index": 457, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_021.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_021.png", "page_index": 457, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:19:34+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM procedure MATRIX-CHAIN-ORDER(p, m, s): begin n := length[p] - 1: for i :- 1 to n do m[i, i] := 0: for l := 2 to n do /* l: length of the chain = the number of matrices */ for i:= 1 to n -l+ 1 do begin j :=i+ l-1: m[i, j] := ; /* initialization */ for k := i to j-1 do /*find k for an optimal parenthesization*/ begin if q< m[i,j] then begin m[i, j] := q; s[i, j] := k end end end end 21" }, { "page_index": 458, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_022.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_022.png", "page_index": 458, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:19:41+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM Step 4: Construct the final optimal solution from computed information We use table s[1..n, 1..n] to determine the best way to multiply the matrices. Each entry s[i, j] records the value of k such that the Az and A k+1 Given the matrices A = , table s computed by 0 MATRIX-CHAIN-ORDER and the indices i and.j, the following recursive procedure MATRIX-CHAIN-MULTIPLY computes the matrix chain product t A. The procedure returns the result in parameter AIJ. With the call: MATRIX-CHAIN-MULTIPLY(A,s,1,n,A1N) the procedure returns the matrix chain product with the parameter A1N. 22" }, { "page_index": 459, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_023.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_023.png", "page_index": 459, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:19:46+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM procedure MATRIX-CHAIN-MULTIPLY(A, s, i, j, AIJ)) begin if j> i then begin MATRIX-CHAIN-MULTIPLY(A, s, i, s[i, j], X): MATRIX-CHAIN-MULTIPLY(A,s, s[i, j]+1,j, Y): MATRIX-MULTIPLY(X, Y, AIJ): end else assign Ai to AIJ: end; 23" }, { "page_index": 460, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_024.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_024.png", "page_index": 460, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:19:52+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM Given the following matrices: A1 30 x 35 A2 35 x 15 A3 15 x 5 A4 5 x 10 A5 10 x 20 A6 20 x 25 Po = 30; P1 = 35; P2 = 15; P3 = 5; P4 = 10; P5 = 20; P6 = 25 What are tables m and s? What is the most cost-effective way for parenthesization to perform this matrix-chain multiplication problem? 24" }, { "page_index": 461, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_025.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_025.png", "page_index": 461, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:20:06+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM i 1 2 3 Table m 4 5 6 j 6 15125 10500 5375 3500 5000 0 5 11875 7125 2500 1000 0 4 9375 4375 750 0 3 7875 2625 0 2 15750 0 1 0 1 2 Table s 3 4 5 6 6 3 3 3 5 5 1 5 3 3 3 4 1 4 3 3 3 1 3 1 2 1 Result : 2 1 1 (A1 (A2 A3)) ((A4 A5) A6) 1 25" }, { "page_index": 462, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_026.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_026.png", "page_index": 462, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:20:21+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM i 1 2 3 Table m 4 5 6 j 6 15125 10500 5375 3500 5000 0 l= 2, 1k: 5 11875 7125 2500 1000 0 Compute : k=1:m[1,2] 4 9375 4375 750 0 k=2: m[2,3] 3 7875 2625 0 k=3: m[3,4] 15750 0 k=4: m[4,5] 1 = 2, 1 k k=5: m[5,6] 1 0 1 2 Table s 3 4 5 6 6 3 3 3 5 5 1 4 5 3 3 3 1 4 3 3 3 - 3 1 2 2 1 = 2, 1 k 1 26" }, { "page_index": 463, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_027.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_027.png", "page_index": 463, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:20:37+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM i 1 2 3 Table m 4 5 6 j 6 15125 10500 5375 3500 5000 0 l= 3, 2k: Compute : 5 11875 7125 2500 1000 0 k=1,2:m[1,3] 4 9375 4375 750 0 k=2, 3:m[2,4] 3 7875 2625 0 1 = 3, k=3,4:m[3,5] 2 k 2 15750 0 k=4, 5: m[4,6] 1 0 1 2 3 4 5 Table s 6 6 3 3 3 5 5 1 5 3 3 3 4 1 4 3 3 3 - 3 2 1 1 = 3, 2 1 2 k 1 1 27" }, { "page_index": 464, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_028.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_028.png", "page_index": 464, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:20:51+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM i Table m 1 2 3 4 5 6 j 6 15125 10500 5375 3500 5000 0 l = 4, 3 k: 5 11875 7125 2500 1000 0 Compute : 4 9375 4375 750 k=1,2,3: m[1, 4] 0 1 = 4, k=2,3, 4: m[2, 5] 3 k 3 7875 2625 0 k=3,4, 5: m[3,6] 2 15750 0 1 0 1 2 3 4 5 Table s 6 6 3 3 3 5 5 1 5 3 3 3 4 1 4 3 3 3 1 1 = 4, 3 k 3 1 2 1 2 1 1 1 28" }, { "page_index": 465, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_029.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_029.png", "page_index": 465, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:21:06+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM i 1 2 3 4 5 Table m 6 j 6 15125 10500 5375 3500 5000 0 5 11875 7125 2500 1000 0 1 = 5, l = 5,4 k: 4 k 4 9375 4375 750 0 Compute : 3 7875 2625 0 k=1, 2, 3,4: m[1, 5] 2 15750 0 k=2, 3, 4, 5: m[2,6] 1 0 1 2 3 Table s 4 5 6 6 3 3 3 5 5 1 5 3 3 3 4 1 1 = 5, 4 k 4 3 3 3 1 3 1 2 1 2 1 1 1 29" }, { "page_index": 466, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_030.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_030.png", "page_index": 466, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:21:21+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM i 1 2 3 Table m 4 5 6 1 6 15125 10500 5375 3500 5000 0 1= 6, 5 k 5 11875 7125 2500 1000 0 4 9375 4375 750 0 l = 6, 5 k: 3 7875 2625 0 Compute: 2 15750 0 k=1, 2, 3, 4, 5: m[1, 6] 1 0 Table s 1 2 3 4 5 6 6 3 3 3 5 5 1 = 6, 1 5 k 5 3 3 3 4 1 4 3 3 3 1 3 1 2 1 2 1 1 1 30" }, { "page_index": 467, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_031.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_031.png", "page_index": 467, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:21:27+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM Po = 30; P1 = 35; P2 = 15; P3 = 5; P4 = 10; Ps = 20; P6 = 25 Compute tables m and s: -k-1- s[1,2]=1 -k-2- s[2,3]=2 k=3- s[3,4]=3 k=4- s[4,5]=4 k=5- s[5,6]=5 31" }, { "page_index": 468, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_032.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_032.png", "page_index": 468, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:21:33+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM Po = 30; P1 = 35; P2 = 15; P3 = 5; P4 = 10; Ps = 20; P6 = 25 Compute tables m and s: m1,3] = min - k = 1 - s[1,3] = 1 m2,4]= min - k = 3 -s[2,4] = 3 m3,5] = min k = 3 - s[3,5] = 3 m4,6] = min 32" }, { "page_index": 469, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_033.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_033.png", "page_index": 469, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:21:41+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM Po = 30; P1 = 35; P2 = 15; P3 = 5; P4 = 10; Ps = 20; P6 = 25 Compute tables m and s: m[1,4] = min3 m[1,2] + m[3,4] + PoPzP4 = 15750 + 750 + 30.15.10 = 21000 k = 3 - s[14l m[3,6] = min3 m[3,4] + m[5,6] + P2P4P6 = 750 + 5000 + 15.10.25 = 9500 k = 3 - s[3,6] = 3 33" }, { "page_index": 470, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_034.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_034.png", "page_index": 470, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:21:49+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM Po = 30; P1 = 35; P2 = 15; P3 = 5; P4 = 10; Ps = 20; P6 = 25 Compute tables m and s: m[1,2] + m[3,5] + PoPzPs = 15750 + 2500 + 30.15.20 = 27250 m1,5 = min - k = 3 - s[1,5] = 3 m[2,3] + m[4,6] + P1P3P6 = 2625 + 3500 + 35.5.25 = 10500 m[2,6] = min k = 3 - s[2,6] l = 3 34" }, { "page_index": 471, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_035.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_035.png", "page_index": 471, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:21:54+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM Po = 30; P1 = 35; P2 = 15; P3 = 5; P4 = 10; Ps = 20; P6 = 25 Compute tables m and s: m1,6 = min k = 3 - s[1,6] 3 35" }, { "page_index": 472, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_036.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_036.png", "page_index": 472, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:22:10+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM i 1 2 3 Table m 4 5 6 j 6 15125 10500 5375 3500 5000 0 5 11875 7125 2500 1000 0 4 9375 4375 750 0 3 7875 2625 0 2 15750 0 1 0 Table s 1 2 3 4 5 6 6 3 3 3 5 5 1 How do we derive the 5 3 3 3 4 1 optimal parenthesization 4 3 3 3 1 from table s? 3 1 2 Result: 2 1 1 (A1 (A2 A3)) ((A4 A5) A6) 1 36" }, { "page_index": 473, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_037.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_037.png", "page_index": 473, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:22:27+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM i 1 2 3 Table m 4 5 6 j 6 15125 10500 5375 3500 5000 0 5 11875 7125 2500 1000 0 4 9375 4375 750 0 3 7875 2625 0 2 15750 0 1 0 Table s 1 2 3 4 5 6 6 3 3 3 5 5 1 How do we derive the 5 3 3 3 4 1 optimal parenthesization 4 3 3 3 1 from table s? 3 1 2 Result: 2 1 1 (A1 A2 A3) (A4 A5 A6) 1 37" }, { "page_index": 474, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_038.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_038.png", "page_index": 474, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:22:41+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM i 1 2 3 Table m 4 5 6 j 6 15125 10500 5375 3500 5000 0 5 11875 7125 2500 1000 0 4 9375 4375 750 0 3 7875 2625 0 2 15750 0 1 0 Table s 1 2 3 4 5 6 6 3 3 3 5 5 1 How do we derive the 5 3 3 3 4 1 optimal parenthesization 4 3 3 3 1 from table s? 3 1 2 Result: 2 1 1 (A1 (A2 A3)) (A4 A5 A6) 1 38" }, { "page_index": 475, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_039.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_039.png", "page_index": 475, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:22:57+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM i 1 2 3 Table m 4 5 6 j 6 15125 10500 5375 3500 5000 0 5 11875 7125 2500 1000 0 4 9375 4375 750 0 3 7875 2625 0 2 15750 0 1 0 Table s 1 2 3 4 5 6 6 3 3 3 5 5 1 How do we derive the 5 3 3 3 4 1 optimal parenthesization 4 3 3 3 1 from table s? 3 1 2 Result: 2 1 1 (A1 (A2 A3)) ((A4 A5) A6) 1 39" }, { "page_index": 476, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_040.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_040.png", "page_index": 476, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:23:06+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM MATRIX-CHAIN-MULTIPLY(A, s, 1, 6, A1n) //s/1,6] = 3 9 (A1 A2 A3)(A4 A5 A6) MATRIX-CHAIN-MULTIPLY(A, s, 1, 3, X)//s[1,3] = 1 >(A1 (A2 A3)) MATRIX-CHAIN-MULTIPLY(A, S, 1, 1, XX) A1 > XX MATRIX-CHAIN-MULTIPLY(A, s, 2, 3, YY) //s[2,3] = 2 MATRIX-CHAIN-MULTIPLY(A, S, 2, 2, XXX) A2 > XXX MATRIX-CHAIN-MULTIPLY(A, S, 3, 3, YYY) A3 > YYY MATRIX-MULTIPLY(XXX, YYY, YY) //YY = A2*A3 MATRIX-MULTIPLY(XX, YY, X) //X = A1*(A2*A3) MATRIX-CHAIN-MULTIPLY(A, s, 4, 6, Y) //s[4,6] = 5 > ((A4 A5) A6) MATRIX-CHAIN-MULTIPLY(A, s, 4, 5, XX) //s[4,5] = 4 MATRIX-CHAIN-MULTIPLY(A, S, 4, 4, XXX A4 > XXX MATRIX-CHAIN-MULTIPLY(A, S, 5, 5, YYY) A5 > YYY MATRIX-MULTIPLY(XXX, YYY, XX) //XX = A4*A5 MATRIX-CHAIN-MULTIPLY(A, S, 6, 6, YY) A6 -> YY MATRIX-MULTIPLY(XX, YY, Y) //Y = (A4*A5)*A6 MATRIX-MULTIPLY(X,Y,A1n)//A1n = (A1*(A2*A3)((A4*A5)*A6 40" }, { "page_index": 477, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_041.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_041.png", "page_index": 477, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:23:13+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM Time complexity of the dynamic programming algorithm for matrix-chain multiplication problem to fully parenthesize the product A1Az...An in such a way that minimizes the number of scalar multiplications for the product Abstract operation : multiplication Best, Average, Worst cases: 41" }, { "page_index": 478, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_042.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_042.png", "page_index": 478, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:23:20+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM procedure MATRIX-CHAIN-ORDER(p, m, s): begin n := length[p] - 1: for i :- 1 to n do m[i, i] := 0: for l := 2 to n do /* 1: length of the chain = the number of matrices */ for i:= 1 to n -l+ 1 do begin j :=i+l-1: m[i, jl := co; /* initialization */ for k := i to j-1 do /*find k for an optimal parenthesization*/ begin if q< m[i,j] then Abstract operation : begin m[i,j] := q; s[i, j] := k end multiplication end end end 42" }, { "page_index": 479, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_043.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_043.png", "page_index": 479, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:23:27+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM Time complexity of the dynamic programming algorithm for matrix-chain multiplication problem to fully parenthesize the product A1Az...A, in such a way that minimizes the number of scalar multiplications for the product Abstract operation : multiplication Best, Average, Worst cases: Iterative algorithm: Cn = 2 =2.n i=1.n-l+1 k=i.i+l-2 43" }, { "page_index": 480, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_044.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_044.png", "page_index": 480, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:23:38+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM Time complexity of the dynamic programming algorithm Abstract operation : multiplication Best, Average, Worst cases: Cn = O(n3) n n-l+1 i+l-2 n n-l+1 n n-l+1 Cn = 2 = 2(i + l - 2 - i + 1) = 2(l -1) l=2 i=1 k=i l=2 i=1 l=2 i=1 n n 2(l -1)(n - l +1-1+1) = Cn 2(l -1)(n - l +1) l=2 l=2 n(n - 1) (n - 1)n(2n - 1) n(n - 1)(3n - 2n + 1 Cn = 2n 2 6 3 44" }, { "page_index": 481, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_045.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_045.png", "page_index": 481, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:23:46+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM Time complexity of the dynamic programming algorithm Abstract operation : multiplication Best, Average, Worst cases: Cn = O(n3) n n-l+1 i+l-2 n n-l+1 n n-l+1 Cn = 2 = 2(i + l - 2 - i + 1) = 2(l -1) l=2 i=1 k=i l=2 i=1 l=2 i=1 n(n - 1) (n - 1)n(2n - 1) n(n - 1)(3n - 2n + 1) Cn = 2n 2 6 3 Cn i 3 45" }, { "page_index": 482, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_046.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_046.png", "page_index": 482, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:23:57+07:00" }, "raw_text": "BK 5.1.1. Matrix-chain multiplication TP.HCM Your turn : 5.1.1.1. Given the following matrices, how different is (A1Az)A3 from A1(AzA3) in terms of cost? A1: 3 x 1000, A,: 1000 x 3, A3: 3 x 1000 Given the following matrices, what are tables m and s? What is the most cost-effective way for parenthesization to perform the matrix-chain multiplication problem? 5.1.1.4. 5.1.1.2. 5.1.1.3. A1 5 x 10 A1 10 x 5 A1 8 x 3 A2 10 x 4 A2 A2 5 x 15 3 x 2 A3 4 x 6 A3 A3 15 x 25 2 x 19 A4 6 x 10 A4 A4 25 x 20 19 x 18 As 10 x 2 46" }, { "page_index": 483, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_047.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_047.png", "page_index": 483, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:24:07+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence 0 m example, a sequence is X = . Given Z =. Z is called a subsequence of X with the corresponding index sequence <2,3,5,7> > A subsequence of a sequence is just the given sequence with some elements left out Given two sequences X and Y, Z is a common subsequence of X and Y if Z is a subsequence of both X and Y. In the longest-common-subsequence problem, given two m wish to find a maximum length subsequence common (LCS) of X and Y. 47" }, { "page_index": 484, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_048.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_048.png", "page_index": 484, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:24:12+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence In the longest-common-subsequence problem, given m subsequence (LCS) of X and Y. X= Y= , , and are LCS's of X and Y. How to find them efficiently? 48" }, { "page_index": 485, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_049.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_049.png", "page_index": 485, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:24:20+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence In the longest-common-subsequence problem, given m subsequence (LCS) of X and Y. Step 1: Characterize the structure of an optimal solution Step 2: Recursively define the value of an optimal solution Step 3: Compute the value of an optimal solution in a bottom-up fashion Step 4: Construct the final optimal solution from computed information 49" }, { "page_index": 486, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_050.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_050.png", "page_index": 486, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:24:35+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence Step 1: Characterize the structure of an optimal solution >, we define the i-th m > m l. If x and Y : x m n-1 n m m- 2. If x... . 7yn t then z x implies that Z is LCS of X m m 3.If xmyn t then Z Yn implies that Z is LCS of X and Y n-1: m n > To find an LCS of X and Y, we need to find the LCS's of x l Y X and Y. Each of these 1 a 1 a n- n-1? YL subproblems has the subsubproblem of finding the LCS. 50" }, { "page_index": 487, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_051.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_051.png", "page_index": 487, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:24:41+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence Step 2: Recursively define the value of an optimal solution Let's define c[i,j] to be the length of LCS of the subsequences X and Y. If either i = 0 or j = 0, one of the sequences has length 0. so the LCS has length 0. The optimal substructure of the LCS problem gives the recursive formula: if i = 0 or j = 0 if i,j>0 and x;= Yj c[i,j] = c[i-1,j-1]+1 if i,j>0 and x;+ yj max (ci,j-1],c[i-1,jD 51" }, { "page_index": 488, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_052.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_052.png", "page_index": 488, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:24:48+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence Step 3: Compute the value of an optimal solution in a bottom-up fashion Based on the recursive formula, we could write a recursive algorithm to compute the length of an LCS of two sequences. However, we compute the solutions in a bottom-up fashion. 0 ..> as inputs. m n It stores the c[i, j] values in table c[0..m, 0..n]. It also maintains table b[1..m, 1..n] to simplify construction of an optimal solution. 52" }, { "page_index": 489, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_053.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_053.png", "page_index": 489, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:24:59+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence procedure LCS-LENGTH(X, Y) begin j-1 1 m := length[X]; n := length[Y]; [i-1,j-1] [i-1,j] i-1 for i := 1 to m do c[i, 0] := 0: for j := 1 to n do c[0, jl := 0: - [i,j-1] [i,j] for i := 1 to m do for j := 1 to n do if xj = yj then begin c[i, j] := c[i-1, j-1]+ 1; b[i, j] :=\" end else if c[i - 1, j] > = c[i, j-1] then begin c[i, j] := c[i - 1, j]; b[i, j] := \"T\" end else begin c[i, j] := c[i, j-1]; b[i, j] := \"< 2 end end; 53" }, { "page_index": 490, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_054.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_054.png", "page_index": 490, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:25:09+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence Step 4: Construct the.final optimal solution from computed information The table b is used l to procedure PRINT-LCS(b, X, i, j) begin construct an LCS of if i<> 0 and j<> 0 then X = < and if b[i,j]=\" \" then m begin PRINT-LCS(b, X,i- 1 ,j -l) : The recursive procedure print x: prints out an LCS of X end and Y. The initial else if b[i,i] = \"T\" then invocation is: PRINT-LCS (b, X, i-1,j) else PRINT-LCS(b, X,i,j-1) PRINT-LCS(b, X,m, n) end; 54" }, { "page_index": 491, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_055.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_055.png", "page_index": 491, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:25:15+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence Given two sequences X and Y as follows. Compute tables c and b and then, find the maximum length of their LCs. List one LCS from table b. X = Y = 55" }, { "page_index": 492, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_056.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_056.png", "page_index": 492, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:25:34+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 0 b[1..7, 1..6] A 0 T 0 T 0 T 1 K 1 < 1 z B 1 K 1 T 0 1 < 1 < 2 K 2 < C 1 T 1 T 0 2 2 < 2 T 2 T B 1 z 1 T 2 T 2 T 3 R 3 < D 1 T 0 2 K 2 T 2 T 3 T 3 T A 0 1 T 2 T 2 T 3 R 3 T 4 K B 2 T 2 T 0 1 R 3 T 4 K 4 T 56" }, { "page_index": 493, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_057.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_057.png", "page_index": 493, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:25:46+07:00" }, "raw_text": "5.1.2. Longest t common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 b[1..7, 1..6] A 0 T 0 T 0 T 1 r 1 1 r B 1 r 1 T 0 1 < 1 2 K 2 < LCS = C 1 T 1 T 0 2 R 2< 2 T 2 T B 1 T 2 T 2 T 1 R 3 R 3 < D 1 T 2 z 2 T 2 T 0 3 T 3 T A 0 1 T 2 T 2 T 3 R 3 T 4 R B 2 T 2 T 1 R 3 T 4 T 0 4 K 57" }, { "page_index": 494, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_058.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_058.png", "page_index": 494, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:25:55+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 b[1..7, 1..6] A B 0 C 0 B D 0 A 0 B 0 58" }, { "page_index": 495, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_059.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_059.png", "page_index": 495, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:26:03+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj b[1..7, 1..6] A 0 T B 0 C 0 B D 0 A 0 B 0 59" }, { "page_index": 496, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_060.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_060.png", "page_index": 496, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:26:14+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj O 6[1..7, 1..6] A 0 T 0 T B 0 C 0 B D 0 A 0 B 0 60" }, { "page_index": 497, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_061.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_061.png", "page_index": 497, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:26:22+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj O 6[1..7, 1..6] A 0 T 0 T 0 T B 0 C 0 B D 0 A 0 B 0 61" }, { "page_index": 498, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_062.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_062.png", "page_index": 498, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:26:34+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj O 0 6[1..7, 1..6] A 0 T 0 T 0 T 1 r B 0 C 0 B D 0 A 0 B 0 62" }, { "page_index": 499, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_063.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_063.png", "page_index": 499, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:26:42+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 6[1..7, 1..6] A 0 T 0 T 0 T 1 r 1 < B 0 C 0 B D 0 A 0 B 0 63" }, { "page_index": 500, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_064.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_064.png", "page_index": 500, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:26:52+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj O b[1..7, 1..6] A 0 T 0 T 0 T 1 K 1 < 1 r B 0 C 0 B D 0 A 0 B 0 64" }, { "page_index": 501, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_065.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_065.png", "page_index": 501, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:27:01+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 b[1..7, 1..6] A 0 T 0 T 0 T 1 K 1 < 1 z B 0 1 R C 0 B D 0 A 0 B 0 65" }, { "page_index": 502, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_066.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_066.png", "page_index": 502, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:27:13+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 6[1..7, 1..6] A 0 T 0 T 0 T 1 K 1 < 1 z B 0 1 z 1 < C 0 B D 0 A 0 B 0 66" }, { "page_index": 503, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_067.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_067.png", "page_index": 503, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:27:23+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 6[1..7, 1..6] A 0 T 0 T 0 T 1 K 1 < 1 z B 0 1 K 1 < 1 < C 0 B D 0 A 0 B 0 67" }, { "page_index": 504, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_068.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_068.png", "page_index": 504, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:27:37+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 6[1..7, 1..6] A 0 T 0 T 0 T 1 r 1 < 1 z B 1 T 0 1 K 1 A 1 C 0 B D 0 A 0 B 0 68" }, { "page_index": 505, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_069.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_069.png", "page_index": 505, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:27:46+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 6[1..7, 1..6] A 0 T 0 T 0 T 1 r 1 < 1 K B 0 1 K 1 A 1 1 T 2 R C 0 B D 0 A 0 B 0 69" }, { "page_index": 506, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_070.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_070.png", "page_index": 506, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:28:01+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] xi 0 0 0 0 0 0 0 b[1..7, 1..6] A 0 T 0 T 0 T 0 1 r 1 < 1 z B 1 r 1 < 1 T 0 1 < 2 r 2 < C 1 1 0 2 r 2< 2 T 2 T B 1 2 T 2 T 0 1r 3 R 3< D 1 2 R 2 T 2 T 3 T 3 T 0 A 1 0 2 T 2 T 3 R 3 T 4 R B 2 T 2 T 3 T 1 r 4 R 4 T 0 70" }, { "page_index": 507, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_071.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_071.png", "page_index": 507, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:28:15+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 0 b[1..7, 1..6] A 0 T 0 T 0 T 0 1 K 1 < 1 z B 1 K 1 T 0 1 < 1 < 2 z 2 < LCS = C 1 T 1 T 0 2 5 2< 2 T 2 T B 2 T 1 z 1 T 2 T 3 R 3 < D 1 T 2 K 2 T 2 T 0 3 T 3 T A 0 1 T 2 T 2 T 3 R 3 T 4 K B 2 T 2 T 0 1 z 3 T 4 R 4 T 71" }, { "page_index": 508, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_072.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_072.png", "page_index": 508, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:28:30+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 b[1..7, 1..6] A 0 T 0 T 0 T 1 K 1 < 1 z B 1 K 1 T 0 1 < 1 < 2 K 2 < LCS = C 1 T 1 T 0 2 5 2< 2 T 2 T B 2 T 1 z 1 T 2 T 3 R 3 < D 0 1 T 2 K 2 T 2 T 3 T 3 T A 0 1 T 2 T 2 T 3 R 3 T 4 R B 2 T 2 T 0 1 z 3 T 4 K 4 T 72" }, { "page_index": 509, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_073.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_073.png", "page_index": 509, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:28:45+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 b[1..7, 1..6] A 0 T 0 T 0 T 1 K 1 < 1 z B 1 K 1 T 0 1 < 1 < 2 K 2 < LCS = C 1 T 1 T 0 2 5 2 < 2 T 2 T B 1 z 1 T 2 T 2 T 3 R 3 < D 1 T 0 2 K 2 T 2 T 3 T 3 T A 0 1 T 2 T 2 T 3 R 3 T 4 R B 2 T 2 T 3 T 4 T 0 1 R 4 K 73" }, { "page_index": 510, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_074.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_074.png", "page_index": 510, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:28:59+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 b[1..7, 1..6] A 0 T 0 T 0 T 1 K 1 < 1 z B 1 K 1 T 0 1 < 1 < 2 K 2 < LCS = C 1 T 1 T 0 2 5 2 < 2 T 2 T B 1 z 1 T 2 T 2 T 3 Z 3 < D 1 T 0 2 z 2 T 2 T 3 T 3 T A 0 1 T 2 T 2 T 3 R 3 T 4 R B 2 T 2 T 3 T 4 T 0 1 R 4 K 74" }, { "page_index": 511, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_075.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_075.png", "page_index": 511, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:29:13+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 b[1..7, 1..6] A 0 T 0 T 0 T 1 K 1 < 1 z B 1 K 1 T 0 1 < 1 < 2 K 2 < LCS = C 1 T 1 T 0 2 5 2 2 T 2 T B 1 T 2 T 1 z 2 T 3 5 3 < D 1 T 0 2 z 2 T 2 T 3 T 3 T A 0 1 T 2 T 2 T 3 R 3 T 4 R B 2 T 2 T 1 R 3 T 4 T 0 4 K 75" }, { "page_index": 512, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_076.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_076.png", "page_index": 512, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:29:29+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 b[1..7, 1..6] A 0 T 0 T 0 T 1 K 1 < 1 z B 1 K 1 T 0 1 < 1 < 2 K 2 < LCS = C 1 T 1 T 0 2 R 2< 2 T 2 T B 1 T 2 T 2 T 1 R 3 R 3 < D 1 T 0 2 z 2 T 2 T 3 T 3 T A 1 T 2 T 2 T 3 R 3 T 0 4 R B 2 T 2 T 1 R 3 T 4 T 0 4 K 76" }, { "page_index": 513, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_077.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_077.png", "page_index": 513, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:29:42+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 b[1..7, 1..6] A 0 T 0 T 0 T 1 r 1 < 1 z B 1 K 1 T 0 1 < 1 2 K 2 < LCS = C 1 T 1 T 0 2 R 2< 2 T 2 T B 1 T 2 T 2 T 1 R 3 R 3 < D 1 T 2 T 2 T 0 2 z 3 T 3 T A 1 T 2 T 2 T 3 R 3 T 0 4 R B 2 T 2 T 1 R 3 T 4 T 0 4 K 77" }, { "page_index": 514, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_078.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_078.png", "page_index": 514, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:29:57+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 b[1..7, 1..6] A 0 T 0 T 0 T 1 r 1 1 r B 1 K 1 T 0 1 < 1 2 K 2 < LCS = C 1 T 1 T 0 2 R 2< 2 T 2 T B 1 T 2 T 2 T 1 R 3 R 3 < D 1 T 2 z 2 T 2 T 0 3 T 3 T A 1 T 2 T 2 T 3 R 3 T 0 4 R B 2 T 2 T 1 R 3 T 4 T 0 4 K 78" }, { "page_index": 515, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_079.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_079.png", "page_index": 515, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:30:13+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 b[1..7, 1..6] A 0 T 0 T 0 T 1 r 1 1 r B 1 z 1 T 0 1 < 1 2 K 2 < LCS = C 1 T 1 T 0 2 R 2< 2 T 2 T B 1 T 2 T 2 T 1 R 3 R 3 < D 1 T 2 z 2 T 2 T 0 3 T 3 T A 0 1 T 2 T 2 T 3 R 3 T 4 R B 2 T 2 T 1 R 3 T 4 T 0 4 K 79" }, { "page_index": 516, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_080.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_080.png", "page_index": 516, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:30:27+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 0 b[1..7, 1..6] A 0 T 0 T 0 T O 1 r 1 1 r B 1 z 1 T 0 1 < 1 2 R 2 < LCS = C 1 T 1 T 0 2 R 2< 2 T 2 T B 1 T 2 T 2 T 1 z 3 R 3 < D 1 T 2 z 2 T 2 T 0 3 T 3 T A 0 1 T 2 T 2 T 3 R 3 T 4 R B 2 T 2 T 1 R 3 T 4 T 0 4 K 80" }, { "page_index": 517, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_081.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_081.png", "page_index": 517, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:30:44+07:00" }, "raw_text": "5.1.2. Longest t common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 0 b[1..7, 1..6] A 0 T 0 T 0 T O 1 r 1< 1 r B 1 r 1 T 0 1 < 1 2 R 2 < LCS = C 1 T 1 T 0 2 R 2< 2 T 2 T B 1 T 2 T 2 T 1 z 3 R 3 < D 1 T 2 z 2 T 2 T 0 3 T 3 T A 0 1 T 2 T 2 T 3 R 3 T 4 R B 2 T 2 T 0 1 R 3 T 4 T 4 K 81" }, { "page_index": 518, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_082.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_082.png", "page_index": 518, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:30:59+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 0 b[1..7, 1..6] A 0 T 0 T 0 T O 1 r 1 1 r B 1 r 1 T 0 1 < 1 2 R 2 < LCS = C 1 T 1 T 0 2 R 2< 2 T 2 T B 1 T 2 T 2 T 1 z 3 R 3 < D 1 T 2 z 2 T 2 T 0 3 T 3 T A 0 1 T 2 T 2 T 3 R 3 T 4 R B 2 T 2 T 1 R 3 T 4 T 0 4 K 82" }, { "page_index": 519, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_083.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_083.png", "page_index": 519, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:31:14+07:00" }, "raw_text": "5.1.2. Longest t common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 b[1..7, 1..6] A 0 T 0 T 0 T O 1 r 1 1 r B 1 r 1 T 0 1 < 1 2 R 2 < LCS = C 1 T 1 T 0 2 R 2< 2 T 2 T B 1 T 2 T 2 T 1 z 3 R 3 < D 1 T 2 z 2 T 2 T 0 3 T 3 T A 0 1 T 2 T 2 T 3 R 3 T 4 R B 2 T 2 T 1 R 3 T 4 T 0 4 K 83" }, { "page_index": 520, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_084.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_084.png", "page_index": 520, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:31:29+07:00" }, "raw_text": "5.1.2. Longest t common BK TP.HCM subsequence B D C A B A yj Tables c[0..7, 0..6] Xj 0 0 b[1..7, 1..6] A 0 T 0 T 0 T O 1 r 1 1 r B 1 r 1 T 0 1 < 1 2 K 2 < LCS = C 1 T 1 T 0 2 R 2< 2 T 2 T B 1 T 2 T 2 T 1 R 3 R 3 < D 1 T 2 z 2 T 2 T 0 3 T 3 T A 0 1 T 2 T 2 T 3 R 3 T 4 R B 2 T 2 T 1 R 3 T 4 T 0 4 K 84" }, { "page_index": 521, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_085.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_085.png", "page_index": 521, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:31:34+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence Time complexity for computing the length of and Y = Abstract operation : assignment Best, Average, Worst cases: CLcs = 2mn + m + n = O(mn) 85" }, { "page_index": 522, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_086.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_086.png", "page_index": 522, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:31:43+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence procedure LCS-LENGTH(X, Y) begin j-1 1 m := length[X]; n := length[Y]; [i-1,j-1] [i-1,j] i-1 for i := 1 to m do c[i, 0] := 0 RI4 for j := 1 to n do c[0, jl := 0 [i,j-1] [i,j] for i := 1 to m do for j := 1 to n do if xj = yj then begin c[i, j] := c[i-1, j-1]+ 1; b[i, j] :=\" end else if c[i - 1, j] > = c[i, j-1] then begin c[i, j] := c[i - 1, j]; b[i, j] := \"T\" end else begin c[i, jl := c[i, i-11; b[i, il := \"< 2 end end; 86" }, { "page_index": 523, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_087.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_087.png", "page_index": 523, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:31:49+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence Your turn: Given two sequences X and Y as follows. Compute tables c and b and then, find the maximum length of their LCS. List one LCS from table b. 5.1.2.1. 5.1.2.2. X = X = Y = Y = 5.1.2.3. 5.1.2.4. X = X = Y = Y = 87" }, { "page_index": 524, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_088.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_088.png", "page_index": 524, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:31:56+07:00" }, "raw_text": "5.1.2. Longest common BK TP.HCM subsequence Your turn: 5.1.2.5. Analyze the time complexity of PRINT-LCS algorithm to derive one LCS of X and Y using table b. 5.1.2.6. Modify PRINT-LCS algorithm to derive all the LCSs of X and Y using table b. Reapply your modified PRINT-LCS algorithm to the previous questions 5.1.2.1-5.1.2.4. How about the time complexity of your modified PRINT-LCS algorithm. 88" }, { "page_index": 525, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_089.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_089.png", "page_index": 525, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:32:07+07:00" }, "raw_text": "BK 5.1.3. (0-1) Knapsack TP.HCM problem \"A thief robbing a store finds it filled with N types of items of varying size and value, but has only a small knapsack of capacity M to use to carry the goods. The knapsack problem is to find the combination of items which the thief should choose for his knapsack in order to maximize the total value of all the items he takes.' Knapsack capacity: M = 17 Assume that each type has the 3 9 unlimited number of items. 4 7 8 A B C D E name What is the combination of size 3 4 7 8 9 items that maximizes the value 4 5 10 11 13 total value of the knapsack? 89" }, { "page_index": 526, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_090.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_090.png", "page_index": 526, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:32:15+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack problem TP.HCM t \"A thief robbing a store finds it filled with N types of items of varying size and value, but has only a small knapsack of capacity M to use to carry the goods. The knapsack problem is to find the combination of items which the thief should choose for his knapsack in order to maximize the total value of all the items he takes.\" > Solved using dynamic programming as follows: Step 1: Characterize the structure of an optimal solution Step 2: Recursively define the value of an optimal solution Step 3: Compute the value of an optimal solution in a bottom-up fashion Step 4: Construct the.final optimal solution from computed information 90" }, { "page_index": 527, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_091.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_091.png", "page_index": 527, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:32:22+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack TP.HCM problem Step 1: Characterize the structure of an optimal solution Let cost[0..M] be an array that stores the highest value achieved with a knapsack of varying capacity i = 0..M. Let best[0..M] be an array that stores the last item that was added into the knapsack to achieve the maximum value cost[0..M] For capacity i and item.j, if adding itemj makes cost[i] the highest value, cost[i] and best[i] are: cost[i] = cost[i - size[j]] + value[j] best[i=j 91" }, { "page_index": 528, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_092.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_092.png", "page_index": 528, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:32:30+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack TP.HCM problem Step 2: Recursively define the value of an optimal solution (max{cost[i],cost[i - sizel] + value[jl} if i - size[il > 0 cost[i] ={ unchanged if i - size[j]< 0 to be added into the knapsack. Using this formula, the algorithm is defined for the unbounded (0-1) knapsack problem with the unlimited number of items for each type. 92" }, { "page_index": 529, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_093.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_093.png", "page_index": 529, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:32:39+07:00" }, "raw_text": "BK 5.1.3. (0-1) Knapsack TP.HCM problem Step 3: Compute the value of an optimal solution in a bottom-up fashion for i := 0 to M do cost[i] := 0; o /* each of item type for j := 1 to N do begin for i := 1 to M do /* i means capacity if i - size[j] >= 0 then if cost[i]< (cost[i - size[j]] + val[j]) then begin cost[i] := cost[i - size[jll + val[jl best[i:=j end; end; 93" }, { "page_index": 530, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_094.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_094.png", "page_index": 530, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:32:47+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack TP.HCM problem Step 4: Construct the final optimal solution from computed information The final optimal solution is stored in cost[M] and best[M] for the maximum total value of the knapsack and the last item added into the knapsack corresponding to the maximum value Other items are then derived iteratively by subtracting the total value downto 0 kv := cost[M]; s := M; while (kv>0) begin print best[s]: kv := kv - val[best[s]]; s := s - size[best[s]]; end; 94" }, { "page_index": 531, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_095.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_095.png", "page_index": 531, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:32:54+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack problem TP.HCM Given the items and knapsack as follows. Find the combination of items that maximizes the total value of the knapsack. N = 5, M = 17, the unlimited number of items for each type A B C D E val[A] = 4 val[B] = 5 val[C] = 10 val[D] = 11 val[E] = 13 95" }, { "page_index": 532, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_096.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_096.png", "page_index": 532, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:33:29+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack problem TP.HCM 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 A size = 3 val = 4 cost 0 0 4 4 4 8 8 8 12 12 12 16 16 16 20 20 20 best A A A A A A A A A A A A A A : A : B size = 4 val = 5 cost 0 0 4 5 5 8 9 10 12 13 14 16 17 18 20 21 22 best - A B A 8 B A B B A B B A B : c size = 7 val = 10 cost 0 0 4 5 5 8 10 10 12 14 15 16 18 20 20 22 24 best 1 1 A 8 B A c 8 A C A c c A C c D size = 8 val = 11 cost 0 0 4 5 5 8 10 11 12 14 15 16 18 20 21 22 24 best : A B B A C D A C C A C C D c C E size = 9 val = 13 cost 0 0 4 5 5 8 10 11 13 14 15 17 18 20 21 23 24 best A B B A D E C E c c D E C -" }, { "page_index": 533, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_097.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_097.png", "page_index": 533, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:33:44+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack problem TP.HCM 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 A size = 3 val = 4 cost 0 0 4 4 4 8 8 8 12 12 12 16 16 16 20 20 20 best A A A A A A A A A A A A A A A : : B size = 4 val = 5 cost 0 0 4 5 5 8 9 10 12 13 14 16 17 18 20 21 22 best A B B A 8 B A B A B B A B 8 c size = Before considering B: cost 0 0 20 20 22 24 cost[8] = 8, best[8] = A best C A 1 c 1 Consider B: D size = 0 0 cost[8] = cost[8-size[B]] + val[B] cost 20 21 22 24 best cost[8] = cost[4] + 5 = 5 + 5 = 10 C D c C 1 E size = After considering B: cost 0 0 20 21 23 24 cost[8] = 10, best[8] = B best D E C" }, { "page_index": 534, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_098.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_098.png", "page_index": 534, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:33:59+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack problem TP.HCM 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 A size = 3 val = 4 cost 0 0 4 4 4 8 8 8 12 12 12 16 16 16 20 20 20 best A A A A A A A A A A A A A A A : : B size = 4 val = 5 cost 0 0 4 5 5 8 9 10 12 13 14 16 17 18 20 21 22 best A B A 8 A B A B B A B 8 c size = Before considering B: cost 0 0 20 20 22 24 cost[9] = 12, best[9] = A best C A 1 c 1 Consider B: D size = 0 0 cost[9] = cost[9-size[B]] + val[B] cost 20 21 22 24 best cost[9] = cost[5] + 5 = 5 + 5 = 10 C D c C 1 E size = After considering B: cost 0 0 20 21 23 24 cost[9] = 12, best[9] = A best D E C" }, { "page_index": 535, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_099.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_099.png", "page_index": 535, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:34:14+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack problem TP.HCM 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 A size = 3 val = 4 cost 0 0 4 4 4 8 8 8 12 12 12 16 16 16 20 20 20 best A A A A A A A A A A A A A A A : B size = 4 val = 5 cost 0 0 4 5 5 8 9 10 12 13 14 16 17 18 20 21 22 best A B A A B A B 8 A B 8 c size = Before considering B: cost 0 0 20 20 22 24 cost[10] = 12,best[10] = A best A 1 c 1 Consider B: D size = cost 0 0 cost[10] = cost[10-size[B]] + val[B] 20 21 22 24 best cost[10] = cost[6] + 5 = 8 + 5 = 13 C D c C 1 E size = After considering B: cost 0 0 20 21 23 24 cost[10] = 13, best[10] = B best C D E C" }, { "page_index": 536, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_100.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_100.png", "page_index": 536, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:34:33+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack problem TP.HCM 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 A size = 3 val = 4 cost 0 0 4 4 4 8 8 8 12 12 12 16 16 16 20 20 20 best A A A A A A A A A A A A A A : A : B size = 4 val = 5 cost 0 0 4 5 5 8 9 10 12 13 14 16 17 18 20 21 22 best - A B A 8 B A B B A B B A B : c size = 7 val = 10 cost 0 0 4 5 5 8 10 10 12 14 15 16 18 20 20 22 24 best 1 1 A 8 B A c 8 A C C A c c A C c D size = 8 val = 11 cost 0 0 4 5 5 8 10 11 12 14 15 16 18 20 21 22 24 best : A B B A C D A C C A C C D c C E size = 9 val = 13 cost 0 0 4 5 5 8 10 11 13 14 15 17 18 20 21 23 24 best A B B A D E C E c c D E c -" }, { "page_index": 537, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_101.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_101.png", "page_index": 537, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:34:54+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack problem TP.HCM 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 A size = 3 val = 4 cost 0 0 4 4 4 8 8 8 12 12 12 16 16 16 20 20 20 best A A A A A A A A A A A A A A : A B size = 4 val = 5 cost 0 0 4 5 5 8 9 10 12 13 14 16 17 18 20 21 22 best - A B A 8 B A B B A B B A B : c size = 7 val = 10 cost 0 0 4 5 5 8 10 10 12 14 15 16 18 20 20 22 24 best 1 1 A 8 B A c 8 A C C A c c A C c D size = 8 val = 11 cost 0 0 4 5 5 8 10 11 12 14 15 16 18 20 21 22 24 best : A B B A C D A C C A C C D c C E size = 9 val = 13 cost 0 0 4 5 5 8 10 11 13 14 15 17 18 20 21 23 24 best A B B A D E c E c c D E c -" }, { "page_index": 538, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_102.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_102.png", "page_index": 538, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:35:14+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack problem TP.HCM 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 A size = 3 val = 4 cost 0 0 4 4 4 8 8 8 12 12 12 16 16 16 20 20 20 best A A A A A A A A A A A A A A : A B size = 4 val = 5 cost 0 0 4 5 5 8 9 10 12 13 14 16 17 18 20 21 22 best - A B A 8 B A B B A B B A B : c size = 7 val = 10 cost 0 0 4 5 5 8 10 10 12 14 15 16 18 20 20 22 24 best 1 1 A 8 B A c 8 A C C A c c A C c D size = 8 val = 11 cost 0 0 4 5 5 8 10 11 12 14 15 16 18 20 21 22 24 best : A B B A C D A C C A C C D c C E size = 9 val = 13 cost 0 0 4 5 5 8 10 11 13 14 15 17 18 20 21 23 24 best A B B A D E c E c c D E c -" }, { "page_index": 539, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_103.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_103.png", "page_index": 539, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:35:17+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack problem TP.HCM N = 5, M = 17, the unlimited number of items for each type A B C D E vaI[A] = 4 val[B] = 5 val[C] = 10 val[D] = 11 val[E] = 13 The maximum total value of the knapsack = 24 Combination of items = {C, C, A} 103" }, { "page_index": 540, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_104.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_104.png", "page_index": 540, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:35:22+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack TP.HCM problem Time complexity of finding the combination of items of N types that maximizes the total value of the knapsack M Abstract operation : assignment Worst case: C 2MN + M = O(MN) knapsack Note: the algorithm works with positive . integers for M and each size. It is (unbounded) 0-1 knapsack problem. 104" }, { "page_index": 541, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_105.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_105.png", "page_index": 541, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:35:28+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack TP.HCM problem \"A thief robbing a store finds it filled with N types of items of varying size and value, but has only a small knapsack of capacity M to use to carry the goods. The knapsack problem is to find the combination of items which the thief should choose for his knapsack in order to maximize the total value of all the items he takes.' Knapsack capacity: M = 17 Assume that each type has only 3 A 7 9 one item. 8 A B C D E name What is the combination of size 3 4 7 8 9 items that maximizes the value 4 5 10 11 13 total value of the knapsack? 105" }, { "page_index": 542, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_106.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_106.png", "page_index": 542, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:35:34+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack problem TP.HCM A dynamic programming algorithm Extended from the previous one with tables cost[N+1,M+1] a and best[N+1,M+1] instead of arrays cost[M+1] and best[M+1] 0 j-size[i] j M 0 0 0 0 i-1 0 cost[i-1, j-size[i]] cost[i-1,j] i 0 cost[i, j] N 0 goal (max{cost[i - 1,j],cost[i - 1,j - size[i]] + value[i} if j - size[i] 0 cost[i,j]={ cost[i - 1,j] if j - size[i] < 0 106" }, { "page_index": 543, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_107.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_107.png", "page_index": 543, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:35:39+07:00" }, "raw_text": "BK 5.1.3. (0-1) Knapsack TP.HCM problem A dynamic for j := 0 to M do cost[0, jl := 0: programming for i := 0 to N do cost[i, 0] := 0; for i := 1 to N do /* each of item type algorithm for the begin for j := 1 to M do /* j means capacity */ bounded (0-1) cost[i, j] := cost[i-1, j]; best[i, j] :- best[i-1, j]; Knapsack problem if j - size[i] >= 0 then if cost[i-1, j]< (cost[i-1, j-size[i]] + val[i]) then with only one item begin for each type cost[i, j] := cost[i-1, j-size[i]] + val[i]; best[i, jl := i; end; Time complexity : end; O(MN) 107" }, { "page_index": 544, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_108.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_108.png", "page_index": 544, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:35:43+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack problem TP.HCM Given the items and knapsack as follows. Find the combination of items that maximizes the total value of the knapsack. N = 5, M = 17, only one item for each type A B C D E vaI[A] = 4 val[B] = 5 val[C] = 10 val[D] = 11 val[E] = 13 108" }, { "page_index": 545, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_109.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_109.png", "page_index": 545, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:36:02+07:00" }, "raw_text": "BK 5.1.3. (0-1) Knapsack problem TP.HCM 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 A size = 3 val = 4 cost 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 best A A A A A A A A A A A A A A : A : B size = 4 val = 5 cost 0 0 4 5 5 5 9 9 9 9 9 9 9 9 9 9 9 best : A B B B B B 8 B B B B : c size = 7 val = 10 cost 0 0 4 5 5 5 10 10 10 14 15 15 15 19 19 19 19 best 1 1 A 8 B B c C C c C C c c c c D size = 8 val = 11 cost 0 0 4 5 5 5 10 11 11 14 15 16 16 19 21 21 21 best : A B B B c D D C C D D C D D D E size = 9 val = 13 cost 0 0 4 5 5 5 10 11 13 14 15 17 18 19 21 23 24 best A B B B c D E C E E C D E E" }, { "page_index": 546, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_110.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_110.png", "page_index": 546, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:36:17+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack problem TP.HCM 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 A size = 3 val = 4 cost 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 best A A A A A A A A A A A A A A A : : B size = 4 val = 5 cost 0 0 4 5 5 9 9 9 9 9 9 9 9 9 9 9 best A B B 8 B B B B 8 c size = Before considering B: cost 0 0 19 19 19 cost[1, 6] = 4,best[1, 6] = A best 1 C c 1 Consider B: D size = cost[2, 6] = cost[1, 6-size[B]] + val[B] cost 0 0 21 21 21 best cost[2, 6] = cost[1, 2] + 5 = 0 + 5 = 5 D D D 1 E size = After considering B: cost 0 0 21 23 24 cost[2, 6] = 5, best[2, 6] = B best D E E -" }, { "page_index": 547, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_111.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_111.png", "page_index": 547, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:36:32+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack problem TP.HCM 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 A size = 3 val = 4 cost 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 best A A A A A A A A A A A A A A A : : B size = 4 val = 5 cost 0 0 4 5 5 5 9 9 9 9 9 9 9 9 9 9 9 best A B B 8 B B B B 8 c size = Before considering B: cost 0 0 19 19 19 cost[1,7] = 4, best[1,7] = A best 1 C c 1 Consider B: D size = 0 0 cost[2, 7] = cost[1, 7-size[B]] + val[B] cost 21 21 21 best cost[2,7] = cost[1, 3] + 5 = 4 + 5 = 9 D D D : E size = After considering B: cost 0 0 21 23 24 cost[2,7] = 9, best[2, 7] = B best D E E -" }, { "page_index": 548, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_112.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_112.png", "page_index": 548, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:36:46+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack problem TP.HCM 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 A size = 3 val = 4 cost 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 best A A A A A A A A A A A A A A A : : B size = 4 val = 5 cost 0 0 4 5 5 5 9 9 9 9 9 9 9 9 9 9 9 best A B B B 8 B B B B 8 c size = Before considering B: cost 0 0 19 19 19 cost[1, 8] = 4, best[1,8] = A best 1 C C c 1 Consider B: D size = 0 0 cost[2, 8] = cost[1, 8-size[B]] + val[B] cost 21 21 21 best cost[2, 8] = cost[1, 4] + 5 = 4 + 5 = 9 D D D : E size = After considering B: cost 0 0 21 23 24 cost[2, 8] = 9, best[2, 8] = B best D E E -" }, { "page_index": 549, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_113.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_113.png", "page_index": 549, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:37:05+07:00" }, "raw_text": "BK 5.1.3. (0-1) Knapsack problem TP.HCM 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 A size = 3 val = 4 cost 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 best A A A A A A A A A A A A A A : A : B size = 4 val = 5 cost 0 0 4 5 5 5 9 9 9 9 9 9 9 9 9 9 9 best : A B B B B B B 8 B B B B : c size = 7 val = 10 cost 0 0 4 5 5 5 10 10 10 14 15 15 15 19 19 19 19 best 1 1 A 8 B B c C C c C C c c c c D size = 8 val = 11 cost 0 0 4 5 5 5 10 11 11 14 15 16 16 19 21 21 21 best : A B B B c D D C C D D C D D D E size = 9 val = 13 cost 0 0 4 5 5 5 10 11 13 14 15 17 18 19 21 23 24 best A B B B c D E C E E C D E E" }, { "page_index": 550, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_114.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_114.png", "page_index": 550, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:37:26+07:00" }, "raw_text": "BK 5.1.3. (0-1) Knapsack problem TP.HCM 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 A size = 3 val = 4 cost 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 best A A A A A A A A A A A A A A : A : B size = 4 val = 5 cost 0 0 4 5 5 5 9 9 9 9 9 9 9 9 9 9 9 best : A B B B B B B 8 B B B B : c size = 7 val = 10 cost 0 0 4 5 5 5 10 10 10 14 15 15 15 19 19 19 19 best 1 1 A 8 B B c C C c C C c c c c D size = 8 val = 11 cost 0 0 4 5 5 5 10 11 11 14 15 16 16 19 21 21 21 best : A B B B c D D C C D D C D D D E size = 9 val = 13 cost 0 0 4 5 5 5 10 11 13 14 15 17 18 19 21 23 24 best A B B B c D E C E E C D E E" }, { "page_index": 551, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_115.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_115.png", "page_index": 551, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:37:29+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack TP.HCM problem N = 5, M = 17, only one item for each type A B C D E vaI[A] = 4 val[B] = 5 val[C] = 10 val[D] = 11 val[E] = 13 The maximum total value of the knapsack = 24 Combination of items = {E, D} 115" }, { "page_index": 552, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_116.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_116.png", "page_index": 552, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:37:34+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack TP.HCM problem Your turn: Trace-by-hand both algorithms for the unbounded and bounded (0-1) knapsack problems as follows. 5.1.3.1. N = 4, M = 10 size[A] = 5,vaI[A] = 9, size[B] = 4, vaI[B] = 8, size[C] = 2 val[C] = 3,size[D] = 3, vaI[D] = 5 5.1.3.2. N = 5, M = 6 size[A] = 3, val[A] = 25, size[B] = 2, vaI[B] = 20, size[C] = 1 val[C] = 15, size[D] = 4, val[D] = 40, size[E] = 5,vaI[E] = 50 5.1.3.3. N = 4, M = 8 size[A] = 2,vaI[A] = 4, size[B] = 3, val[B] = 7, size[C] = 5 val[C] = 9,size[D] = 6, val[D] = 11 5.1.3.4. N = 4, M = 9 size[A] = 2,val[A] = 3,size[B] = 3,vaI[B] = 4, size[C] = 4 vaI[C] = 5, size[D] = 5, val[D] = 7 116" }, { "page_index": 553, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_117.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_117.png", "page_index": 553, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:37:39+07:00" }, "raw_text": "BK 5.1.3.(0-1) Knapsack TP.HCM problem Your turn: 5.1.3.5. Design and analyze the algorithm 0 that outputs the items packed in the knapsack after cost and best are obtained from the dynamic programming algorithm when there is only one e item for each type. 5.1.3.6. Design and analyze the algorithm 0 l that handles the (0-1) knapsack problem d number of items for each type. with a limited 117" }, { "page_index": 554, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_118.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_118.png", "page_index": 554, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:37:44+07:00" }, "raw_text": "5.1.4. Transitive closure with BK Warshall's algorithm TP.HCM For directed graphs, we're often interested in the set of vertices that can be reached from a given vertex by traversing edges from the graph in the indicated direction One operation we might want to perform is \"to add an edge directly from vertex x to vertex y if there is some way to get from x to y\". The graph that is obtained by adding all edges of this nature to a directed graph is called the transitive closure of the graph. Since the transitive closure is likely to be dense, so an adjacency matrix representation is called for. 118" }, { "page_index": 555, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_119.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_119.png", "page_index": 555, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:37:51+07:00" }, "raw_text": "5.1.4. Transitive closure e with BK Warshall's algorithm TP.HCM a b c b a A directed graph a 0 1 0 0 and 0 0 0 1 its adjacency matrix c 0 0 0 0 d C d 1 0 1 0 6 a C b a and a 1 1 1 1 its transitive closure 1 1 1 1 0 0 0 0 c C d 1 d 1 1 1 119" }, { "page_index": 556, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_120.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_120.png", "page_index": 556, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:37:56+07:00" }, "raw_text": "5.1.4. Transitive closure with BK Warshall's algorithm TP.HCM Warshall's algorithm There is a simple algorithm for computing the transitive closure of a graph represented by an adjacency matrix. for y := 1 to V do for x := 1 to V do if a[x, y] then for j := 1 to V do if a[y, j] then a[x, j] := true; //true = 1 S. Warshall invented this method in 1962, using the simple observation: \"If there is a way to get from node x to node y and a way to get from node y to node j, then there is a way to get from node x to node j. 120" }, { "page_index": 557, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_121.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_121.png", "page_index": 557, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:38:01+07:00" }, "raw_text": "5.1.4. Transitive closure with BK Warshall's algorithm TP.HCM Warshall's algorithm repeats V iterations on the adjacency matrix a, constructing a series of V boolean matrices: a(0),.., a(y-1),a(),...,a(v) The central point of the algorithm is that we can compute all elements of each matrix a() from its immediate predecessor a(y-1) in series. After the y-th iteration, a[x, j] is equal to 1 if and only if there exists a directed path of a positive length from vertex x to vertex.j with each intermediate vertex, if any, numbered not higher than y. After the y-th iteration, we compute the elements of matrix a by the following formula: ay[x,j] = ay-1[x,j] or (ay-1[x, y] and ay-1[y, j] Warshall's algorithm applies dynamic programming paradigm recursive algorithm. Instead, it brings out an iterative algorithm with the support of a matrix for storing intermediate results. 121" }, { "page_index": 558, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_122.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_122.png", "page_index": 558, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:38:06+07:00" }, "raw_text": "5.1.4. Transitive closure e with BK Warshall's algorithm TP.HCM Rule for changing zeros in Warshall's algorithm ay-1[x,y] ay-1[y,j] X ay[x,j] = ay-1[x,j] or (ay-1[x,y] and ay-1[y,j] j y 1 y ay-1 1 x 0-1 x 1 1 1 122" }, { "page_index": 559, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_123.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_123.png", "page_index": 559, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:38:11+07:00" }, "raw_text": "5.1.4. Transitive closure e with BK Warshall's algorithm TP.HCM Given a directed graph, what is its transitive closure? 6 a c d a a 0 1 0 A0 = b 0 0 0 1 0 C 0 0 0 d d 1 0 1 0 123" }, { "page_index": 560, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_124.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_124.png", "page_index": 560, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:38:19+07:00" }, "raw_text": "5.1.4. Transitive closure with BK Warshall's algorithm TP.HCM Given a directed graph, what is its transitive closure? a c a b a 0 1 O O A0 = b O 0 0 1 O 0 0 d C d 1 0 1 0 a b C a a 1 0 0 A1 = 6 0 0 1 0 0 0 c C d d 1 1 1 124" }, { "page_index": 561, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_125.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_125.png", "page_index": 561, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:38:26+07:00" }, "raw_text": "5.1.4. Transitive closure e with BK Warshall's algorithm TP.HCM Given a directed graph, what is its transitive closure? a C a b 0 1 0 0 a A1 = b O 0 O 1 0 0 0 d C d 1 1 1 0 a b C a a 0 1 0 1 A2 = b 0 0 1 0 0 0 c d C d 1 1 1 1 125" }, { "page_index": 562, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_126.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_126.png", "page_index": 562, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:38:34+07:00" }, "raw_text": "5.1.4. Transitive closure with BK Warshall's algorithm TP.HCM Given a directed graph, what is its transitive closure? 6 c a a 0 1 O 1 a A2 = b 0 0 1 O O 0 d C d 1 1 1 1 a b C a a 0 1 0 1 A3 = 6 0 0 1 0 0 0 c d C d 1 1 1 1 126" }, { "page_index": 563, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_127.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_127.png", "page_index": 563, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:38:41+07:00" }, "raw_text": "5.1.4. Transitive closure e with BK Warshall's algorithm TP.HCM Given a directed graph, what is its transitive closure? 6 a c a 0 1 0 1 a A3 = 6 0 0 1 0 0 O d C d 1 1 1 1 a b c a b a 1 1 1 1 A4 = 6 1 1 1 1 0 0 0 c d C d 1 1 1 1 127" }, { "page_index": 564, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_128.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_128.png", "page_index": 564, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:38:49+07:00" }, "raw_text": "5.1.4. Transitive closure e with BK Warshall's algorithm TP.HCM Given a directed graph, what is its transitive closure? a c a b a 0 1 0 0 A0 = 6 0 0 1 0 0 0 d C d 1 0 1 lransitive a b C a b closure a 1 1 1 1 A4 = b 1 1 1 1 0 0 0 c d C d 1 1 1 1 128" }, { "page_index": 565, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_129.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_129.png", "page_index": 565, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:38:54+07:00" }, "raw_text": "5.1.4. Transitive closure with BK Warshall's algorithm TP.HCM Time complexity of Warshall's algorithm to find transitive closure of a directed graph Abstract operation : assignment Worst case: O(lVI3) Note : The algorithm runs faster by treating matrix rows as bit strings and employing g bitwise or operation. No need of separate matrices for recording intermediate results. The underlying idea can be applied to the more general problem of finding lengths of the shortest paths in weighted graphs. 129" }, { "page_index": 566, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_130.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_130.png", "page_index": 566, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:39:01+07:00" }, "raw_text": "5.1.4. Transitive closure e with BK Warshall's algorithm TP.HCM Your turn : For each directed c graph, present both graph and adjacency matrix. Then, trace- by-hand Warshall's algorithm to find its transitive closure. a c d 6 c a a b 0 1 0 0 0 0 a a 1 6 0 0 1 0 1 1 1 0 0 1 1 0 0 1 C d 0 0 0 0 0 0 1 0 5.1.4.1. 5.1.4.2. 5.1.4.3. 130" }, { "page_index": 567, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_131.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_131.png", "page_index": 567, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:39:05+07:00" }, "raw_text": "5.1.4. Transitive closure with BK Warshall's algorithm TP.HCM Your turn : 5.1.4.4. Explain how Warshall's algorithm 0 can be used to determine whether a given digraph is a dag (directed acyclic graph). Is it a good algorithm for this problem? 5.1.4.5. Is it a good idea to apply 0 Warshall's algorithm to find the transitive closure of an undirected graph? If yes, give an example to demonstrate it. 131" }, { "page_index": 568, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_132.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_132.png", "page_index": 568, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:39:10+07:00" }, "raw_text": "5.1.5. The all-pairs shortest path BK TP.HCM with Floyd's algorithm problem l I For weighted graphs (directed or not) one might want to build a matrix allowing one to find the shortest path from x to y for all pairs of vertices. This is the all-pairs shortest path problem. It is also possible to use the idea just like Warshall's algorithm, which is attributed to R. W. Floyd. Floyd's algorithm A weighted graph is represented by an adjacency matrix. Dynamic programming is applied for an iterative algorithm. It is applicable to both undirected and directed weighted graphs provided that they do not contain a cycle of a negative length 132" }, { "page_index": 569, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_133.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_133.png", "page_index": 569, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:39:20+07:00" }, "raw_text": "5.1.5. The all-pairs shortest path BK TP.HCM with Floyd's algorithm problem 2 a b c b a A weighted graph a 0 3 8 8 3 7 and 6 2 0 8 its adjacency matrix 1 7 0 1 8 d C d 6 0 and a c a c its distance matrix 0 10 3 4 0 3 0 3 for the weights of 2 0 5 6 0 0 1 3 the shortest paths 0 1 4 0 0 0 c and the matrix for 6 16 9 0 0 3 1 0 intermediate vertices 133" }, { "page_index": 570, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_134.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_134.png", "page_index": 570, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:39:23+07:00" }, "raw_text": "5.1.5. The all-pairs shortest path BK TP.HCM with Floyd's algorithm problem l l Floyd's algorithm for y := 1 to V do for x := 1 to V do if a [x,y]> 0 then for j := 1 to V do if a[y,j]> 0 then if (a[x, y] + a[y, j]< a [x,j]) then begin a[x,j] := a[x, y] + a[y, j]; end; 134" }, { "page_index": 571, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_135.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_135.png", "page_index": 571, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:39:28+07:00" }, "raw_text": "5.1.5. The all-pairs shortest path BK TP.HCM with Floyd's algorithm problem l 1 Floyd's algorithm repeats V iterations on the adjacency matrix a, 0 constructing a series of V matrices: The central point of the algorithm is that we can compute all elements of each matrix a() from its immediate predecessor a(v-1) After the y-th iteration, a[x, j] stores the shortest length of the directed path from the vertex x to vertex.j with each intermediate vertex, if any, numbered not higher than y. After the y-th iteration, we compute the elements of matrix a by the following formula: ay[x,j] = min (ay-1[x,j], ay-1[x, y] + ay-1[y,j]) The superscript y indicates the value of an element in matrix a after the y-th iteration. 135" }, { "page_index": 572, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_136.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_136.png", "page_index": 572, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:39:31+07:00" }, "raw_text": "5.1.5. The all-pairs shortest path BK TP.HCM with Floyd's algorithm problem l l Floyd's algorithm ay-1[x,y] ay-1[y,j] x ay-1[x,j] ay[x,j] = min (ay-1[x,j], ay-1[x, y] + ay-1[y,j]) 136" }, { "page_index": 573, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_137.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_137.png", "page_index": 573, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:39:37+07:00" }, "raw_text": "5.1.5. The all-pairs shortest path BK TP.HCM with Floyd's algorithm problem l 1 for i := 1 to V do o Floyd's for j:= 1 to V do P[i,j] := 0; algorithm for y := 1 to V do for x := 1 to V do Extended with if a [x,y] > 0 then matrix P, where for j := 1 to V do if a [y,j] > 0 then P[x,j] holds the if (a[x,y]+ a[y, j]< a [x,j]) then vertex y that led begin Floyd's algorithm a[x, j] := a[x, y] + a[y, j]; to find the smallest P[x, j] :- y; value of a[x,j] end; 137" }, { "page_index": 574, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_138.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_138.png", "page_index": 574, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:39:41+07:00" }, "raw_text": "5.1.5. The all-pairs shortest path BK TP.HCM with Floyd's algorithm problem l 1 Floyd's algorithm Using matrix P and procedure pathO, we can print the intermediate vertices y on the shortest path from vertex x to vertex j to form the shortest path from x to j. procedure path(x, j: int) var y : int: begin y := P[x,j]; if y = 0 then return; path(x,y); writeln(y); path(y,j): end 138" }, { "page_index": 575, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_139.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_139.png", "page_index": 575, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:39:50+07:00" }, "raw_text": "5.1.5. The all-pairs shortest path BK TP.HCM with Floyd's algorithm problem A0 2 a b c b a A weighted graph a 0 3 8 8 3 and 7 6 2 0 8 8 its adjacency matrix 1 7 0 1 8 d C 6 0 8 A4 P4 How to find a c a c its distance matrix 0 10 3 4 0 3 0 3 for the weights of 2 0 5 6 0 0 1 3 the shortest paths 7 0 1 4 0 0 0 c and the matrix for 0 6 16 9 0 0 3 1 0 Intermediate vertices? 139" }, { "page_index": 576, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_140.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_140.png", "page_index": 576, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:40:00+07:00" }, "raw_text": "5.1.5. The all-pairs shortest path BK TP.HCM with Floyd's algorithm problem A0 po 6 6 O 3 0 0 0 a 0 8 8 6 2 0 0 0 0 0 0 1 0 0 0 0 8 6 0 0 0 0 A1 p1 6 From A0 to A1: a c a c From po to p1: 0 3 0 0 0 0 2 0 5 0 0 0 1 0 8 0 1 0 0 0 0 6 9 0 0 0 1 0 8 140" }, { "page_index": 577, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_141.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_141.png", "page_index": 577, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:40:10+07:00" }, "raw_text": "5.1.5. The all-pairs shortest path BK TP.HCM with Floyd's algorithm problem A1 p1 6 6 a c 0 3 0 0 0 a 0 8 8 2 O S 0 0 1 0 8 0 1 0 0 0 0 6 9 0 0 0 1 0 A2 p2 From A1 to A2: 6 a c a c From p1 to p2: 0 3 0 0 0 0 2 0 5 0 0 0 1 0 8 9 7 0 1 2 0 0 0 6 9 0 0 0 1 0 8 141" }, { "page_index": 578, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_142.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_142.png", "page_index": 578, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:40:21+07:00" }, "raw_text": "5.1.5. The all-pairs shortest path BK TP.HCM with Floyd's algorithm problem A2 p2 6 6 a a a 0 3 0 0 0 a 0 8 8 2 0 0 0 1 0 9 7 1 2 0 0 0 6 9 0 0 0 1 0 8 A3 P3 From A2 to A3: a c a c From p2 to p3: 0 10 3 4 0 3 0 3 2 0 5 6 6 0 0 1 3 9 0 1 2 0 0 0 6 16 9 0 0 3 1 0 142" }, { "page_index": 579, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_143.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_143.png", "page_index": 579, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:40:32+07:00" }, "raw_text": "5.1.5. The all-pairs shortest path BK TP.HCM with Floyd's algorithm problem A3 P3 6 6 a c 10 3 + 0 3 0 3 a 2 0 5 6 6 0 0 1 3 9 0 1 2 0 0 0 6 16 9 O 0 3 1 0 A4 P4 From A3 to A4: 6 6 a c a c From P3 to P4: 0 10 3 4 0 3 0 3 2 0 5 6 6 0 0 1 3 1 4 0 0 0 6 16 9 0 0 3 1 0 143" }, { "page_index": 580, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_144.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_144.png", "page_index": 580, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:40:42+07:00" }, "raw_text": "5.1.5. The all-pairs shortest path BK TP.HCM with Floyd's algorithm problem Ao 2 a b c b a A weighted graph a 0 3 8 8 and 3 7 6 2 0 8 its adjacency matrix 1 7 0 1 8 d C 6 0 A4 P4 and a c a c its distance matrix 0 10 3 4 0 3 0 3 for the weights of 2 0 5 6 0 0 1 3 the shortest paths 7 0 1 4 0 0 0 c and the matrix for 6 16 9 0 0 3 1 0 intermediate vertices 144" }, { "page_index": 581, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_145.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_145.png", "page_index": 581, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:40:51+07:00" }, "raw_text": "5.1.5. The all-pairs shortest path BK TP.HCM problem with Floyd's algorithm Ao 2 a 6 c b a A weighted graph 0 3 a 8 and 3 7 6 6 2 0 8 its adjacency matrix 1 1 C d 6 0 8 8 A4 P4 What is the shortest 6 a c a c path from c to a? 10 3 3 0 3 > path(c,a) 6 2 0 5 6 6 0 0 1 3 > path(c,d), d, 7 0 1 4 0 0 0 c c path(d,a) 6 16 9 0 0 3 1 0 c, d, a 145" }, { "page_index": 582, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_146.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_146.png", "page_index": 582, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:40:55+07:00" }, "raw_text": "5.1.5. The all-pairs shortest path BK TP.HCM with Floyd's algorithm problem 1 Time complexity of Floyd's algorithm for the all-pairs shortest path problem on a weighted c graph of V vertices and E edges Asbtract operation: assignment Worst case: O(lVl3) 146" }, { "page_index": 583, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_147.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_147.png", "page_index": 583, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:41:04+07:00" }, "raw_text": "5.1.5. The all-pairs shortest path BK TP.HCM with Floyd's algorithm problem Your turn : Given the following graphs, present both graph and adjacency matrix for each graph and then trace-by-hand Floyd's algorithm to solve the all-pairs shortest path problem. 2 0 d a C a c a b 6 5 1 2 a 8 8 a 1 3 2 8 6 7 0 2 2 0 2 8 4 c d 3 1 9 0 8 + 2 3 d 4 1 0 8 2 3 8 3 e 5.1.5.1. 5.1.4.2. 5.1.4.3. 147" }, { "page_index": 584, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_148.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_148.png", "page_index": 584, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:41:12+07:00" }, "raw_text": "5.1.5. The all-pairs shortest path BK TP.HCM with Floyd's algorithm problem l l 2 Your turn : a 5.1.5.4. Given a weighted graph: 6 3 3 What is its adjacency matrix? 4 What are its distance matrix and 0 1 + 2 intermediate vertex matrix after the 3 all-pairs shortest path problem is 2 8 solved? d e What are the shortest paths from a to 2 d and from c to f? b c d a 5.1.5.5. Given an adjacency 0 2 a 4 6 matrix : b 2 0 1 2 What is its corresponding graph? What are the shortest paths from a to c 5 0 1 d and from d to b? d 9 2 0 00 148" }, { "page_index": 585, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_149.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_149.png", "page_index": 585, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:41:17+07:00" }, "raw_text": "BK 5.2. Greedy algorithms TP.HCM Algorithms for optimization problems typically go through a sequence of steps, with a set of choices at each step. A greedy algorithm always makes the choice that looks the best at the moment. That is, it makes a locally optimal choice in the hope that this choice will lead to a globally optimal solution. Some examples of greedy algorithms for solving 0 An activity-selection problem The fractional knapsack problem Huffman code problem Finding minimum-spanning trees Graph coloring 149" }, { "page_index": 586, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_150.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_150.png", "page_index": 586, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:41:22+07:00" }, "raw_text": "BK 5.2. Greedy algorithms TP.HCM There are two ingredients that are exhibited by most problems that lend themselves to a greedy strategy: (1) the greedy choice property and (2) optimal substructure. Greedy choice property 1 The choice made by a greedy algorithm may depend on choices so.far, but it cannot depend on any.future choices or on the solutions of the subproblems. Thus, unlike dynamic programming, a greedy algorithm usually progresses in a top- down fashion, making one greedy choice after another. iteratively reducing each given problem instance to a smaller. Optimal substructure o The optimal solution for the problem contains within it optimal solutions to subprobems 150" }, { "page_index": 587, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_151.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_151.png", "page_index": 587, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:41:27+07:00" }, "raw_text": "BK 5.2. Greedy algorithms TP.HCM Your turn : 5.2.1. Compare the following strategies: 0 Divide-and-conquer Decrease-and-conquer Dynamic programming Greedy 5.2.2. Link each algorithm to its 0 corresponding design strategy : a. Algorithm for 0-1 knapsack problem 1. Divide-and-conguer b. Algorithm for external sorting ii. Decrease-and-conguer c. Algorithm for constructing Huffman code iii. Dynamic programming d. Algorithm for finding topological sorting iv. Greedy 151" }, { "page_index": 588, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_152.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_152.png", "page_index": 588, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:41:31+07:00" }, "raw_text": "5.2.1. Activity-selection BK TP.HCM problem Suppose we have a set S = {1, 2, ..., n} of n activities that wish to use a resource, such as a lecture hall. which can be used by only one activity at a time. Each activity i has a starting time s; and a finishing time fi, such that s; -fi. If selected, activity i takes place during the half-open time interval [s, f). Activities i not overlap: The activity-selection problem is to select a maximum- 0 size set of mutually compatible activities. 152" }, { "page_index": 589, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_153.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_153.png", "page_index": 589, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:41:36+07:00" }, "raw_text": "5.2.1. Activity-selection BK TP.HCM problem In the greedy algorithm for activity-selection problem, we assume that the input activities are in ascending order of.finishing times: ff...fn /* s is the array keeping the starting times of the set of n activities and f is the array keeping the finishing times of the set of n activities */ begin n := lengths]: A:=1 j:=1: for i := 2 to n do if s: >= f then /* i is compatible with all activities in A */ begin A:=AU{i}; J :=i end end 153" }, { "page_index": 590, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_154.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_154.png", "page_index": 590, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:41:40+07:00" }, "raw_text": "5.2.1. Activity-selection BK TP.HCM problem The activity picked next by GREEDY-ACTIVITY- SELECTOR is always the one with the earliest finishing time that can be legally scheduled. The activity picked is opportunities as possible for the remaining activities to be scheduled. Greedy algorithms do not always produce optimal solutions. However, GREEDY-ACTIVITY-SELECTOR always finds an optimal solution to an instance of the activity-selection problem 154" }, { "page_index": 591, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_155.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_155.png", "page_index": 591, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:41:46+07:00" }, "raw_text": "5.2.1. Activity-selection BK TP.HCM problem Si fi Given a sorted list of 1 1 4 activities, what activities 2 3 5 are selected? 3 0 6 4 5 7 5 3 8 6 5 9 7 6 10 8 8 11 9 8 12 10 2 13 11 12 14 155" }, { "page_index": 592, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_156.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_156.png", "page_index": 592, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:41:52+07:00" }, "raw_text": "5.2.1. Activity-selection BK TP.HCM problem Given a sorted list of activities, what activities are selected? sifi 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 1 4 2 3 5 3 6 4 5 7 5 3 8 6 5 9 6 10 8 8 11 9 8 12 10 2 13 11 12 14 156" }, { "page_index": 593, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_157.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_157.png", "page_index": 593, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:41:59+07:00" }, "raw_text": "5.2.1. Activity-selection BK TP.HCM problem Given a sorted list of activities, what activities are selected? sifi 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 1 4 2 3 5 3 6 4 5 7 5 3 8 6 5 9 6 10 8 8 11 9 8 12 10 2 13 11 12 14 A = {1} 157" }, { "page_index": 594, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_158.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_158.png", "page_index": 594, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:42:06+07:00" }, "raw_text": "5.2.1. Activity-selection BK TP.HCM problem Given a sorted list of activities, what activities are selected? sifi 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 - 1 1 4 2 3 5 3 6 4 5 7 5 3 8 6 5 9 6 10 8 8 11 9 8 12 10 2 13 11 12 14 A={1} 158" }, { "page_index": 595, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_159.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_159.png", "page_index": 595, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:42:14+07:00" }, "raw_text": "5.2.1. Activity-selection BK TP.HCM problem Given a sorted list of activities, what activities are selected? sifi 0 1 2 3 4 5 6 7 8 9 10 11 12 13 314 - 1 1 4 2 3 5 3 6 4 5 7 5 3 8 6 5 9 6 10 8 8 11 9 8 12 10 2 13 11 12 14 A = {1,4} 159" }, { "page_index": 596, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_160.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_160.png", "page_index": 596, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:42:22+07:00" }, "raw_text": "5.2.1. Activity-selection BK TP.HCM problem Given a sorted list of activities, what activities are selected? sifi 0 1 2 3 4 5 6 7 8 9 10 11 12 13 314 1 1 4 2 3 5 3 6 4 5 7 5 3 8 6 5 9 6 10 8 8 11 9 8 12 10 2 13 11 12 14 A = {1,4} 160" }, { "page_index": 597, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_161.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_161.png", "page_index": 597, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:42:30+07:00" }, "raw_text": "5.2.1. Activity-selection BK TP.HCM problem Given a sorted list of activities, what activities are selected? sifi 0 1 2 3 4 5 6 7 8 9 10 11 12 13 314 - 1 1 4 2 3 5 3 0 6 4 5 5 3 8 6 5 9 6 10 8 8 11 9 8 12 10 2 13 11 12 14 A = {1,4, 8} 161" }, { "page_index": 598, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_162.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_162.png", "page_index": 598, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:42:42+07:00" }, "raw_text": "5.2.1. Activity-selection BK TP.HCM problem Given a sorted list of activities, what activities are selected? sifi 0 1 2 3 4 5 6 7 8 9 10 11 12 13 314 1 1 4 2 3 5 3 0 6 4 5 5 3 8 6 5 9 6 10 8 8 11 9 8 12 10 2 13 11 12 14 A = {1, 4, 8} 162" }, { "page_index": 599, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_163.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_163.png", "page_index": 599, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:42:54+07:00" }, "raw_text": "5.2.1. Activity-selection BK TP.HCM problem Given a sorted list of activities, what activities are selected? sifi 0 1 2 3 4 5 6 7 8 9 10 11 12 13 314 1 1 4 2 3 5 3 0 6 4 5 5 3 8 6 5 9 6 10 8 8 11 9 8 12 10 2 13 11 12 14 A = {1,4,8,11} 163" }, { "page_index": 600, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_164.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_164.png", "page_index": 600, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:42:58+07:00" }, "raw_text": "5.2.1. Activity-selection BK TP.HCM problem Time complexity of the greedy algorithm for the activity-selection problem (not counting the cost of sorting finishing times) Abstract operation: comparison Best, Average, Worst cases: O(n) Time complexity of the greedy algorithm for the activity-selection problem (counting the cost of sorting finishing times) Abstract operation : comparison Best, Average, Worst cases: O(nlog,n) 164" }, { "page_index": 601, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_165.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_165.png", "page_index": 601, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:43:06+07:00" }, "raw_text": "5.2.1. Activity-selection BK TP.HCM problem Your turn : Given the following g lists of activities, from each list, what activities are selected for scheduling? i 1 2 3 4 5 6 7 8 9 10 11 12 5.2.1.1. List 1 1 3 4 2 6 4 10 12 Si 11 f: 3 4 6 8 9 13 14 15 16 5.2.1.2. List 2 2 5 3 4 1 3 5 2 8 6 10 Si fi 5 7 8 11 9 6 10 8 11 12 13 15 165" }, { "page_index": 602, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_166.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_166.png", "page_index": 602, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:43:11+07:00" }, "raw_text": "5.2.2. Fractional knapsack BK TP.HCM problem In the previous section with dynamic programming, the 0-1 knapsack problem is posed as follows. \"A thief robbing a store finds it filled with N types of items of varying size and value (each item of the i-th item type is worth v; dollars and weights w; pounds), but has only a small knapsack of capacity M to use to carry the goods. The knapsack problem is to find the combination of items which the thief should choose for his knapsack in order to maximize the total value of all the items he takes.' This is called the 0-1 knapsack problem because each item must be either taken or left behind; the thief can not take a fractional part of an item 166" }, { "page_index": 603, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_167.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_167.png", "page_index": 603, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:43:17+07:00" }, "raw_text": "5.2.2. Fractional knapsack BK TP.HCM problem In the fractional knapsack problem, the setup is the same, but the thief can take.fractions of items, rather than having to make a binary (0-1) choice of each item. Both knapsack problems exhibit the optimal substructure property For the 0-1 problem, consider the most valuable load with the weights at most M pounds. If we remove item from this load, the remaining load is the most valuable load weighing at most M - w; that the thief can take from the n-1 original items excluding j. For the fractional problem, consider that if we remove a weight w;-w of one item .j from the optimal load, the remaining load is the most valuable load weighting at most M - (w;-w) that the thief can take from the n-1original items, excluding item.j. We use greedy algorithm for the fractional knapsack and dynamic programming for the 1-0 knapsack 167" }, { "page_index": 604, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_168.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_168.png", "page_index": 604, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:43:21+07:00" }, "raw_text": "5.2.2. Fractional knapsack BK TP.HCM problem To solve the fractional problem with the greedy strategy, we first compute the value per pound (vj/w:) for each item The thief begins by taking as much as possible of the item with the greatest value per pound (v;/wi). If the more, he takes as much as possible of the item with the next greatest value per pound, and so forth until he cannot carry any more 168" }, { "page_index": 605, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_169.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_169.png", "page_index": 605, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:43:25+07:00" }, "raw_text": "5.2.2. Fractional knapsack BK TP.HCM problem procedure GREEDY_KNAPSACK(V,W,M,X,n); var rc: real; i: integer; begin for i:= 1 to n do X[i]:= 0: rc := M : // rc = remaining knapsack capacity for i := 1 to n do begin if W[i]>rc then exit; X[i] :=1; rc :=rc -W[i] end; if i < n then X[i] := rc/W[i] end V and W are the arrays that contain the values and weights of n objects ordered in such a way that V/W; Vi+1/W i+1 M is the knapsack capacity and X is a solution vector. 169" }, { "page_index": 606, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_170.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_170.png", "page_index": 606, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:43:30+07:00" }, "raw_text": "5.2.2. Fractional knapsack BK TP.HCM problem With the knapsack M = 50 and the following items: W[1] = 10, V[1] = 60, W[2] = 20, V[2] = 100, W[3] = 30, V[3] = 120, W[4] = 40, V[4] = 120 What is the combination of items that makes the total value of the knapsack the highest? Item 1 Item 2 Item 3 Item 4 Knapsack 60 100 120 120 Max? 170" }, { "page_index": 607, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_171.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_171.png", "page_index": 607, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:43:35+07:00" }, "raw_text": "5.2.2. Fractional knapsack BK TP.HCM problem With the knapsack M = 50 and the following items: W[1] = 10,V[1] = 60, W[2] = 20, V[2] = 100, W[3] = 30 V[3] = 120, W[4] = 40, V[4] = 120 What is the combination of items that makes the total value of the knapsack the highest? V[1] V[2] V[3] V[4] 6, 5 4 = 3 W[1] W[2] W[3] W[4] Pick item 1,remaining capacity = M - W[1] = 40 - Pick item 2,remaining capacity = 40 - W[2] = 20 > Pick * item 3,remaining capacity = 20 - W3l = 0 * 3 >X=K1,1,2/3,0} 171" }, { "page_index": 608, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_172.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_172.png", "page_index": 608, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:43:40+07:00" }, "raw_text": "5.2.2. Fractional knapsack BK TP.HCM problem With the knapsack M = 50 and the following items: W[1] = 10, V[1] = 60, W[2] = 20, V[2] = 100, W[3] = 30, V[3] = 120, W[4] = 40, V[4] = 120 What is the combination of items that makes the total value of the knapsack the highest? Item 1 Item 2 Item 3 Item 4 Knapsack 60 100 120 120 Max=240 X =K1,1,2/3,0} 172" }, { "page_index": 609, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_173.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_173.png", "page_index": 609, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:43:44+07:00" }, "raw_text": "5.2.2. Fractional knapsack BK TP.HCM problem Time complexity of the greedy algorithm for solving the fractional knapsack problem (not counting the cost of sorting n objects) Abstract operation: comparison Best, Average, Worst cases: O(n) Time complexity of the greedy algorithm for solving the fractional knapsack problem (counting the cost of sorting n objects) Abstract operation: comparison Best, Average, Worst cases: O(nlog,n) 173" }, { "page_index": 610, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_174.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_174.png", "page_index": 610, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:43:48+07:00" }, "raw_text": "5.2.2. Fractional knapsack BK TP.HCM problem Your turn: Given the knapsack and the following items, what is the combination of items that makes the total value of the knapsack the highest? 5.2.2.1.M = 20, W[A] = 18,V[A] = 25, W[B] = 15, V[B] = 24,W[C] = 10,V[C] = 15 5.2.2.2.M = 10, W[A] = 5, V[A] = 9, W[B] = 4, V[B] = 8 W[C] = 2,V[C] = 3,W[D] = 3,V[D] = 5 5.2.2.3. Design and analyze a greedy algorithm for 1. the fractional knapsack problem where each item type has the limited number of items greater than or equal to 1. 174" }, { "page_index": 611, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_175.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_175.png", "page_index": 611, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:43:53+07:00" }, "raw_text": "BK 5.2.3. Huffman codes TP.HCM We consider the problem of designing a binary character code wherein each character is represented by a unique binary string. Huffman codes are widely used for file compression. Huffman algorithm uses a table of the frequencies of occurrences of each character as a binary string 175" }, { "page_index": 612, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_176.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_176.png", "page_index": 612, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:43:59+07:00" }, "raw_text": "BK 5.2.3. Huffman codes TP.HCM b d f a c e Frequency 45 13 12 16 5 Fixed length codeword 000 001 010 011 100 101 Variable length codeword 0 101 100 111 1101 1100 Suppose a 100,000-character data file needs to be stored compactly If a.fixed length code (3 bit) is used to represent 6 characters, 0 300,000 bits are needed to code the entire file of 100,000 characters. A variable-length code can do better than a fixed length code, by giving frequent characters short code-words and infrequent characters long code-words. This variable-length code requires: (45. 1 + 13 .3 + 12.3 + 16.3 + 9.4 + 5.4).100,000/100 = 224,000 bits to represent the file, saving approximately 25 %. 176" }, { "page_index": 613, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_177.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_177.png", "page_index": 613, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:44:04+07:00" }, "raw_text": "BK 5.2.3. Huffman codes TP.HCM Prefix-free code We consider here only codes in which no codeword is also a prefix of some other codeword. Such codes are called prefix- free-code or prefix-code. It is possible to show that the optimal data compression achieved by a character code can always be achieved with a prefix code. Prefix codes are desirable because they simplify encoding and decoding Encoding is simple: we just concatenate the code-words representing each character of the file. Decoding is simple with a prefix code. Since no codeword is a prefix of any other, the code word that begins an encoded file is unambiguous 177" }, { "page_index": 614, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_178.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_178.png", "page_index": 614, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:44:08+07:00" }, "raw_text": "BK 5.2.3. Huffman codes TP.HCM An optimal code for a file is always represented by a full binary tree in which every non-leaf node has two children We interpret the binary codeword for a charater as the path from the root to that character, where 0 means \"g0 to the left child\" and 1 means go to the right child\". If C is the alphabet from which the characters are drawn, then the tree for an optimal prefix code has exactly [C leaves, one for each letter of the alphabet. and exactly C-1 internal nodes. 178" }, { "page_index": 615, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_179.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_179.png", "page_index": 615, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:44:13+07:00" }, "raw_text": "BK 5.2.3. Huffman c codes TP.HCM 100 0 1 100 0 1 86 14 a:45 55 0 1 0 0 1 30 58 28 14 25 0 1 0 1 0 1 0 1 0 1 a:45 b:13 c:12 d:16 e:9 f:5 c:12 b:13 d:16 14 0 1 f:5 e:9 (a). Fixed-length codes (b): Variable-length codes 179" }, { "page_index": 616, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_180.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_180.png", "page_index": 616, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:44:17+07:00" }, "raw_text": "BK 5.2.3. Huffman codes TP.HCM Given a tree T corresponding to a prefix code, it is a simple matter to compute the number of bits required to encode a file. For each character c in the alphabet C, let.f(c) denote the frequency of c in the file and d(c) is the length of the codeword for character c. The number of bits required to encode a file is Z.f(c)dr(c) B(T)= cEC which we define as the cost of the tree T 180" }, { "page_index": 617, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_181.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_181.png", "page_index": 617, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:44:22+07:00" }, "raw_text": "BK 5.2.3. Huffman codes TP.HCM Construct Huffman codes with the greedy strategy Huffman invented a greedy agorithm that constructs an optimal prefix code called a Huffman code. The algorithm builds the tree T corresponding to the optimal code in a bottom-up manner. It begins with a set of [C leaves and performs a sequence of C-1 \"merging\" operations to create the final tree A priority queue Q, keyed on f, is used to identify the two least frequency objects to merge together. The result of merging the two objects is a new object whose frequency is the sum of the frequencies of the two objects that have been merged. 181" }, { "page_index": 618, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_182.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_182.png", "page_index": 618, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:44:26+07:00" }, "raw_text": "BK 5.2.3. Huffman codes TP.HCM o The Huffman greedy algorithm procedure HUFFMAN(C) ; begin n := ICl ; Q := C ; // construct a min-heap for i := 1 to n -1 do begin z := ALLOCATE-NODE(Q); left[z] := EXTRACT-MIN(Q): right[z] := EXTRACT-MIN(Q); f[z] := f[left[z]] + f[right[z]]; INSERT(Q,z): end end 182" }, { "page_index": 619, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_183.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_183.png", "page_index": 619, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:44:31+07:00" }, "raw_text": "BK 5.2.3. Huffman codes TP.HCM Given the following characters and their frequencies in textual files. Construct a Huffman code for these characters. What is the average code length? Compared to a fixed-length code, how much does this Huffman code save when compressing a file of 200,000 characters? Character a b c d e Frequency 45 13 12 16 9 5 183" }, { "page_index": 620, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_184.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_184.png", "page_index": 620, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:44:40+07:00" }, "raw_text": "BK 5.2.3. Huffman c codes TP.HCM (i) f:5 e:9 c:12 b:13 d:16 a:45 (ii) c:12 b:13 d:16 a:45 14 0/ 1 f:5 e:9 (iii) d :16 14 25 a:45 (iv) 25 30 a:45 0/ 0/ 0 1 1 1 0 1 f:5 e:9 c:12 b:13 c:12 b:13 d:16 14 0/ 1 f:5 e:9 (v) a:45 (vi) 100 55 0 1 0 1 30 25 a:45 55 0 1 0 0 1 30. b:13 d:16 25 c:12 14 0 1 0 0 1 c:12 b:13 d:16 14 f:5 e:9 0/ 1 f:5 e:9 184" }, { "page_index": 621, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_185.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_185.png", "page_index": 621, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:44:45+07:00" }, "raw_text": "BK 5.2.3. Huffman codes TP.HCM Given the following characters and their frequencies in textual files. Character a 6 d f e Frequency 45 13 12 16 9 5 Huffman code: Averaged code /ength = (1*45 + 3*13 + 3*12 + a = 0 3*16 + 4*9 + 4*5)/100 = 2.24 bits/character b = 101 Fixed-length code: c = 100 code length = Tlog,61 = 3 bits/character d = 111 Requires: 200,000*3 = 600,000 bits e = 1101 Huffman code : f = 1100 Requires: 200,000*2.24 = 448,000 bits Saved: (3-2.24)/3 = 25.33% 185" }, { "page_index": 622, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_186.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_186.png", "page_index": 622, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:44:50+07:00" }, "raw_text": "BK 5.2.3. Huffman codes TP.HCM Time complexity of the Huffman greedy algorithm to construct Huffman codes on a set of n characters Abstract operation: comparison Best, Average, Worst cases: O(nlog,n) Given a set C of n characters, building Q as a min-heap can be done with time O(n) The for loop is executed exactly n-1 times, and since each heap operation requires O(log,n), this loop contributes O(n/og,n) to the running time. 186" }, { "page_index": 623, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_187.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_187.png", "page_index": 623, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:44:55+07:00" }, "raw_text": "BK 5.2.3. Huffman codes TP.HCM Your turn : 5.2.3.1. Given the following characters and 0 their frequencies in textual files. Construct a Huffman code for these characters What is the average code length? Compared to a fixed-length code, how much does this Huffman code save when compressing a file of 300,000 characters? Character b C e + a g Frequency 23 18 12 15 20 5 7 187" }, { "page_index": 624, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_188.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_188.png", "page_index": 624, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:45:00+07:00" }, "raw_text": "BK 5.2.3. Huffman codes TP.HCM Your turn : 5.2.3.2. Given the following characters and 0 1 their frequencies in textual files. Construct a Huffman code for these characters Encode the text ABACAB_D using the Huffman code achieved above Decode the text whose encoding is 10011110111001010 in the Huffman code achieved above Character A B C D Frequency 40 10 20 15 15 188" }, { "page_index": 625, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_189.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_189.png", "page_index": 625, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:45:05+07:00" }, "raw_text": "BK 5.2.3. Huffman codes TP.HCM Your turn : 5.2.3.3. Given the following characters and 0 their frequencies in textual files. Construct a Huffman code for these characters What is the average code length? Compared to a fixed-length code, how much does this Huffman code save when compressing a file of 500,000 characters? Character A B C D E Frequency 20 7 10 4 18 189" }, { "page_index": 626, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_190.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_190.png", "page_index": 626, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:45:10+07:00" }, "raw_text": "BK 5.2.4. Graph coloring TP.HCM Given an undirected graph, co/oring the graph is 0 an assignment of a color to each vertex of the graph so that no two vertices connected by an edge can have the same color. We wish to find a coloring with the minimum number of colors. This is an optimization problem. One reasonable strategy for graph coloring is using a greedy algorithm. The idea: Initially, we try to color as many vertices as possible with the first color, then as many uncolored vertices as possible with the second color and so on. Note: Greedy algorithm cannot yield the optimal 0 solution for this problem. 190" }, { "page_index": 627, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_191.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_191.png", "page_index": 627, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:45:14+07:00" }, "raw_text": "BK 5.2.4. Graph coloring TP.HCM To color vertices with a new color, we do: Select some uncolored vertex and color it with a new color. Scan the list of uncolored vertices. For each uncolored vertex, determine whether it has an edge to any vertex already colored with the new color. If there is no such an edge, color the present vertex with the new color. In the following figure, we color vertex 1 with pink color and then color vertices 3 and 4 with the same pink color. 3 5 191" }, { "page_index": 628, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_192.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_192.png", "page_index": 628, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:45:18+07:00" }, "raw_text": "BK 5.2.4. Graph coloring TP.HCM Procedure SAME COLOR determines a set of vertices (called newc/r), all of which can be colored with a new color. This procedure is called repeatedly until all vertices are colored. procedure SAME_COLOR(G, newclr); /* SAME COLOR assigns to newc/r a set of vertices of G that may be given the same color */ begin newclr := O: for each uncolored vertex v of G do if v is not adjacent to any vertex in newclr then mark v colored and add v to newc/r. end; 192" }, { "page_index": 629, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_193.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_193.png", "page_index": 629, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:45:22+07:00" }, "raw_text": "BK 5.2.4. Graph coloring TP.HCM procedure G_COLORING(G); procedure SAME_COLOR(G, newclr); /* SAME COLOR assigns to newclr a set of vertices of G that may be given the same color ; a: adjacency matrix for graph G */ begin newclr := O: for each uncolored vertex v of G do begin found := false; for each vertex w e newclr do if a[v,w] = 1 /* there is an edge between v and w in G */ then found := true, if not found then mark y colored and add y to newc/r end end; 193" }, { "page_index": 630, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_194.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_194.png", "page_index": 630, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:45:28+07:00" }, "raw_text": "BK 5.2.4. Graph coloring TP.HCM for each vertex in G do mark uncolored; while there is any vertex marked uncolored do begin SAME_COLOR(G, newc/r); print newc/r end; Theorem: If x(G) is the minimum number of colors to color graph G and G is the largest degree in G then x(G) G +1. Complexity of the greedy algorithm for graph coloring Assume that the graph is represented by an adjacency matrix. In procedure SAME_COLOR, each cell in the adjacency matrix is examined when we color the uncolored vertices with a new color Complexity of procedure SAME_COLOR: O(n2) where n is the number of vertices in G. If m is the number of colors used to color the graph then 0 procedure SAME_COLOR is called m times at all. Therefore, the complexity of the whole algorithm is m*O(n2). Since m is often a small number, we can say: the algorithm has a quadratic complexity 194" }, { "page_index": 631, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_195.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_195.png", "page_index": 631, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:45:32+07:00" }, "raw_text": "BK 5.2.4. Graph coloring TP.HCM Applications Exam timetabling Each exam is represented by a vertex in the graph. Exam timetabling is assigning time periods to exams. Time periods are the colors used to color the vertices of the graph. An edge connects two vertices if there exists at least one student who takes both the exams, therefore we are not allowed to assign those two exams which are represented by the two vertices to the same time period. Frequency assignment problem in wireless broadcasting or mobile telephone 195" }, { "page_index": 632, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_196.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_196.png", "page_index": 632, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:45:37+07:00" }, "raw_text": "BK 5.2.4. Graph coloring TP.HCM Heuristics for graph coloring \"The vertex with the largest degree will be examined to color first\" (Welsh and Powell) Degree of a vertex: the number of edges 0 connected to this vertex. Reason: The vertices with more connected edges 0 will be more difficult to be colored if we wait until all their adjacent vertices are colored. Algorithm 0 1. Arrange the vertices in descending order of degrees. 2. Color a vertex with the maximum degree with color 1. 3. Choose an uncolored vertex with the maximum degree If there is another vertex with the same maximum degree, choose either of them. 4. Color the chosen vertex with the least possible (lowest numbered) color. 5. If all vertices are colored, stop. Otherwise, return to 3. 196" }, { "page_index": 633, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_197.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_197.png", "page_index": 633, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:45:41+07:00" }, "raw_text": "BK 5.2.4. Graph coloring TP.HCM Given a graph as follows. Conduct graph coloring with Welsh and Powell's heuristic. How many colors have been used? B A E H 1 G F C D K 197" }, { "page_index": 634, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_198.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_198.png", "page_index": 634, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:45:47+07:00" }, "raw_text": "BK 5.2.4. Graph coloring TP.HCM Given a graph as follows. Conduct graph coloring with Welsh and Powell's heuristic. How many colors have been used? sort coloring B E: 5 Color E, D, I with B: 4 A D: 4 blue E A: 3 H 1 Color B, C, F, H, K C: 3 F: 3 with green G F C J: 3 G: 2 Color A, J, G with H: 1 D pink I: 1 K K: 1 198" }, { "page_index": 635, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_199.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_199.png", "page_index": 635, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:45:50+07:00" }, "raw_text": "BK 5.2.4. Graph coloring TP.HCM Given a graph as follows. Conduct graph coloring with Welsh and Powell's heuristic. How many colors have been used? 3 B A E H 1 G F C K 199" }, { "page_index": 636, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_200.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_200.png", "page_index": 636, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:45:55+07:00" }, "raw_text": "BK 5.2.4 Graph coloring TP.HCM Your turn : 5.2.4.1. Given a graph as follows. Color this graph using a color set of {green, red, yellow} in such a way that no two vertices connected by an edge can have the same color. If using Welsh and Powell's heuristic, do you obtain the same result? B B E E C 0 H 1 G A H D A G F F 5.2.4.1 (a) 5.2.4.1 (b) 200" }, { "page_index": 637, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_201.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_201.png", "page_index": 637, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:46:00+07:00" }, "raw_text": "BK 5.2.4 Graph coloring TP.HCM 5.2.4.2. Given a graph as follows. Color this graph in such a way that no two vertices connected by an edge can have the same color. If using Welsh and Powell's heuristic, do you obtain the same result? B A E 1 H F G C D 201" }, { "page_index": 638, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_202.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_202.png", "page_index": 638, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:46:04+07:00" }, "raw_text": "BK 5.2.4 Graph coloring TP.HCM Your turn : 5.2.4.3. Given a map as 4 5 follows. Color this map in 2 such a way that no two 1 adjacent regions can have the same color. If 3 using Welsh and Powell's heuristic, do you obtain the same result? 202" }, { "page_index": 639, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_203.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_203.png", "page_index": 639, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:46:08+07:00" }, "raw_text": "BK 5.2.4 Graph coloring TP.HCM Your turn: 5.2.4.4. Given a graph as follows. Color the edges of this graph in such a way that no two edges sharing the same vertex can have the same color. Is the number of colors you have used the minimum one? why? B A E H F G D C 203" }, { "page_index": 640, "chapter_num": 5, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_204.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_5/slide_204.png", "page_index": 640, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:46:13+07:00" }, "raw_text": "Algorithms Analysis and Design BK TP.HCM (C03031) ton 5.1. Dynamic Programming S questi answer question 5.1.1. Matrix-chain multiplication tion question question que s 5.1.2. Longest common subsequence 5.1.3. (0-1) Knapsack problem 5.1.4. Transitive closure with Warshall's algorithm 5.1.5. The all-pairs shortest path problem with Floyd's algorithm 5.2. Greedy Algorithms 5.2.1. Activity-selection problem 5.2.2. Fractional knapsack problem 5.2.3. Huffman codes 5.2.4. Graph coloring 204" }, { "page_index": 641, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_001.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_001.png", "page_index": 641, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:46:16+07:00" }, "raw_text": "Ho Chi Minh City University of Technology BK Faculty of Computer Science and Engineering TP.HCM Chapter 6: : Backtracking and Branch-and-Bound Algorithms Analysis Design and (C03031 Instructor: Assoc. Prof. Dr. Vo Thi Ngoc Chau Email: chauvtn@hcmut.edu.vn Semester 2 - 2022-2023" }, { "page_index": 642, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_002.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_002.png", "page_index": 642, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:46:20+07:00" }, "raw_text": "BK Course Learning Outcomes TP.HCM 1. Able to analyze the complexity of the algorithms (recursive or iterative) and estimate the efficiency of the algorithms. 2. Improve the ability to design algorithms in different areas by decomposing a computing problem into advanced algorithm design strategies. 3. Able to discuss Np-completeness. 2" }, { "page_index": 643, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_003.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_003.png", "page_index": 643, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:46:24+07:00" }, "raw_text": "BK References TP.HCM [1] Cormen, T. H., Leiserson, C. E, and Rivest, R. L. Introduction to Algorithms, The MiT Press, 2009. [2] Levitin, A., Introduction to the Design and Analysis of Algorithms, 3rd Edition, Pearson, 2012 [3] Sedgewick, R., A/gorithms in C++, Addison-Wesley. 1998. [4] Weiss, M.A., Data Structures and Algorithm Analysis in C, TheBenjamin/Cummings Publishing, 1993. 3" }, { "page_index": 644, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_004.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_004.png", "page_index": 644, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:46:29+07:00" }, "raw_text": "BK Course Oytline TP.HCM Chapter 1. Fundamentals 0 1 Chapter 2. Divide-and-Conquer Strategy Chapter 3. Decrease-and-Conguer Strategy 0 1 Chapter 4. Transform-and-Conquer Strategy 0 Chapter 5. Dynamic Programming and Greedy Strategies Chapter 6. Backtracking and Branch-and- 0 1 Bound Chapter 7. NP-completeness 0 Chapter 8. Approximation Algorithms 0 1 4" }, { "page_index": 645, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_005.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_005.png", "page_index": 645, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:46:32+07:00" }, "raw_text": "Chapter 6. BK TP.HCM Backtracking Branch-and-Bound and 6.1. Backtracking algorithms 06 6.1.1. The Knight's Tour problem 6.1.2. The Eight Queens problem 6.2. Branch-and-Bound algorithms 6.2.1. Traveling Salesman problem 5" }, { "page_index": 646, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_006.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_006.png", "page_index": 646, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:46:36+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM The task is to determine an algorithm for finding solutions to specific problems not by following a fixed rule of computation, but by trial-and-error. The common pattern is to decompose the trial-and- error process into partial tasks. Often these tasks are most naturally expressed in recursive terms and consist of the exploration of a finite number of subtasks. We may view the entire process as a search process that gradually builds up and scans a tree of subtasks. 6" }, { "page_index": 647, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_007.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_007.png", "page_index": 647, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:46:41+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM State space tree To illustrate the working of a backtracking algorithm, we construct a tree structure which records the executed selections. This tree structure is called state space tree or search tree. The root node of the tree represents the origina/ state before the start of the search process. The nodes in the first level represent the selections corresponding to the first component of the solution. The nodes in the second level represent the selections corresponding to the second component of the solution, and so on. 7" }, { "page_index": 648, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_008.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_008.png", "page_index": 648, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:46:45+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM State space tree A node in the state space tree is called promising if it corresponds to the partial solution which can lead to a complete solution; otherwise, it is called a non-promising solution Leaf nodes represent the dead-end situations or a complete solution. If each node in the state space tree has children on average, and the length of the solution path is N, then the total number of nodes in the tree is computed as 1+ a1+ a2 +...+aN =(aN+1-1)/(a-1) When N is large enough, (N+1 -1)/(-1) is approximately equal to aN 8" }, { "page_index": 649, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_009.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_009.png", "page_index": 649, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:46:50+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM A backtracking algorithm with a state space tree In the majority of cases, a state-space tree for a backtracking algorithm is constructed in the manner of depth-first search. If the current node is promising, its child is generated by adding the first remaining legitimate option for the next component of a solution, and the processing moves to this child. If the current node turns out to be nonpromising, the algorithm backtracks to the node's parent to consider the next possible option for its last component; if there is no such option, it backtracks one more level up the tree, and so on. Finally, if the algorithm reaches a complete solution to the problem, it either stops (if just one so/ution is required) or continues searching for other possible solutions. 9" }, { "page_index": 650, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_010.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_010.png", "page_index": 650, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:46:54+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM procedure try; The general begin intialize selection of candidates: repeat pattern of a select next: backtracking if acceptable then begin algorithm record it: if solution incomplete then begin try next step: if not successful then cancel recording end end until successful v no more candidates end 10" }, { "page_index": 651, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_011.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_011.png", "page_index": 651, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:46:59+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM If at each step procedure try (i: integer); var k : integer: the number of begin k:=0; candidates to be repeat investigated is k:=k+1: select k-th candidate: fixed, say m. if acceptable then then the begin record it: algorithm is if i Z. Solve this problem by a backtracking algorithm. What is a state space tree for the given instance of the problem? 12" }, { "page_index": 653, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_013.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_013.png", "page_index": 653, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:47:08+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM Let's assign values from the set of values K1,2} to X,Y and Z for constraints: X = Y, X # Z, Y > Z X =1 X =2 Y=2 Y= 1 Y= 1 Y=2 X z =1 X z =2 z=2 z=1 X X X solution 13" }, { "page_index": 654, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_014.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_014.png", "page_index": 654, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:47:11+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM Time complexity of a backtracking algorithm Since time complexity of a backtracking algorithm is proportional to the number of nodes in the state space tree, the time complexity of this algorithm is proportional to a Computational time of a backtracking algorithm is always exponential. 14" }, { "page_index": 655, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_015.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_015.png", "page_index": 655, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:47:16+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM The problem of finding a Hamiltonian cycle in an indirected graph Given an indirected graph, find a Hamiltonian cycle which is a path that starts and ends at the same vertex and passes through all the other vertices exactly once. For example: Given an indirected graph (G), a Hamiltonian cycle is in blue. b Graph (G) f 0 d e 15" }, { "page_index": 656, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_016.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_016.png", "page_index": 656, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:47:20+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM The problem of finding a Hamiltonian cycle in an indirected graph Given an indirected graph, find a Hamiltonian cycle which is a path that starts and ends at the same vertex and passes through all the other vertices exactly once. State space tree Root: a starting vertex to start a depth-first search recursively on the graph Each node represents the j-th visited vertex forming a path of length j-1 of the cycle A leaf that represents the V-th visited vertex that has an edge back to the starting vertex forms a solution. The tree is constructed in the depth-first-search manner. 16" }, { "page_index": 657, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_017.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_017.png", "page_index": 657, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:47:26+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM The problem of finding a Hamiltonian cycle in an indirected graph For example: given an indirected graph (G), one Hamiltonian cycles are found in blue. Graph (G) b : a b C C d b d e d e f e e a b c e x X d c d b d e x V V 17" }, { "page_index": 658, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_018.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_018.png", "page_index": 658, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:47:30+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM The problem of generating all permutations 0 Given a set of n elements A= {a1, az,...,an}, we want to generate all n! different permutations from that set. For example: A = {1, 2, 3}. All permutations are: 123,132,312, 213, 231,321. State space tree Root: the starting point with no decision made yet Each node represents a part of one permutation in the solution formed so far. Each leaf represents one permutation in the solution. The tree is constructed in the depth-first-search manner. 18" }, { "page_index": 659, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_019.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_019.png", "page_index": 659, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:47:34+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM The problem of generating all permutations For example: A = {1, 2, 3}. All permutations are: 123, 132, 312, 213, 231, 321. 3 1 2 2 2 3 1 3 1 3 2 3 1 2 1 123 132 213 231 312 321 19" }, { "page_index": 660, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_020.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_020.png", "page_index": 660, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:47:38+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM The m-coloring problem with m colors Given a graph, check whether there exists a coloring of the graph's vertices with no more than m colors in such a way that no two adjacent vertices are assigned the same color. For example: given an indirected graph (G), its colored graph with {pink, green, blue} is below. b a + C d d e Graph (G) Colored graph (G) 20" }, { "page_index": 661, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_021.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_021.png", "page_index": 661, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:47:43+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM The m-coloring problem with m colors Given a graph, check whether there exists a coloring of the graph's vertices with no more than m colors in such a way that no two adjacent vertices are assigned the same color. State space tree Root: a starting vertex to be colored Each node represents a vertex which is the j-th colored one. Each edge represents a color to color the starting vertex of this edge A leaf is a dead-end or a solution. A solution leaf is an end of the V-th colored vertex. A tree is constructed in the depth-first search manner. 21" }, { "page_index": 662, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_022.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_022.png", "page_index": 662, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:47:50+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM The m-coloring problem with m colors For example: given an indirected graph (G), its colored graph with {pink, green, blue} is below. a b a b p g b C p b g X C d e b g X X X X d d b x x X e e f p p C X X x x + + b d g X X X V 22 V" }, { "page_index": 663, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_023.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_023.png", "page_index": 663, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:47:54+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM The subset-sum problem positive integers whose sum is equal to a given positive integer d. For example: For an ordered set S = {3, 5, 6, 7} and d = 15, solution = 3, 5, 7}. State space tree Root: the starting point with no decision made yet. Each node represents the current accumulated sum Nonpromising nodes with constraints: s' + si+1 > d (the sum s'is too large) n s'+ sj < d (the sum s'is too small) j=i+1 Where: s s, ... sn\"" }, { "page_index": 664, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_024.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_024.png", "page_index": 664, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:48:00+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM The subset-sum problem For example: For an ordered set S = {3, 5, 6, 7} and d = 15, solution = 3, 5, 7}. 0 with 3 w/o 3 3 with 5 w/o 5 with 5 w/o 5 5 0 8 3 with 6 w/o 6 with 6 w/o 6 w/o with 6 x 8 0+6+7<15 14 9 3 11 5 with w/o 7 x x x x x 14+7>15 9+7>15 15 3+7<15 11+7>15 5+7<15 8 x 15=d 8<15 24" }, { "page_index": 665, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_025.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_025.png", "page_index": 665, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:48:03+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM Your turn : 6.1.1. List three main characteristics of a backtracking algorithm. 6.1.2. What is a state space tree? Give 06 another name of this tree. 6.1.3. Compare the backtracking strategy with the brute-force one. 25" }, { "page_index": 666, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_026.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_026.png", "page_index": 666, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:48:08+07:00" }, "raw_text": "BK 6.1. Backtracking algorithms TP.HCM Your turn : 6.1.4. Draw a state space tree for each instance of the following problems. Design and analyze the backtracking algorithms for these problems. 6.1.4.1. The problem of generating all permutations of 1, 2 3,4} 6.1.4.2. The subset-sum problem: S = 3,1,7,4,5} and d = 11 6.1.4.3. The problem of finding a Hamiltonian cycle in (G) 6.1.4.4. The m-coloring problem on (G) with {red, green blue} b Graph (G) d C e g f 26" }, { "page_index": 667, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_027.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_027.png", "page_index": 667, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:48:12+07:00" }, "raw_text": "6.1.1. The Knight's Tour BK TP.HCM problem Given a n x n board with n2 fields, a knight - being allowed to move according to the rules of chess - is The problem is to find a covering of the entire board, if 0 there exists one, i.e., to compute a tour of n2 -1 moves such that every field of the board is visited exactly once. The obvious way to reduce the problem of covering n? 0 fields is to consider the problem of either - finding out that none is possible. Let us define an algorithm trying to perform a next move. 27" }, { "page_index": 668, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_028.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_028.png", "page_index": 668, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:48:18+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem the problem is to find a covering of the entire board, if there exists one, i.e., to compute a tour of n2 -1 moves such that every field of the board is visited exactly once. 1 2 3 4 5 1 2 3 4 5 1 1 1 1 6 15 10 21 2 2 14 20 5 16 3 3 19 2 7 22 11 4 4 8 13 24 17 4 5 5 25 18 3 12 23 28" }, { "page_index": 669, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_029.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_029.png", "page_index": 669, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:48:22+07:00" }, "raw_text": "6.1.1. The Knight's Tour BK TP.HCM problem procedure try next move; begin initialize selection of moves; repeat select next candidate from list of next moves: if acceptable then begin record move: if board not full then begin try next move: if not successful then erase previous recording end end until (move was successful) v (no more candidates end 29" }, { "page_index": 670, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_030.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_030.png", "page_index": 670, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:48:26+07:00" }, "raw_text": "6.1.1. The Knight's Tour BK TP.HCM problem In this algorithm, we use a new \"problem-solving method based on backtracking. Its main feature is that: Steps toward the total solution are attempted and recorded that may later be taken back and erased in the recordings when it is discovered that the step does not possibly lead to the total solution, that the step leads to a \"dead-end\". 30" }, { "page_index": 671, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_031.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_031.png", "page_index": 671, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:48:30+07:00" }, "raw_text": "6.1.1. The Knight's Tour BK TP.HCM problem Data representation Let's represent the board by a matrix, h. type index = 1..n; var h: array[index, index] of integer; h[x, y] = 0: field has not been visited h[x, y] = i: field has been visited in the i-th move (1 i n2) u, v: coordinates of possible move destination. The predicate \"acceptable\" can be expressed as (1, there are 8 potential candidates for coordinates of the destination. They are numbered 1 to 8 as follows: 3 2 4 1 5 8 6 33" }, { "page_index": 674, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_034.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_034.png", "page_index": 674, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:48:42+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Relationship between the current coordinate pair and 8 possible moves: y = 1 y = 2 y = 3 y = 4 y = 5 3 2 x = 1 (x-2,y-1) (x-2,y+1) 4 1 x = 2 (x-1,y-2) (x-1,y+2) x = 3 (x,y) 5 8 x = 4 (x+1,y-2) (x+1,y+2 6 7 x = 5 (x+2,y-1) (x+2,y+1) 34" }, { "page_index": 675, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_035.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_035.png", "page_index": 675, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:48:46+07:00" }, "raw_text": "6.1.1. The Knight's Tour BK TP.HCM problem A simple method of obtaining u, v from x, y is by addition of the coordinate differences stored in two arrays a and b. Then an index k may be used to number the \"next candidate\". program knightstour (output): const n = 5; nsq = 25: type index = 1..n i,j: index; q: boolean: var s: set of index: a,b: array [1..8] of integer; h: array [index, index] of integer: 35" }, { "page_index": 676, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_036.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_036.png", "page_index": 676, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:48:50+07:00" }, "raw_text": "6.1.1. The Knight's Tour BK TP.HCM problem procedure try (i: integer; x, y: index; var q:boolean)) A backtracking algorithm for var k,u,v : integer; q1: boolean; the knight's tour problem. begin k:=0; repeat k:=k+1; q1:=false; u:=x+a[k]; v:=y+b[k] Time complexity : if (u in s) (v in s) then if h[u,v]=0 then Abstract operation: move begin Worst case analysis h[u,v]:=i; if i< nsq then begin try(i+1, u, v, q1); if- q1 then h[u,v]:=0 end else q1 :=true end until q1 v (k= 8): q:=q1 end 36" }, { "page_index": 677, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_037.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_037.png", "page_index": 677, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:48:55+07:00" }, "raw_text": "6.1.1. The Knight's Tour BK TP.HCM problem begin s:=1,2,3,4,5] a[1]:= -1; b[1]:=2; h[1,1]:=1; try (2,1,1,q) a[2]:= -2; b[2]:=1; if q then a[3]:= -2; b[3]:=-1; for i:=1 to n do a[4]:= -1; b[4]:=-2; begin a[5]:= 1; b b[5]:= -2; for j:=1 to n do a[6]:= 2; l b[61:= -1; write(h[i,j:5) a[7]:= 2; b[7]:= 1; writeln a[8]:= 1; b[8]:=2; end for i:=1 to n do else writeln (NO SOLUTION) for j:=1 to n do h[i,jl:=0 end. 37" }, { "page_index": 678, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_038.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_038.png", "page_index": 678, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:48:59+07:00" }, "raw_text": "6.1.1. The Knight's Tour BK TP.HCM problem from which the tour starts. h[xo,y,]:= 1; try(2,xo, Yo, q A solution is obtained with initial position l <1,1> for n=5 1 6 15 10 21 14 20 5 16 19 2 7 22 11 8 13 24 17 4 25 18 3 12 23 38" }, { "page_index": 679, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_039.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_039.png", "page_index": 679, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:49:02+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 1 2 3 4 5 39" }, { "page_index": 680, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_040.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_040.png", "page_index": 680, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:49:06+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 1 2 3 2 4 5 40" }, { "page_index": 681, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_041.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_041.png", "page_index": 681, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:49:10+07:00" }, "raw_text": "6.1.1. The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 1 2 3 3 2 4 5 41" }, { "page_index": 682, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_042.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_042.png", "page_index": 682, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:49:14+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 1 2 3 3 2 4 5 42" }, { "page_index": 683, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_043.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_043.png", "page_index": 683, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:49:18+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 1 2 3 3 5 2 4 5 43" }, { "page_index": 684, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_044.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_044.png", "page_index": 684, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:49:22+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 1 2 6 3 3 5 2 4 5 44" }, { "page_index": 685, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_045.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_045.png", "page_index": 685, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:49:26+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 7 1 2 6 3 3 5 2 4 5 45" }, { "page_index": 686, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_046.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_046.png", "page_index": 686, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:49:30+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 7 1 2 6 3 3 5 2 8 4 5 46" }, { "page_index": 687, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_047.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_047.png", "page_index": 687, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:49:34+07:00" }, "raw_text": "6.1.1. The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 7 1 2 6 3 3 5 2 8 4 5 47" }, { "page_index": 688, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_048.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_048.png", "page_index": 688, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:49:38+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 7 1 2 10 6 3 3 5 2 8 4 5 48" }, { "page_index": 689, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_049.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_049.png", "page_index": 689, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:49:41+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 7 1 2 10 6 3 3 5 2 8 4 11 5 49" }, { "page_index": 690, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_050.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_050.png", "page_index": 690, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:49:46+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 7 1 2 10 6 3 3 5 2 8 4 11 5 12 50" }, { "page_index": 691, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_051.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_051.png", "page_index": 691, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:49:50+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 7 1 2 10 6 3 3 5 2 8 13 4 11 5 12 51" }, { "page_index": 692, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_052.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_052.png", "page_index": 692, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:49:54+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 6 3 3 5 2 8 13 4 11 5 12 52" }, { "page_index": 693, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_053.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_053.png", "page_index": 693, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:49:59+07:00" }, "raw_text": "6.1.1. The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 3 5 2 8 13 4 11 5 12 53" }, { "page_index": 694, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_054.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_054.png", "page_index": 694, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:50:04+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 3 5 2 8 13 4 16 11 5 12 54" }, { "page_index": 695, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_055.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_055.png", "page_index": 695, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:50:09+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 3 5 2 17 8 13 4 16 11 5 12 55" }, { "page_index": 696, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_056.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_056.png", "page_index": 696, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:50:14+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 18 3 5 2 17 8 13 4 16 11 5 12 56" }, { "page_index": 697, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_057.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_057.png", "page_index": 697, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:50:21+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 18 3 5 2 17 8 13 4 16 11 19 5 12 57" }, { "page_index": 698, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_058.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_058.png", "page_index": 698, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:50:28+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 18 3 5 2 17 8 13 4 16 11 19 5 20 12 58" }, { "page_index": 699, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_059.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_059.png", "page_index": 699, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:50:33+07:00" }, "raw_text": "6.1.1. The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 18 x 3 5 2 17 8 13 4 16 11 19 5 20 12 59" }, { "page_index": 700, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_060.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_060.png", "page_index": 700, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:50:38+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 18 x 3 5 2 17 8 13 4 16 11 19 5 12 60" }, { "page_index": 701, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_061.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_061.png", "page_index": 701, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:50:43+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 10 15 6 3 18 2 x 3 5 2 17 8 13 4 16 11 5 12 61" }, { "page_index": 702, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_062.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_062.png", "page_index": 702, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:50:48+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 3 5 2 17 8 13 4 16 11 5 18 12 62" }, { "page_index": 703, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_063.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_063.png", "page_index": 703, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:50:53+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 3 5 2 17 8 13 4 16 11 19 5 18 12 63" }, { "page_index": 704, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_064.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_064.png", "page_index": 704, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:50:58+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 20 3 5 2 17 8 13 4 16 11 19 5 18 12 64" }, { "page_index": 705, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_065.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_065.png", "page_index": 705, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:51:02+07:00" }, "raw_text": "6.1.1. The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 20 x 3 5 2 17 8 13 4 16 11 19 5 18 12 65" }, { "page_index": 706, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_066.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_066.png", "page_index": 706, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:51:07+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 x 3 5 2 17 8 13 4 16 11 19 5 18 12 66" }, { "page_index": 707, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_067.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_067.png", "page_index": 707, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:51:12+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 x 3 5 2 17 8 13 4 16 11 5 18 12 67" }, { "page_index": 708, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_068.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_068.png", "page_index": 708, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:51:17+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 3 5 2 17 8 13 4 16 11 18 5 12 68" }, { "page_index": 709, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_069.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_069.png", "page_index": 709, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:51:21+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 3 5 2 17 8 13 4 16 11 18 5 19 12 69" }, { "page_index": 710, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_070.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_070.png", "page_index": 710, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:51:26+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 x 3 5 2 17 8 13 4 16 11 18 5 19 12 70" }, { "page_index": 711, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_071.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_071.png", "page_index": 711, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:51:31+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 x 3 5 2 17 8 13 4 16 11 18 5 12 71" }, { "page_index": 712, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_072.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_072.png", "page_index": 712, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:51:36+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 x 5 2 17 3 8 13 4 16 11 5 12 72" }, { "page_index": 713, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_073.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_073.png", "page_index": 713, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:51:41+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 4 9 14 7 1 2 10 15 6 3 3 5 2 8 13 4 16 11 5 17 12 73" }, { "page_index": 714, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_074.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_074.png", "page_index": 714, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:51:46+07:00" }, "raw_text": "6.1.1.The Knight's Tour BK TP.HCM problem Demonstration with an initial position <1, 1> on a 5-by-5 board: 1 2 3 4 5 1 6 15 10 21 1 2 14 9 20 5 16 19 2 22 3 11 4 8 13 24 17 4 5 25 18 3 12 23 74" }, { "page_index": 715, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_075.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_075.png", "page_index": 715, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:51:50+07:00" }, "raw_text": "6.1.1. The Knight's Tour BK TP.HCM problem Your turn: 6.1.1.1. Trace-by-hand the backtracking algorithm for the knight's tour problem on a 4-by-4 board, starting from <1, 1>. 6.1.1.2. Trace-by-hand the backtracking algorithm for the knight's tour problem on a 5-by-5 board, starting from <2, 2>. 6.1.1.3. Trace-by-hand the backtracking algorithm for the knight's tour problem on a 6-by-6 board, starting from <3, 3>. 75" }, { "page_index": 716, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_076.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_076.png", "page_index": 716, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:51:53+07:00" }, "raw_text": "6.1.1. The Knight's Tour BK TP.HCM problem Your turn: 6.1.1.4. Modify the backtracking algorithm 0 6 previously designed for one solution to a given instance of the knight's tour problem so that it can generate all the possible tours starting from a given initial position. Analyze the time complexity of the modified algorithm. 6.1.1.5. Give an example to trace-by-hand the modified algorithm. What is its corresponding state space tree? 76" }, { "page_index": 717, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_077.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_077.png", "page_index": 717, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:51:57+07:00" }, "raw_text": "6.1.2. The Eight Queens BK TP.HCM problem This problem was investigated by C.F. Gauss in 1850 but he did not completely solve it. The eight queens problem is stated as: \"Eight queens are to be placed on a chess board in such a way that no queen checks against any other queens\". Chess rule: A queen can attack all other queens in either the same column, row, or diagonals on the board. Using the backtracking template, we obtain an initial version of a backtracking algorithm for the 8 queens problem. 77" }, { "page_index": 718, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_078.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_078.png", "page_index": 718, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:52:01+07:00" }, "raw_text": "6.1.2. The Eight Queens BK TP.HCM problem 1 Q1 One 2 Q7 solution for 3 Q5 the Eight 4 Q8 Queens 5 Q2 problem 6 Q4 Q6 8 Q3 78" }, { "page_index": 719, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_079.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_079.png", "page_index": 719, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:52:06+07:00" }, "raw_text": "6.1.2. The Eight Queens BK TP.HCM problem procedure try (i: integer): begin initialize selection of positions for the i-th queen repeat make next selection: if safe then begin setqueen: ifi< 8 then begin try (i + 1): if not successful then remove queen end end until s successful v no more positions end 79" }, { "page_index": 720, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_080.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_080.png", "page_index": 720, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:52:10+07:00" }, "raw_text": "6.1.2. The e Eight Queens BK TP.HCM problem Data representation How to represent 8 queens on the board? var x: array[1..8] of integer; a: array[1..8] of Boolean; b: array[b1..b2] of Boolean c: array[c1..c2] of Boolean: where x[i] denotes the row position of the queen in the i column. a[j] means no queen lies in the j-th row. b[k] means no queen occupies the k-th diagonal c[k] means no queen sits on the k-th diagonal 80" }, { "page_index": 721, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_081.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_081.png", "page_index": 721, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:52:14+07:00" }, "raw_text": "6.1.2. The Eight Queens BK TP.HCM problem The choice for index bounds b1, b2, c1, and c2 is dictated by the way that indices of b and c are computed. We note that in the diagonal all fields have the same sums of their coordinates i + i, and that in the diagonal, the coordinate differences (i-j) a are constant Given these data, the statement setqueen is refined as: x[i] := j; a[j] := false; b[i+j] := false; c[i-j] := false: The statement removequeen is refined as: a[j] := true; b[i+j] := true; c[i-j] := true; The condition safe is represented as: a[j] b[i+j] c[i-j] 81" }, { "page_index": 722, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_082.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_082.png", "page_index": 722, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:52:18+07:00" }, "raw_text": "6.1.2. The Eight Queens BK TP.HCM problem y 2 7 (1+6, 2+5, ...) u = x+ y 16 1 2 3 4 5 6 7 x 8 1 2 3 4 5 7 8 v = x - y -7 (1-8) -3 3 5 7 (8-1) 82" }, { "page_index": 723, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_083.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_083.png", "page_index": 723, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:52:24+07:00" }, "raw_text": "6.1.2. The Eight Queens BK TP.HCM problem program eightqueeen1(output); begin {find one solution to eight queens x[i]:=j; problem} a[1j]:=false; b[i+j]:=false; i : integer; q: boolean: c[i-j]:=false, var a : array [1..8] of boolean; if i<8 then b : array [2..16] of boolean; begin c : array [-7..7] of boolean: try (i+1, q) x : array [1..8] of integer; if - q then procedure try(i: integer; var q: begin boolean); a]:=true; b[i+j]:=true, var 1: integer c[i-j]:=true begin end j:=0; end repeat else q:=true j:=j+1; q:=false; end if a[j] b[i+j] c[i-j] then untiI q v (j=8) end {try}; 83" }, { "page_index": 724, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_084.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_084.png", "page_index": 724, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:52:30+07:00" }, "raw_text": "6.1.2. The Eight Queens BK TP.HCM problem program eightqueeen1(output): Time complexity of {find one solution to eight queens problem} a backtracking begin algorithm for the for i:= 1 to 8 do a[i]:=true: for i:= 2 to 16 do b[i]:=true; eight queens for i:=-7 to 7 do c[i]:=true problem : try (1,q); Abstract operation : if q then for i:=1 to 8 do placement write (x[i]:4) Worst case analysis : writeln Cn = O(n!) end 84" }, { "page_index": 725, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_085.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_085.png", "page_index": 725, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:52:34+07:00" }, "raw_text": "6.1.2. The Eight Queens BK TP.HCM problem 1 Q1 One 2 Q7 solution for 3 Q5 the Eight 4 Q8 Queens 5 Q2 problem 6 Q4 Q6 8 Q3 85" }, { "page_index": 726, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_086.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_086.png", "page_index": 726, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:52:39+07:00" }, "raw_text": "6.1.2.The Eight Queens BK TP.HCM problem A solution to the four queens problem 1 Q1 1 Q1 2 2 Q2 3 3 4 4 1 Q1 1 Q1 Q3 2 2 x Q2 3 3 Q2 4 4 86" }, { "page_index": 727, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_087.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_087.png", "page_index": 727, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:52:43+07:00" }, "raw_text": "6.1.2. The Eight Queens BK TP.HCM problem Q1 Q1 1 1 Q3 2 2 3 3 Q2 Q2 4 4 Q1 Q3 1 1 Q3 Q1 2 2 H4 x Q4 3 3 Q2 Q2 4 4 87" }, { "page_index": 728, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_088.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_088.png", "page_index": 728, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:52:47+07:00" }, "raw_text": "6.1.2.The Eight Queens BK TP.HCM problem Extension for all the solutions The extension is to find not only one but all the solutions to the posed problem. Extension method: Once a solution is found and recorded, we proceed to the next candidate delivered by the systematic selection process. The general schema is derived from the backtracking template and modified to generate all the solutions. 88" }, { "page_index": 729, "chapter_num": 6, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_089.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_6/slide_089.png", "page_index": 729, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:52:51+07:00" }, "raw_text": "6.1.2. The Eight Queens BK TP.HCM problem procedure try(i: integer): A backtracking var k: integer. algorithm begin for k:=1 to m do template to begin generate all the select the k-th candidate: solutions to a if acceptable then given problem begin record it: if i Some problems can be solved efficient/y, some inefficiently, and some cannot. Why? 6" }, { "page_index": 763, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_007.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_007.png", "page_index": 763, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:56:01+07:00" }, "raw_text": "BK Quick Review TP.HCM For many problems we have several efficient algorithms to solve. Sorting n elements, search for a key in n elements, . .. However, many problems arise in practice which do not have such efficient solving algorithms. Permutations of n elements, graph coloring, bin packing, .. For a large class of problems we can't even tell whether or not an efficient algorithm might exist. Hamiltonian cycle problem, traveling salesman problem, . . 7" }, { "page_index": 764, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_008.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_008.png", "page_index": 764, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:56:05+07:00" }, "raw_text": "BK Quick Review TP.HCM Easy problems vs. Hard problems A great deal of research has been done in this area and lends to the development of mechanisms by which new problems can be classified as being as difficult as old problems. Sometimes, the line between \"easy\" and \"hard\" problems is hardly decided For example: P1 (Easy): Is there a path from x to y with weight M? P2 (Hard): Is there a path from x to y with weight M? P1 - BFS in linear time P2 - Branch-and-Bound in exponential time 8" }, { "page_index": 765, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_009.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_009.png", "page_index": 765, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:56:08+07:00" }, "raw_text": "Z.1. Deterministic and Nondeterministic BK TP.HCM Polynomial-Time algorithms P : a set of all the problems that can be solved by deterministic algorithms in polynomial time. Deterministic: at any time, whatever the algorithm is doing, there is only one thing that it could do next. For example : Sorting N elements belongs to P since there is Insertion sort whose time complexity is proportional to N2 9" }, { "page_index": 766, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_010.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_010.png", "page_index": 766, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:56:13+07:00" }, "raw_text": "Z.1. Deterministic and Nondeterministic BK TP.HCM Polynomial-Time algorithms Non-determinism One way to extend the power of a computer is to endow it with the power of non-determinism. Non-determinism : when an algorithm is faced with a choice of several options, it has the power to \"guess\" the right one. Non-deterministic algorithms For example: Let A be an unsorted set of n positive integers. A nondeterministic algorithm NSORT(A, n) sorts these numbers in ascending order and then outputs them in that order. 10" }, { "page_index": 767, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_011.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_011.png", "page_index": 767, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:56:18+07:00" }, "raw_text": "Z.1. Deterministic and Nondeterministic BK TP.HCM Polynomial-Time algorithms NSORT (A, n) : a non-deterministic algorithm // An array B is used as a temporary array. procedure NSORT (A, n) // sort n positive integers in ascending order: <= begin for i:= 1 to n do B[i]:= 0; / guessing stage for i:= 1 to n do begin Function choice(1:n) can j := choice(1:n) if B[j] <> 0 then failure choose one of the correct else B[j]:= A[i] positions in the range end; from 1 to n. / verification stage for i:= 1 to n-1 do if B[i] > B[i+1] then failure; print(B) ; success end; 11" }, { "page_index": 768, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_012.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_012.png", "page_index": 768, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:56:22+07:00" }, "raw_text": "Z.1. Deterministic and Nondeterministic BK TP.HCM Polynomial-Time algorithms A deterministic interpretation of a nondeterministic algorithm can be made by allowing unbounded parallelism in computation. Whenever a choice is made, the algorithm makes several copies of itself. One copy is made for each of the possible choices. Thus, many copies are executing at the same time. The first copy that reaches a successful completion terminates all of the other computations. If a copy reaches a failure completion, then only that copy of the algorithm terminates. 12" }, { "page_index": 769, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_013.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_013.png", "page_index": 769, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:56:26+07:00" }, "raw_text": "Z.1. Deterministic and Nondeterministic BK TP.HCM Polynomial-Time algorithms Nondeterministic algorithms In fact, a nondeterministic machine does not make any copies of an algorithm when a choice is made. Instead, it has the ability to select the \"correct \" element.from a set of allowable choices when a choice is made. A \"correct\" element is defined relatively to the shortest sequence of choices that leads to a successful termination termination, we shall assume that the algorithm terminates in one unit of time with output unsuccessful computation \". 13" }, { "page_index": 770, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_014.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_014.png", "page_index": 770, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:56:30+07:00" }, "raw_text": "Z.1. Deterministic and Nondeterministic BK TP.HCM Polynomial-Time algorithms Note on the nondeterministic algorithm NSORT : The success and failure signals are equivalent to a stop statement in a deterministic algorithm The complexity of NSORT is O(n). Its verification stage runs in polynomial time. NP: a set of all the problems that can be solved by nondeterministic algorithms in polynomial time. For example: \"Is there a longest path from vertex x to vertex y in a graph?\" is an NP problem. 14" }, { "page_index": 771, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_015.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_015.png", "page_index": 771, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:56:34+07:00" }, "raw_text": "Z.1. Deterministic and Nondeterministic BK TP.HCM Polynomial-Time algorithms Circuit satisfiability problem (csP) Given a logical formula in the form of: (x1 + x3 + x5)*(x1+x2 + x4)*(x3 + x4+x5)* (x2 +x3 + x5) where the xi s represent Boolean variables (true or false), + represents OR, * represents AND, and represents NOT. The CSP problem is to determine whether or not there exists an assignment of truth values to the variables that makes the formula true. CSP is an NP problem 15" }, { "page_index": 772, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_016.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_016.png", "page_index": 772, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:56:38+07:00" }, "raw_text": "Z.1. Deterministic and Nondeterministic BK TP.HCM Polynomial-Time algorithms A nondeterministic algrithm for CSP procedure EVAL(E, n) boolean x[n]; begin for i= 1 to n do x[i] := choice(true, false) end; if (E is true) then success else failure end; 16" }, { "page_index": 773, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_017.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_017.png", "page_index": 773, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:56:43+07:00" }, "raw_text": "Z.1. Deterministic and Nondeterministic BK TP.HCM Polynomial-Time algorithms Your turn: 7.1.1. Distinguish a deterministic algorithm from a nondeterministic polynomial-time one. 7.1.2. Which statement is correct about NP? 7.1.2.1. NP is a set of the nonpolynomial time problems. Z.1.2.2. NP is a set of the nondeterministic problems. 7.1.2.3. NP is a set of the nonpolynomial time algorithms for hard problems. 7.1.2.4. NP is a set of the problems that can be solved by nondeterministic algorithms in polynomial time. 7.1.2.5. NP is a set of the hard problems that can be solved by deterministic algorithms in nonpolynomial time. 7.1.3. Is P a proper subset of NP? Why? Why not? 17" }, { "page_index": 774, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_018.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_018.png", "page_index": 774, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:56:47+07:00" }, "raw_text": "Z.1. Deterministic and Nondeterministic BK TP.HCM Polynomial-Time algorithms Your turn: 7.1.4. Given a decision version of the 0-1 0 knapsack problem as follows. Given a knapsack of size M, a list of n items, each of which has weight w, and value vi, for i=1..n, and R is a positive real value. The problem is to check which items will be taken by the thief to obtain the total value of the knapsack greater than or equal to R. Design and analyze a nondeterministic algorithm for this decision problem. 18" }, { "page_index": 775, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_019.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_019.png", "page_index": 775, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:56:51+07:00" }, "raw_text": "Z.1. Deterministic and Nondeterministic BK TP.HCM Polynomial-Time algorithms Your turn: 7.1.5. Design and analyze a nondeterministic algorithm for the subset sum problem. 7.1.6. Design and analyze a nondeterministic algorithm for the vertex cover problem. 7.1.7. Design and analyze a nondeterministic 0 algorithm for the Hamiltonian cycle problem. Hint: a decision version of each problem in 7.1.5, 7.1.6, and 7.1.7 might be defined and then a nondeterministic algorithm can be designed. 19" }, { "page_index": 776, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_020.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_020.png", "page_index": 776, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:56:55+07:00" }, "raw_text": "BK 7.2. NP-completeness TP.HCM There is a list of problems that are known to belong to NP but might or might not belong to P. (That is, they are easy to solve on a non-deterministic machine but. no one has been able to find an efficient algorithm on a conventional deterministic machine for any of them These problems have an additional property: \"If any of these problems can be solved in polynomial time on a deterministic machine, then so can all problems in NP.\" 20" }, { "page_index": 777, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_021.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_021.png", "page_index": 777, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:56:58+07:00" }, "raw_text": "BK 7.2. NP-completeness TP.HCM The problems that are known to belong to NP but might or might not belong to P are said to be Np-complete. NP-complete P NP 21" }, { "page_index": 778, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_022.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_022.png", "page_index": 778, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:57:03+07:00" }, "raw_text": "BK 7.2. NP-completeness TP.HCM NP-complete problems form a subset of the most difficult problems in NP. The primary tool used to prove that problems are NP- complete uses the idea of polynomial reducibility. Any algorithm to solve a new problem in NP can be used to solve some known NP-complete problem by the following process: transform any instance of the known NP-complete problem using the given algorithm, then transform the solution back to a solution of the NP-complete problem. 22" }, { "page_index": 779, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_023.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_023.png", "page_index": 779, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:57:06+07:00" }, "raw_text": "BK 7.2. NP-completeness TP.HCM Proving NP-completeness by reduction NP problems known candidate for NP-complete Np-completeness problem 23" }, { "page_index": 780, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_024.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_024.png", "page_index": 780, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:57:08+07:00" }, "raw_text": "BK 7.2. NP-completeness TP.HCM Polynomial reducibility Let L1 and L2 be problems. L1 polynomially reduces to L2, (also written L1 ap L2) if and only if there is a way to transform L1 to L2 such that any deterministic algorithm that solves L2 in polynomial time can be used to solve L1. The transformation must be done in polynomial time. 24" }, { "page_index": 781, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_025.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_025.png", "page_index": 781, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:57:12+07:00" }, "raw_text": "BK 7.2. NP-completeness TP.HCM To prove that a problem L is NP-complete, we need to prove that: 1. L belongs to NP 2. Some known NP-complete problem is polynomially reducible to L. For example: Given two following problems Traveling Salesman Problem (TSP): Given a set of cities and distances between a pair, find a tour of all the cities of distance less than or equal to M. Hamiltonian Cycle Problem (HCP): Given a graph. find a simple cycle that includes all the vertices. 25" }, { "page_index": 782, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_026.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_026.png", "page_index": 782, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:57:16+07:00" }, "raw_text": "BK 7.2. NP-completeness TP.HCM Given HCP is NP-complete, we wish to determine whether or not TSP is also NP-complete TSP belongs to NP. Any algorithm for solving TSP can be used to solve HCP, via polynomial reduction: Given an instance of HCP (a graph), construct an instance of TSP as follows: for cities in TSP, use the set of N vertices in the graph 1 - for distances between each pair of cities, use 1 if there is an edge between the corresponding vertices in the graph, 2 if there is no edge. Use the algorithm for TSP to find a tour of distance N. The tour corresponds precisely to the Hamiltonian cycle. 26" }, { "page_index": 783, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_027.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_027.png", "page_index": 783, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:57:20+07:00" }, "raw_text": "BK 7.2. NP-completeness TP.HCM That is HCP reduces to TSP, so the NP-completeness of HCP implies the NP-completeness of TSP. The reduction of HCP to TSP is relatively simple because the problems are so similar. Actually, polynomial reductions can be quite complicated and can connect problems which seem to be quite dissimilar. Similarly, it is possible to reduce the circuit satisfiability problem to HCP. 27" }, { "page_index": 784, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_028.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_028.png", "page_index": 784, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:57:25+07:00" }, "raw_text": "BK 7.2. NP-completeness TP.HCM \"I can't find an efficient algorithm, but neither can all these famous people.' M. Garey and D.S. Johnson. Computers and Intractability: A Guide to the Theory of NP-Comp/eteness. W.H. Freemand and Company, San Francisco, CA, 1979, pp.3. 28" }, { "page_index": 785, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_029.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_029.png", "page_index": 785, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:57:29+07:00" }, "raw_text": "BK 7.2. NP-completeness TP.HCM Your turn : 7.2.1. What is a NP-complete problem? Give an 0 example. 7.2.2. List 3 reasons for a need to comprehend Np- 0 completeness. Give an example for each reason. 7.2.3. The additional property of NP-complete problems is: \"If any of these problems can be solved in polynomial time on a deterministic machine, then so can all problems in NP.\" Which is implied from this property? Why? Z.2.3.1. P = NP 7.2.3.2. P C NP 7.2.3.3. P D NP Z.2.3.4. NP does not exist 29" }, { "page_index": 786, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_030.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_030.png", "page_index": 786, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:57:33+07:00" }, "raw_text": "BK 7.2. NP-completeness TP.HCM Your turn: 7.2.3. Given the Hamiltonian cyc/e problem is 0 NP-complete, prove that the /ongest path problem is also NP-complete. The Hamiltonian cyc/e problem : determine whether a given graph G=(V, E) has a Hamiltonian cycle. The /ongest path problem: determine whether a given graph G=(V, E) has a simple path of length greater than or equal to K where K is a positive integer such that K Vl 30" }, { "page_index": 787, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_031.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_031.png", "page_index": 787, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:57:38+07:00" }, "raw_text": "BK 7.2. NP-completeness TP.HCM Your turn : 7.2.4. Given the vertex cover problem is NP-complete 0 prove that the set cover problem is also NP-complete. The vertex cover problem: for a given graph G = (V, E) and a positive integer m Vl, determine whether there is a vertex cover of size m or less for G. (A vertex cover of size k for a graph G = (V,E) is a subset V c V such that IV'l = k and, for each edge (u, v) e E, at least one of u and v belongs to V.) The set cover problem: given a finite set X and a family F of subsets of X, such that every element of X belongs to at least one subset in F: X = u S and a positive integer m IFI : SeF determine whether there is a subset C c F whose members and lCl < m. SeC 31" }, { "page_index": 788, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_032.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_032.png", "page_index": 788, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:57:43+07:00" }, "raw_text": "BK 7.2. NP-completeness TP.HCM Your turn : 7.2.5. Given the clique problem is NP-complete, prove that the vertex cover problem is also NP-complete. The clique problem: for a given graph G = (V, E) and a positive integer m Vl, determine whether G contains a clique of size m or more. (A clique of size k in a graph is its complete subgraph of k vertices.) The vertex cover problem: for a given graph G = (V, E) and a positive integer m Vl, determine whether there is a vertex cover of size m or Iess for G. (A vertex cover of size k for a graph G = (V, E) is a subset V' ε V such that IV'l = k and, for each edge (u, v) e E, at least one of u and v belongs to V'.) 32" }, { "page_index": 789, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_033.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_033.png", "page_index": 789, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:57:47+07:00" }, "raw_text": "BK 7.3. Cook's theorem TP.HCM But: How was the.first problem proven to be NP-complete? The satisfiability problem (SAT) is to determine whether a formula is true for some assignment of truth values to the variables. CSP = 3-CNF SAT S.A. Cook (1971) gave a direct proof that SAT problem is NP-complete If there is a polynomial time algorithm for the satisfiability problem, then all problems in NP can be solved in polynomial time. The proof is extremely complicated. It is based on a general-purpose computer known as a Turing machine. 33" }, { "page_index": 790, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_034.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_034.png", "page_index": 790, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:57:51+07:00" }, "raw_text": "BK 7.4. The halting problem TP.HCM The ha/ting problem a specific problem that is a/gorithmical/y unsolvable an undecidab/e problem given by the English logician and computer science pioneer Alan Turing (1912-1954) in 1936 Defined : \"Given a computer program and an input to it, determine whether the program will ha/t on that input or continue working indefinitely on it.\" 34" }, { "page_index": 791, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_035.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_035.png", "page_index": 791, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:57:55+07:00" }, "raw_text": "BK 7.4. The halting problem TP.HCM A proof that there is no algorithm for the halting problem is made by contradiction. Assume that A is an a/gorithm that so/ves the halting problem. That is, for any program P and input I, if program P halts on I; We can consider program P as an input to itself and use the output of algorithm A for pair (P, P) to construct a program Q as follows: (halts, if A(P,P) = 0, i.e.,program P does not halt on input P; Q(P)=3 (does not halt, if A(P, P) = 1, i. e.,program P halts on input P 35" }, { "page_index": 792, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_036.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_036.png", "page_index": 792, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:57:59+07:00" }, "raw_text": "BK 7.4. The halting problem TP.HCM A proof that there is no algorithm for the halting problem is made by contradiction. Then on substituting Q for P, we obtain (halts, if A(Q,Q) = 0,i. e.,program Q does not halt on input Q Q(Q) = (does not halt, if A(Q,Q) = 1, i. e.,program Q halts on input Q This is a contradiction because neither of the two outcomes for program Q is possible. >Algorithm A does not solve the halting problem. > The halting problem is unso/vable. 36" }, { "page_index": 793, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_037.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_037.png", "page_index": 793, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:58:03+07:00" }, "raw_text": "BK 7.4. The halting problem TP.HCM The halting problem \"Given a computer program and an input to it, determine whether the program will halt on that input or continue working indefinitely on it.\" The proof of the undecidability of the halting problem uses the diagonalization discovered by the German mathematician Georg Cantor in 1873. M. Sipser. Introduction to the theory of computation. 2nd Edition. Thomson Course Technology, 2006, pp. 173-181. 37" }, { "page_index": 794, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_038.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_038.png", "page_index": 794, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:58:07+07:00" }, "raw_text": "7.5. Some NP-complete BK TP.HCM problems Thousands of diverse problems are known to be NP- complete. Of course, the list begins with the satisfiability problem and includes TSP, the Hamiltonian cycle problem, as well as the longest-path problem. The following additional problems are representative - Partition: Given a set of integers, can they be divided into two sets whose sums are equal? - Integer linear programming: Given a linear problem, is there a solution in integers? 38" }, { "page_index": 795, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_039.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_039.png", "page_index": 795, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:58:11+07:00" }, "raw_text": "7.5. Some NP-complete BK TP.HCM problems - Multiprocessor scheduling: Given a deadline and a set of tasks of varying length to be performed on two identical processors, can the tasks be arranged so that the deadline is met? - Vertex cover: Given a graph and an integer N, is there a set of fewer than N vertices which touch all the edges? - Bin packing: We are given n objects which have to be placed in bins of equal capacity L. Object i requires l; units of bin capacity. The objective is to determine the minimum number of bins needed to accommodate all n objects. 39" }, { "page_index": 796, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_040.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_040.png", "page_index": 796, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:58:15+07:00" }, "raw_text": "7.5. Some NP-complete BK TP.HCM problems SAT 3 CNF-SAT CLIQUE SUBSET-SUM VERTEX-COVER KNAPSACK HAMILTONIAN SET-COVER TRAVELING-SALESMAN LONGEST-PATH Relationship between some problems for polynomial reduction 40" }, { "page_index": 797, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_041.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_041.png", "page_index": 797, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:58:19+07:00" }, "raw_text": "7.5. Some NP-complete BK TP.HCM problems P NP ? These and many related problems have important natural practical applications. The fact that no good algorithm has been found for any of these problems is surely strong evident that P + NP. Whether or not P= NP, the practical fact is that we have at present no algorithms guaranteed to solve any of the NP-complete problems efficiently 41" }, { "page_index": 798, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_042.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_042.png", "page_index": 798, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:58:23+07:00" }, "raw_text": "7.6. Some approaches to BK TP.HCM with NP-complete cope problems Use an approximation algorithm that is not the best solution but a near-optimal solution. Based on \"average-time\" performance, develop an algorithm that finds the solution in some cases, but does not necessarily work in all cases. Use with \"efficient\" exponential algorithms, for example, backtracking or branch-and-bound algorithms. Invent heuristics and add it to the algorithm to improve the performance of the algorithm. Apply metaheuristics. 42" }, { "page_index": 799, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_043.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_043.png", "page_index": 799, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:58:27+07:00" }, "raw_text": "7.6. Some approaches to BK TP.HCM with NP-complete cope problems Heuristics: knowledge in a specific problem that can be used to guide the search process in finding a solution of an algorithm. Thanks to heuristics, the algorithm becomes more efficient. Metaheuristics: a kind of more general heuristics which can be used for solving several kinds of problems. Recently, metaheuristics is an active research field with the introduction of many popular metaheuristics, such as: - genetic algorithm - simulated annealing Tabu search - etc. 43" }, { "page_index": 800, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_044.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_044.png", "page_index": 800, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:58:31+07:00" }, "raw_text": "7.6. Some approaches to BK TP.HCM with NP-complete cope problems There are several NP-complete problems in some following fields: numerical analysis geometry modeling graph processing image processing data mining The most important practical contribution of the theory of NP-completeness is that: NP-completeness provides a mechanism to discover a new problem from any of many diverse areas is \"easy\" or \"hard\" 44" }, { "page_index": 801, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_045.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_045.png", "page_index": 801, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:58:35+07:00" }, "raw_text": "7.6. Some approaches to BK TP.HCM with NP-complete problems cope Undecidab/e problems The halting problem Intractable problems Generating all the permutations of n elements NP-comp/ete problems Traveling salesman problem Hamiltonian cycle problem P problems String matching on text T and pattern P Sorting n elements 45" }, { "page_index": 802, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_046.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_046.png", "page_index": 802, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:58:39+07:00" }, "raw_text": "BK Your turn 7.3-7.6 TP.HCM on (1): What is the first proven NP-complete problem? (2). What is implied from the Cook's theorem? (3). Which statement is correct about the halting problem? (3.1). There is no efficient algorithm for the halting problem. (3.2). There is no algorithm for the halting problem in polynomial time. (3.3). There is no algorithm for the halting problem (3.4). There is no determistic algorithm for the halting problem. 46" }, { "page_index": 803, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_047.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_047.png", "page_index": 803, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:58:43+07:00" }, "raw_text": "BK Your turn 7.3-7.6 TP.HCM on (4). State ten NP-complete problems. (5). List three approaches dealing with NP- complete problems. For each listed approach, present one algorithm example for a particular NP-complete problem. (6): A branch-and-bound deterministic algorithm is designed for the traveling salesman problem. What is assumed about the problem when this algorithm is used in practice? 47" }, { "page_index": 804, "chapter_num": 7, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_048.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_7/slide_048.png", "page_index": 804, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:58:48+07:00" }, "raw_text": "Algorithms Analysis and Design BK TP.HCM (C03031) lon Chapter 7. NP-completeness gues questior questi answer question quest 7.1. Deterministic and Nondeterministic ruestion question Polynomial-time algorithms 7.2. NP-completeness 7.3. Cook's theorem 7.4. The halting problem 7.5. Some NP-complete problems 7.6. Some approaches to cope with NP-complete problems 48" }, { "page_index": 805, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_001.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_001.png", "page_index": 805, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:58:51+07:00" }, "raw_text": "Ho Chi Minh City University of Technology BK Faculty of Computer Science and Engineering TP.HCM Chapter 8: Approximation 1 Algorithms Algorithms Analysis Design and (C03031) Instructor: Assoc. Prof. Dr. Vo Thi Ngoc Chau Email: chauvtn@hcmut.edu.vn Semester 2 - 2022-2023" }, { "page_index": 806, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_002.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_002.png", "page_index": 806, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:58:55+07:00" }, "raw_text": "BK Course Learning Outcomes TP.HCM 1. Able to analyze the complexity of the algorithms (recursive or iterative) and estimate the efficiency of the algorithms. 2. Improve the ability to design algorithms in different areas by decomposing a computing problem into advanced algorithm design strategies. 3. Able to discuss Np-completeness. 2" }, { "page_index": 807, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_003.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_003.png", "page_index": 807, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:58:58+07:00" }, "raw_text": "BK References TP.HCM [1] Cormen, T. H., Leiserson, C. E, and Rivest, R. L. Introduction to Algorithms, The MiT Press, 2009. [2] Levitin, A., Introduction to the Design and Analysis of Algorithms, 3rd Edition, Pearson, 2012 [3] Sedgewick, R., A/gorithms in C++, Addison-Wesley. 1998. [4] Weiss, M.A., Data Structures and Algorithm Analysis in C, TheBenjamin/Cummings Publishing, 1993. 3" }, { "page_index": 808, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_004.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_004.png", "page_index": 808, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:59:03+07:00" }, "raw_text": "BK Course Oytline TP.HCM Chapter 1. Fundamentals 0 1 Chapter 2. Divide-and-Conquer Strategy Chapter r 3. Decrease-and-Conquer Strategy 0 1 Chapter 4. Transform-and-Conquer Strategy 0 Chapter 5. Dynamic Programming and Greedy Strategies Chapter 6. Backtracking and Branch-and-Bound Chapter 7. NP-completeness 0 1 Chapter 8. Approximation Algorithms 4" }, { "page_index": 809, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_005.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_005.png", "page_index": 809, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:59:07+07:00" }, "raw_text": "Chapter 8. BK Approximation Algorithms TP.HCM 8.1. Why approximation algorithms? 8.2. Vertex Cover problem 8.3. Set Cover problem 0 8.4. Traveling Salesman problem 8.5. Scheduling Independent tasks 0 8.6. Bin Packing problem 5" }, { "page_index": 810, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_006.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_006.png", "page_index": 810, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:59:11+07:00" }, "raw_text": "8.1.Why BK TP.HCM approximation algorithms? Many problems of practical significance are Np- complete but are too important to abandon merely because obtaining an optimal solution is intractable. If a problem is NP-complete, we are unlikely to find a polynomial time algorithm for solving it exactly, but it may still be possible to find near- optimal solution in polynomial time. In practice, near-optimality is often good enough. An algorithm that returns near-optimal solutions is called an approximation algorithm. 6" }, { "page_index": 811, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_007.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_007.png", "page_index": 811, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:59:15+07:00" }, "raw_text": "8.1.Why BK TP.HCM approximation algorithms? Performance bounds for an approximation algorithm i is an instance of an optimization problem. c(i) is the cost of a solution produced by the approximation algorithm and c*(i) is the cost of an optimal solution. For a minimization problem, a performance bound is defined as: c(i)/c*(i). For a maximization problem, a performance bound is defined as: c*(i)/c(i). A performance bound for an approximation algorithm is expected to be as small as possible. ," }, { "page_index": 812, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_008.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_008.png", "page_index": 812, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:59:20+07:00" }, "raw_text": "8.1.Why BK TP.HCM approximation algorithms? algorithm An approximation algorithm for the given optimization problem instance i, has a ratio bound of p(n) if for any input of size n, the cost c of the solution produced by the approximation algorithm is within a factor öf p(n) 'of the cost c* of an optimal solution. That is: max(c(i)/c*(i), c*(i)/c(i)) < p(n) Note that p(n) is always greater than or equal to 1. If p(n) = 1 then the approximation algorithm is an optimal algorithm. The larger p(n), the worse algorithm. 8" }, { "page_index": 813, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_009.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_009.png", "page_index": 813, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:59:23+07:00" }, "raw_text": "8.1.Why BK TP.HCM approximation algorithms? Relative error We define the relative error of an approximation algorithm for any input size as Ic(i) - c*(i)1/ c*(i) We say that an approximation algorithm has a relative error bound of a(n) if Ic(i)-c*(i)I/c*(i) < e(n) Note that a(n) is always greater than or equal to 0. If a(n) = 0 then the approximation algorithm is an optimal algorithm. The Iarger a(n), the worse algorithm. 9" }, { "page_index": 814, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_010.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_010.png", "page_index": 814, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:59:27+07:00" }, "raw_text": "BK 8.2.Vertex Cover problem TP.HCM Vertex cover: given an undirected graph G=(V,E), a vertex cover is a subset V'cV such that if (u,v)eE, then ueV' or v eV' (or both) - Size of a vertex cover: the number of vertices in it. The vertex cover problem: find a vertex cover of a minimum size. This problem is NP-hard since the related decision problem is NP-complete. 10" }, { "page_index": 815, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_011.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_011.png", "page_index": 815, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:59:31+07:00" }, "raw_text": "BK 8.2. Vertex Cover problem TP.HCM Approximation algorithm for the vertex cover problem with time complexity of O(E) APPROX-VERTEX-COVER(G) 1 C 0 2 E'lCl= 2A C={b, c, e,f, d, g} A lCl < 2C*I >lC7C*l< 2 14" }, { "page_index": 819, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_015.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_015.png", "page_index": 819, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:59:48+07:00" }, "raw_text": "BK 8.2. Vertex Cover problem TP.HCM Your turn: Given the following graphs, find their vertex covers with the approximation algorithm. How different are they from the optimal covers? 8.2.1. 8.2.2. e d a b 9 g h 15" }, { "page_index": 820, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_016.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_016.png", "page_index": 820, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:59:52+07:00" }, "raw_text": "BK 8.2.Vertex Cover problem TP.HCM Your turn: 8.2.3. Design and analyze another 0 approximation algorithm for the vertex cover problem. Hint: you might think of heuristics by considering vertex instead of edge. 8.2.4. Trace-by-hand your algorithm in 8.2.3 0 for the graphs given in 8.2.1 and 8.2.2. Are 16" }, { "page_index": 821, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_017.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_017.png", "page_index": 821, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T17:59:57+07:00" }, "raw_text": "BK 8.3. Set Cover problem TP.HCM The set cover problem is an optimization problem that models many resource-selection problems. An instance (X, F) of the set-cover problem consists of a finite set X and a family F of subsets of X, such that every element of X belongs to at Ieast one subset in F: X = U S SeF We say that a subset SeF covers its elements. The problem is to find a minimum-size subset C c F whose members cover all of X: X = U s SeC o We say that any C satisfying the above equation X. covers 17" }, { "page_index": 822, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_018.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_018.png", "page_index": 822, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:00:02+07:00" }, "raw_text": "BK 8.3. Set Cover problem TP.HCM A greedy approximation algorithm for the set cover problem Easily be implemented with polynomial time in lX] and [Fl Since the number of iterations of the loop on lines 3-6 is at most min(Xl IFD) and the loop body can be implemented to run in time O(xl:FD, there is an implementation that runs in time OXlFD*minXVFD Greedy-Set-Cover(X, F) 1. U =X 2.C = 0 3.whiIe U l= O do 4. select an SeF that maximizes l S n Ul 5. U = U - S 6. C = C U{S} 7. return C 18" }, { "page_index": 823, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_019.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_019.png", "page_index": 823, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:00:07+07:00" }, "raw_text": "BK 8.3. Set Cover problem TP.HCM Given an instance K{X, F} of the set cover 0 problem, where X consists of the 12 black points and F ={ S1, Sz, S3, S4, S5 S6}. The greedy algorithm produces the final set C = 0 {S1, S4, S5, S3} in order. S1 ={x1,x2,x3,x4,x5,x6} S1 Sz={x5,x6,x8,x9} S3={x1,x4,x7,x10} S2 S4={x2,x5,x7,x8,x11} S4 S5 ={x3,x6,x9,x12} S3 S5 S6 S6={x10,x11} 19" }, { "page_index": 824, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_020.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_020.png", "page_index": 824, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:00:12+07:00" }, "raw_text": "BK 8.3. Set Cover problem TP.HCM Given an instance K{X, F} of the set cover 0 problem, where X consists of the 12 black points and F ={ S1, Sz, S3, S4, S5r S6}. A minimum size set cover is C* = { S3, S4, S5}. The greedy algorithm produces the final set C = 0 {S1, S4, S5, S} in order. U = X S1 ={x1,x2,x3,x4,x5,x6} Pick S1: U = {x7,X8r Xgr X10 X11, X12} Sz={x5,x6,x8,x9} C ={S1} Pick S4: U = {Xg, X10, X12} S3={x1,x4,x7,x10} C = {S1, S4} S4={x2,x5,x7,x8,x11} Pick S5: U = {x1o} S5 ={x3,x6,x9,x12} C = {S1, S4, S5} Pick S3: U = O S6={x10,x11} C = {S1, S4, S5,S3} 20" }, { "page_index": 825, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_021.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_021.png", "page_index": 825, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:00:16+07:00" }, "raw_text": "BK 8.3. Set Cover problem TP.HCM Ratio bound of the greedy set-cover algorithm Theorem: c Greedy-set-cover has a ratio bound H(max{lS1: S eF}). The dth harmonic number d Hd = 2i=11/i Corollary (He qua): Greedy-set-cover has a ratio bound of (ln[X] +1). > Proof is available in: T.H. Cormen, C.E. Leiserson, R.L. Rivest, and C. Stein. Introduction to A/gorithms. 3rd Edition. The MIT Press, 2009, pp. 1119-1121. 21" }, { "page_index": 826, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_022.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_022.png", "page_index": 826, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:00:20+07:00" }, "raw_text": "BK 8.3. Set Cover problem TP.HCM Applications Assume that X is a set of skills that are needed to solve a problem and we have a set of people available to work on it. We wish to form a team, containing as few people as possible, such that for every requisite skill in X, there is a member in the team having that skill. Assign emergency stations (fire stations) in a city . Allocate sale branch offices for a company. Schedule for bus drivers. 22" }, { "page_index": 827, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_023.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_023.png", "page_index": 827, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:00:24+07:00" }, "raw_text": "BK 8.3. Set Cover problem TP.HCM Your turn: 8.3.1. Assign fire stations in a city by solving its corresponding set cover problem. Compare it with the optimal solution: assign fire stations at 3, 8, 9. 1 8 10 6 3 9 11 2 5 The map of a city 23" }, { "page_index": 828, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_024.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_024.png", "page_index": 828, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:00:28+07:00" }, "raw_text": "BK 8.3. Set Cover problem TP.HCM Your turn : 8.3.2. Given an instance e KX, F} of the set 0 cover problem, where X consists of the 11 S4, S5, S6, S7, S8, S9,S10, S11}.Apply the approximation algorithm to solve the above instance. S1 = {x1,X3,X4} S7 = {Xz, X4,X6, X7, X8} S2 = {x1,Xz,X4, X5} S8 ={X5, X6, X7, X8, Xg, X11} S3 = {X1,X3, X4, X5, X6} S9 ={X5, X8r X10, X11} S4 = {X1, X3, X4, X6, X7} S10 = {X4, X8, Xg, X10, X11} S5 ={Xz, X3, X5, X81 Xg} S11 = {xg, X10, X11} S6 = {X1, X3, X5, X6, X7, X8} 24" }, { "page_index": 829, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_025.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_025.png", "page_index": 829, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:00:32+07:00" }, "raw_text": "BK 8.3. Set Cover problem TP.HCM Your turn : 8.3.3. Given an instance e KX,F} of the set 0 cover problem, where X consists of the 7 elements X = {a, b, c, d, e, f, g} and F K{ S1, S2, S3, S4, S5, S6, S7}.Apply the approximation algorithm to solve the above instance. S1 = {a,b,f,g} S5 = {f, g} S2 ={a,b, g} S6 ={d,f} S3 = {a, b, c} S7 = {d} S4 = {e,f,g} 25" }, { "page_index": 830, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_026.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_026.png", "page_index": 830, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:00:37+07:00" }, "raw_text": "8.4.Traveling Salesman BK TP.HCM problem Since finding the shortest tour for TSP requires so that is almost as short as the shortest. That is, it may be possible to find near-optimal solution. For example: We can use an approximation 0 algorithm for HCP. It's relatively easy to find a tour that is longer by at most a factor of two than the optimal tour. The method is based on: the algorithm for finding the minimum spanning tree an observation that it is always the cheapest to go directly from vertex u to vertex w; going by way of any intermediate vertex v can't be less expensive. C(u,w) < C(u,v)+ C(v,w) 26" }, { "page_index": 831, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_027.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_027.png", "page_index": 831, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:00:42+07:00" }, "raw_text": "8.4. Traveling Salesman BK TP.HCM problem APPROX-TSP-TOUR computes a near-optimal tour of an undirected graph G. A preorder tree walk recursively visits every vertex in the tree listing a vertex when it's first encountered, before any of its children is visited. procedure APPROX-TSP-TOUR(G, c); begin select a vertex r e V[G] to be the \"root\" vertex; using Prim's algorithm: MST-PRIM(G, c, r); apply a preorder tree walk of T and let L be the list of'vértices visited in the walk; form the resulting Hamiltonian cycle H that visits the vertices in the order of L; end 27" }, { "page_index": 832, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_028.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_028.png", "page_index": 832, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:00:47+07:00" }, "raw_text": "8.4. Traveling Salesman BK TP.HCM problem procedure MST-PRIM l (G, W,r) G = (V, E) is a weighted graph with the weight function /* w, and r is an arbitrary root vertex, p[v] is a parent vertex of v. */ begin Prim's Q := V[G]; /*Q is a priority queue (min-heap)*/ for each u e Q do key[u] := o; algorithm key[r] := 0; p[r] := NIL; for a whiIe Q is not empty do begin minimum u := EXTRACT-MIN(Q); for each v e Q and w(u, v) < key[v] then spanning * update the key field of vertex v */ tree begin p[v] := u; key[v] := w(u, v end end end; 28" }, { "page_index": 833, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_029.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_029.png", "page_index": 833, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:00:50+07:00" }, "raw_text": "8.4.Traveling Salesman BK TP.HCM problem An example for the traveling salesman problem solved with APPROX-TSP-TOUR g 29" }, { "page_index": 834, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_030.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_030.png", "page_index": 834, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:00:57+07:00" }, "raw_text": "8.4. Traveling Salesman BK TP.HCM problem An example for the traveling salesman problem solved with APPROX-TSP-TOUR a b c d e f 9 h 0 0,nil 00 00 0 1 1 2,a [V10,a 2,a [V10,a V8,aV20,aV17,a 2 V2,b 2,a [V10,a 2,b 4,b 5,b 3 2,a V10,a 5,b 2,b 4,b 1 g 4 V2,d 2,b v8,d 5,b 5 V2,eV2,eV5,b 6 V2,eV5,b V5,b T 2,aV2,b2,aV2,dV2,eV2,eV5,b 0,nil Minimum Spanning Tree Finding with Prim's Algorithm 30" }, { "page_index": 835, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_031.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_031.png", "page_index": 835, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:01:05+07:00" }, "raw_text": "8.4. Traveling Salesman BK TP.HCM problem An example for the traveling salesman problem solved with APPROX-TSP-TOUR a b c d e f 9 h 0 0,nil 00 00 8 1 1 2,a [V10,a a 2,a [V10,a V8,a[V20,aV17,a 2 V2,b 2,a [V10,a 2,b 4,b 5,b 3 2,a V10,a 5,b 2,b 4,b h g 4 V2,d 2,b v8,d 5,b 5 V2,eV2,eV5,b 6 V2,eV5,b V5,b T 2,aV2,b2,aV2,dV2,eV2,eV5,b 0,nil Minimum Spanning Tree Finding with Prim's Algorithm 31" }, { "page_index": 836, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_032.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_032.png", "page_index": 836, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:01:09+07:00" }, "raw_text": "8.4.Traveling Salesman BK TP.HCM problem An example for the traveling salesman problem solved with APPROX-TSP-TOUR g The preorder tree walk is not simple tour, since a node has been visited many times, but it can be fixed, the tree walk visits the vertices in the order a, b, c, b, h, b, a, d, e, f, e, g, e, d, a. From this order, we can arrive to the Hamiltonian cycle H: a, b, c, h, d, e ,f, g, a. 32" }, { "page_index": 837, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_033.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_033.png", "page_index": 837, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:01:13+07:00" }, "raw_text": "8.4. Traveling Salesman BK TP.HCM problem g g The tree walk: a, b, c, b, h, b, a, d, e, f, e, g, e, d, a. The Hamiltonian cycle H: a, b, c, h, d, e ,f, g, a. Triangle inequality: c->h < c->b + b->h h->d < h->b + b->d < h->b + b->a + a->d f->g < f->e+ e->g g->a < g->e + e->a < g->e + e->d + d->a 33" }, { "page_index": 838, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_034.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_034.png", "page_index": 838, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:01:18+07:00" }, "raw_text": "8.4. Traveling Salesman BK TP.HCM problem An example for the traveling salesman problem solved with APPROX-TSP-TOUR The optimal tour: a,b,c,h,f,g,e,d,a Cost(H*) = 2 + V2 + V5 + V5 + 2 + v2+ v2+ 2 14.71477 g The total cost of H is approximately 19.074.An optimal tour H* has the total h cost of approximately 14.715. The running time of APPROX-TSP-TOUR is O(IVl2) with the main contribution of the running time of MST-PRIM. 34" }, { "page_index": 839, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_035.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_035.png", "page_index": 839, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:01:22+07:00" }, "raw_text": "8.4. Traveling Salesman BK TP.HCM problem Ratio bound of APPROX-TSP-TOUR Theorem: APPROX-TSP-TOUR is an approximation algorithm with a ratio bound of 2 for the TSP with triangle inequality. Proof: Let H* be an optimal tour for a given set of vertices. Since we obtain a spanning tree by deleting any edge from a tour, if T is a minimum spanning tree for the given set of vertices, then : c(T) < c(H*) (1) A full walk W of T traverses every edge of T twice, we have: c(W) = 2c(T) (2) (1) and (2) imply that: c(W) < 2c(H*) (3) 35" }, { "page_index": 840, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_036.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_036.png", "page_index": 840, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:01:27+07:00" }, "raw_text": "8.4. Traveling Salesman BK TP.HCM problem n Ratio bound of APPROX-TSP-TOUR But W is not a tour since it visits some vertices more than once. By the triangle inequality, we can delete a visit to any vertex from W. By repeatedly applying this operation, we can remove from w all but the first visit to each vertex. Let H be the cycle corresponding to this preorder walk. It is a Hamiltonian cycle, since every vertex is visited exactly once. Since H is obtained by deleting vertices from W, we have: c(H) c(W (4) From (3) and (4), we conclude: c(H) 2c(H*). So, APPROX-TSP-TOUR returns a tour whose cost is not more than twice the cost of an optimal tour. 36" }, { "page_index": 841, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_037.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_037.png", "page_index": 841, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:01:32+07:00" }, "raw_text": "8.4.Traveling Salesman BK TP.HCM problem Your turn: Given weighted complete graphs, solve the traveling salesman problem with each graph starting from vertex a by using the approximation algorithm. What is the tour? How about its found cost? 3 b 2 5 a b 3 1 2 7 8 4 5 5 9 3 e C d C 8 3 1 d 8.4.1 8.4.2 37" }, { "page_index": 842, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_038.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_038.png", "page_index": 842, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:01:37+07:00" }, "raw_text": "8.4.Traveling Salesman BK TP.HCM problem Your turn: Given weighted complete graphs, solve the traveling salesman problem with each graph starting from vertex a by using the approximation algorithm. What is the tour? How about its found cost? 3 4 b b a 4 8 7 4 12 6 3 9 8 11 2 6 9 8 6 7 5 10 d d 8.4.3 8.4.4 38" }, { "page_index": 843, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_039.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_039.png", "page_index": 843, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:01:41+07:00" }, "raw_text": "8.5. Scheduling BK TP.HCM Independent tasks An instance of the scheduling problem is defined by a set of n task times, t;, 1< i n, and m, the number of processors. Obtaining minimum finish time schedules is NP-complete. The scheduling rule we will use is called the LPT (longest processing time) rule. Definition : An LPT schedu/e is one that is the 0 result of an algorithm, which, whenever a processor becomes free, assigns to that processor a task whose time is the /argest of those tasks not yet assigned. 39" }, { "page_index": 844, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_040.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_040.png", "page_index": 844, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:01:46+07:00" }, "raw_text": "8.5. Scheduling BK TP.HCM Independent tasks Let m = 3, n = 6 and (t1, tz, t3, t4, t5, t.) (8, 7, 6, 5, 4, 3). In an LPT schedule tasks 1, 2 and 3 respectively. Tasks 1, 2, and 3 are assigned to processors 1, 2 and 3. Tasks 4, 5 and 6 are respectively assigned to the processors s 3, 2, and d 1. The finish time is 11. Since 2 t;/3 = 11, the schedule is also optimal. Finish time = 11 P1 t1 t6 P2 t2 t5 P3 t3 t4 40" }, { "page_index": 845, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_041.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_041.png", "page_index": 845, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:01:51+07:00" }, "raw_text": "8.5. Scheduling BK TP.HCM Independent tasks d (t1, tz, t3 o Let m = 3, n = 7 and t41 t5 t6 t7) (5, 5, 4, 4, 3, 3, 3). The LPT schedule is shown in the following figure. This has a finish time is 11. The optimal schedule is 9. Hence, for this instance F*(I) - F(I)/F*(I) (11-9)/9=2/9. Finish time = 11 Optimal time = 9 P1 t1 t5 t7 t1 t3 P2 t2 t6 t2 t4 t3 t4 P3 t5 t6 (a) LPT schedule (b) Optimal schedule 41" }, { "page_index": 846, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_042.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_042.png", "page_index": 846, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:01:56+07:00" }, "raw_text": "8.5. Scheduling BK TP.HCM Independent tasks schedules for some problem instances, it does not do so for all instances. How bad can LpT schedules be relative to optimal schedules? Theorem: Let F*(I) be the finish time of an optimal m processor schedule for instance I of the task scheduling problem. Let F(I) be the finish time of an LPT schedule for the same Instance, then IF*(I)-F(I)1/F*(I) 1/3 - 1/(3m) > The proof of this theorem can be referred to the book E. Horowitz and S. Sahni. Fundamentals of Computer A/gorithms. Pitman Publishing, 1978]. 42" }, { "page_index": 847, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_043.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_043.png", "page_index": 847, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:01:59+07:00" }, "raw_text": "8.5. Scheduling BK TP.HCM Independent tasks Your turn : 8.5.1. Using the longest processing time (LPT) rule, write and analyze an algorithm for scheduling n independent tasks on m processors. What is the algorithm design strategy you have used with the LPT rule? Why? 43" }, { "page_index": 848, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_044.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_044.png", "page_index": 848, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:02:02+07:00" }, "raw_text": "8.5. Scheduling BK TP.HCM Independent tasks Your turn : 8.5.2. Given the problem of scheduling independent tasks which is defined as follows : The number of processors m = 3, the set of 6 tasks with (t1, tz, t3, t4, t5, t6) (2, 5, 8,1, 5,1). Apply the LPT rule to solve the above scheduling problem. What is finish time? How different is it from the optimal one? 44" }, { "page_index": 849, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_045.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_045.png", "page_index": 849, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:02:06+07:00" }, "raw_text": "8.5. Scheduling BK TP.HCM Independent tasks Your turn : 8.5.3. Given the problem of scheduling independent tasks which is defined below : The number of processors m = 4, the t, ta, tg, t1or t11, t12 t13) = (4, 3, 6, 7, 2, 5, 8, 1,9, 5, 1,3,7). Apply the LPT rule to solve the above scheduling problem. What is finish time? How different is it from the optimal one? 45" }, { "page_index": 850, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_046.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_046.png", "page_index": 850, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:02:10+07:00" }, "raw_text": "BK 8.6.Bin Packing problem TP.HCM We are given n objects which have to be placed in bins of equal capacity L. Object i requires /, units of bin capacity. The objective is to determine the minimum number of bins needed to accommodate all n objects. 13 14, 15, 16) = (5, 6,3,7,5, 4). How many bins are needed minimally to pack these? The bin packing problem is NP-complete. 46" }, { "page_index": 851, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_047.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_047.png", "page_index": 851, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:02:13+07:00" }, "raw_text": "BK 8.6. Bin Packing problem TP.HCM One can derive many simple heuristics for the bin packing problem. In general, they will not obtain optimal packings. However, they obtain packings that use only a \"small\" fraction of bins more than an optimal packing. Four heuristics : First fit (FF) Best fit (BF) First fit Decreasing (FFD) Best fit Decreasing (BFD 47" }, { "page_index": 852, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_048.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_048.png", "page_index": 852, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:02:18+07:00" }, "raw_text": "BK 8.6. Bin Packing problem TP.HCM First-fit Index the bins 1, 2, 3,... All bins are initially filled to level 0. Objects are considered for packing in the order 1, 2, ..., n. To pack object i, find the least index j such that bin j is filled to the level r (r L - /). Pack i into bin j. Bin j is now filled to level r + lj Best-fit 0 1 The initial conditions are the same as for FF. When object i is being considered, find the least index j such that bin j is filled to a level r (r L - /) and r is as large as possible. Pack i into bin j. Bin j is now filled to level r + 1j. 48" }, { "page_index": 853, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_049.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_049.png", "page_index": 853, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:02:21+07:00" }, "raw_text": "BK 8.6.Bin Packing problem TP.HCM First-fit decreasing (FFD) Reorder the objects so that /, - /i+1, 1 i < n. Now use First-fit to pack the objects Best-fit decreasing (BFD) Now use Best-fit to pack the objects. 49" }, { "page_index": 854, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_050.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_050.png", "page_index": 854, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:02:25+07:00" }, "raw_text": "BK 8.6. Bin Packing problem TP.HCM Given L = 10, n = 6, and (l1 1z 13 14 15, 16) (5,6,3,7,5,4 6 13 (a) First Fit 12 15 (b) Best Fit 13 50" }, { "page_index": 855, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_051.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_051.png", "page_index": 855, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:02:28+07:00" }, "raw_text": "BK 8.6.Bin Packing problem TP.HCM Given L = 10,n = 6, and (l1, 1z,13 14, 15r 16) (5,6, 3,7,5,4) > ordered: (14 12, 11, 15, 16 13) 3 (c) First Fit Decreasing and Best Fit Decreasing FFD and BFD do better than either FF or BF on this instance. While FFD and BFD obtain optimal packings on this example, they do not in general obtain such packings. 51" }, { "page_index": 856, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_052.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_052.png", "page_index": 856, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:02:33+07:00" }, "raw_text": "BK 8.6.Bin Packing problem TP.HCM Theorem : Let I be an instance of the bin packing problem and let F*(I) be the minimum number of bins needed for this instance. The packing generated by either FF or BF uses no more than (17/10)F*(I)+2 bins. The packing generated by either FFD or BFD uses no more than (11/9)F*(I)+4 bins. > The proof of this theorem is long and complex, given in [D.S. Johnson. Near-optimal bin packing a/gorithms. PhD Thesis at the Massachusetts Institute of Technology, 1973]. 52" }, { "page_index": 857, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_053.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_053.png", "page_index": 857, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:02:36+07:00" }, "raw_text": "BK 8.6. Bin Packing problem TP.HCM Your turn : 8.6.1. Using four heuristics FF, BF, FFD, and BFD, write and analyze their corresponding algorithms for the bin packing problems on n objects with L for the capacity of each bin. 53" }, { "page_index": 858, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_054.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_054.png", "page_index": 858, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:02:40+07:00" }, "raw_text": "BK 8.6.Bin Packing problem TP.HCM Your turn: 8.6.2. Given the bin packing problem in which the capacity of each bin is 13, the number of objects is 8 and the capacity of each object given the array L = (7, 9, 7, 1, 6,2,4,3). a) If First Fit is used to solve the problem, what is the result? b) If the object with capacity 1 is removed, and First Fit is used, what will be the result? c) What is the result if Best Fit is used? First Fit Decreasing? Best Fit Decreasing? 54" }, { "page_index": 859, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_055.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_055.png", "page_index": 859, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:02:44+07:00" }, "raw_text": "BK 8.6. Bin Packing problem TP.HCM Your turn : 8.6.3. Given the bin packing problem in which the capacity of each bin is 1, the number of objects is 7 and the capacity of each object given the array L = (0.2, 0.6, 0.5, 0.2, 0.8, 0.3, 0.2). Show the results corresponding to the following heuristics. a) First Fit b) E Best Fit c) First Fit Decreasing d) E Best Fit Decreasing 55" }, { "page_index": 860, "chapter_num": 8, "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_056.png", "metadata": { "doc_type": "slide", "course_id": "CO3031", "source_file": "/workspace/data/converted/CO3031_Algorithms-Design_and_Analysis/Chapter_8/slide_056.png", "page_index": 860, "language": "en", "ocr_engine": "PaddleOCR 3.2", "extractor_version": "1.0.0", "timestamp": "2025-10-31T18:02:49+07:00" }, "raw_text": "Algorithms Analysis and Design BK TP.HCM (C03031) uol gues questio Chapter 8. Approximation algorithms questi answer question wuest tion sto question gues 8.1. Why approximation algorithms? 8.2. Vertex Cover problem 8.3. Set Cover problem 8.4. Traveling Salesman problem 8.5. Scheduling Independent tasks 8.6. Bin Packing problem 56" } ] }