This commit is contained in:
krahets
2025-12-31 19:38:45 +08:00
parent fdc032e300
commit f31cbc3f9f
474 changed files with 130810 additions and 103691 deletions
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+94 -94
View File
@@ -58,8 +58,8 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:300,300i,400,400i,700,700i%7CJetBrains+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Lato";--md-code-font:"JetBrains Mono"}</style>
@@ -371,7 +371,7 @@
<span class="md-ellipsis">
Before starting
Before Starting
@@ -388,7 +388,7 @@
<span class="md-nav__icon md-icon"></span>
Before starting
Before Starting
</label>
@@ -487,7 +487,7 @@
<span class="md-ellipsis">
0.1 About this book
0.1 About This Book
@@ -515,7 +515,7 @@
<span class="md-ellipsis">
0.2 How to read
0.2 How to Use This Book
@@ -604,7 +604,7 @@
<span class="md-ellipsis">
Chapter 1. Encounter with algorithms
Chapter 1. Encounter With Algorithms
@@ -626,7 +626,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 1. Encounter with algorithms
Chapter 1. Encounter With Algorithms
</label>
@@ -648,7 +648,7 @@
<span class="md-ellipsis">
1.1 Algorithms are everywhere
1.1 Algorithms Are Everywhere
@@ -676,7 +676,7 @@
<span class="md-ellipsis">
1.2 What is an algorithm
1.2 What Is an Algorithm
@@ -769,7 +769,7 @@
<span class="md-ellipsis">
Chapter 2. Complexity analysis
Chapter 2. Complexity Analysis
@@ -791,7 +791,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 2. Complexity analysis
Chapter 2. Complexity Analysis
</label>
@@ -813,7 +813,7 @@
<span class="md-ellipsis">
2.1 Algorithm efficiency assessment
2.1 Algorithm Efficiency Evaluation
@@ -841,7 +841,7 @@
<span class="md-ellipsis">
2.2 Iteration and recursion
2.2 Iteration and Recursion
@@ -869,7 +869,7 @@
<span class="md-ellipsis">
2.3 Time complexity
2.3 Time Complexity
@@ -897,7 +897,7 @@
<span class="md-ellipsis">
2.4 Space complexity
2.4 Space Complexity
@@ -990,7 +990,7 @@
<span class="md-ellipsis">
Chapter 3. Data structures
Chapter 3. Data Structures
@@ -1012,7 +1012,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 3. Data structures
Chapter 3. Data Structures
</label>
@@ -1034,7 +1034,7 @@
<span class="md-ellipsis">
3.1 Classification of data structures
3.1 Classification of Data Structures
@@ -1062,7 +1062,7 @@
<span class="md-ellipsis">
3.2 Basic data types
3.2 Basic Data Types
@@ -1090,7 +1090,7 @@
<span class="md-ellipsis">
3.3 Number encoding *
3.3 Number Encoding *
@@ -1118,7 +1118,7 @@
<span class="md-ellipsis">
3.4 Character encoding *
3.4 Character Encoding *
@@ -1211,7 +1211,7 @@
<span class="md-ellipsis">
Chapter 4. Array and linked list
Chapter 4. Array and Linked List
@@ -1233,7 +1233,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 4. Array and linked list
Chapter 4. Array and Linked List
</label>
@@ -1283,7 +1283,7 @@
<span class="md-ellipsis">
4.2 Linked list
4.2 Linked List
@@ -1339,7 +1339,7 @@
<span class="md-ellipsis">
4.4 Memory and cache *
4.4 Memory and Cache *
@@ -1430,7 +1430,7 @@
<span class="md-ellipsis">
Chapter 5. Stack and queue
Chapter 5. Stack and Queue
@@ -1452,7 +1452,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 5. Stack and queue
Chapter 5. Stack and Queue
</label>
@@ -1530,7 +1530,7 @@
<span class="md-ellipsis">
5.3 Double-ended queue
5.3 Double-Ended Queue
@@ -1621,7 +1621,7 @@
<span class="md-ellipsis">
Chapter 6. Hash table
Chapter 6. Hashing
@@ -1643,7 +1643,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 6. Hash table
Chapter 6. Hashing
</label>
@@ -1665,7 +1665,7 @@
<span class="md-ellipsis">
6.1 Hash table
6.1 Hash Table
@@ -1693,7 +1693,7 @@
<span class="md-ellipsis">
6.2 Hash collision
6.2 Hash Collision
@@ -1721,7 +1721,7 @@
<span class="md-ellipsis">
6.3 Hash algorithm
6.3 Hash Algorithm
@@ -1860,7 +1860,7 @@
<span class="md-ellipsis">
7.1 Binary tree
7.1 Binary Tree
@@ -1888,7 +1888,7 @@
<span class="md-ellipsis">
7.2 Binary tree traversal
7.2 Binary Tree Traversal
@@ -1916,7 +1916,7 @@
<span class="md-ellipsis">
7.3 Array Representation of tree
7.3 Array Representation of Tree
@@ -1944,7 +1944,7 @@
<span class="md-ellipsis">
7.4 Binary Search tree
7.4 Binary Search Tree
@@ -1972,7 +1972,7 @@
<span class="md-ellipsis">
7.5 AVL tree *
7.5 AVL Tree *
@@ -2135,7 +2135,7 @@
<span class="md-ellipsis">
8.2 Building a heap
8.2 Building a Heap
@@ -2163,7 +2163,7 @@
<span class="md-ellipsis">
8.3 Top-k problem
8.3 Top-K Problem
@@ -2326,7 +2326,7 @@
<span class="md-ellipsis">
9.2 Basic graph operations
9.2 Basic Operations on Graphs
@@ -2354,7 +2354,7 @@
<span class="md-ellipsis">
9.3 Graph traversal
9.3 Graph Traversal
@@ -2495,7 +2495,7 @@
<span class="md-ellipsis">
10.1 Binary search
10.1 Binary Search
@@ -2523,7 +2523,7 @@
<span class="md-ellipsis">
10.2 Binary search insertion
10.2 Binary Search Insertion
@@ -2551,7 +2551,7 @@
<span class="md-ellipsis">
10.3 Binary search boundaries
10.3 Binary Search Edge Cases
@@ -2579,7 +2579,7 @@
<span class="md-ellipsis">
10.4 Hashing optimization strategies
10.4 Hash Optimization Strategy
@@ -2607,7 +2607,7 @@
<span class="md-ellipsis">
10.5 Search algorithms revisited
10.5 Search Algorithms Revisited
@@ -2756,7 +2756,7 @@
<span class="md-ellipsis">
11.1 Sorting algorithms
11.1 Sorting Algorithms
@@ -2784,7 +2784,7 @@
<span class="md-ellipsis">
11.2 Selection sort
11.2 Selection Sort
@@ -2812,7 +2812,7 @@
<span class="md-ellipsis">
11.3 Bubble sort
11.3 Bubble Sort
@@ -2840,7 +2840,7 @@
<span class="md-ellipsis">
11.4 Insertion sort
11.4 Insertion Sort
@@ -2868,7 +2868,7 @@
<span class="md-ellipsis">
11.5 Quick sort
11.5 Quick Sort
@@ -2896,7 +2896,7 @@
<span class="md-ellipsis">
11.6 Merge sort
11.6 Merge Sort
@@ -2924,7 +2924,7 @@
<span class="md-ellipsis">
11.7 Heap sort
11.7 Heap Sort
@@ -2952,7 +2952,7 @@
<span class="md-ellipsis">
11.8 Bucket sort
11.8 Bucket Sort
@@ -2980,7 +2980,7 @@
<span class="md-ellipsis">
11.9 Counting sort
11.9 Counting Sort
@@ -3008,7 +3008,7 @@
<span class="md-ellipsis">
11.10 Radix sort
11.10 Radix Sort
@@ -3101,7 +3101,7 @@
<span class="md-ellipsis">
Chapter 12. Divide and conquer
Chapter 12. Divide and Conquer
@@ -3123,7 +3123,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 12. Divide and conquer
Chapter 12. Divide and Conquer
</label>
@@ -3145,7 +3145,7 @@
<span class="md-ellipsis">
12.1 Divide and conquer algorithms
12.1 Divide and Conquer Algorithms
@@ -3173,7 +3173,7 @@
<span class="md-ellipsis">
12.2 Divide and conquer search strategy
12.2 Divide and Conquer Search Strategy
@@ -3201,7 +3201,7 @@
<span class="md-ellipsis">
12.3 Building binary tree problem
12.3 Building a Binary Tree Problem
@@ -3229,7 +3229,7 @@
<span class="md-ellipsis">
12.4 Tower of Hanoi Problem
12.4 Hanoi Tower Problem
@@ -3366,7 +3366,7 @@
<span class="md-ellipsis">
13.1 Backtracking algorithms
13.1 Backtracking Algorithm
@@ -3394,7 +3394,7 @@
<span class="md-ellipsis">
13.2 Permutation problem
13.2 Permutations Problem
@@ -3422,7 +3422,7 @@
<span class="md-ellipsis">
13.3 Subset sum problem
13.3 Subset-Sum Problem
@@ -3450,7 +3450,7 @@
<span class="md-ellipsis">
13.4 n queens problem
13.4 N-Queens Problem
@@ -3547,7 +3547,7 @@
<span class="md-ellipsis">
Chapter 14. Dynamic programming
Chapter 14. Dynamic Programming
@@ -3569,7 +3569,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 14. Dynamic programming
Chapter 14. Dynamic Programming
</label>
@@ -3591,7 +3591,7 @@
<span class="md-ellipsis">
14.1 Introduction to dynamic programming
14.1 Introduction to Dynamic Programming
@@ -3619,7 +3619,7 @@
<span class="md-ellipsis">
14.2 Characteristics of DP problems
14.2 Characteristics of Dynamic Programming Problems
@@ -3647,7 +3647,7 @@
<span class="md-ellipsis">
14.3 DP problem-solving approach
14.3 Dynamic Programming Problem-Solving Approach
@@ -3675,7 +3675,7 @@
<span class="md-ellipsis">
14.4 0-1 Knapsack problem
14.4 0-1 Knapsack Problem
@@ -3703,7 +3703,7 @@
<span class="md-ellipsis">
14.5 Unbounded knapsack problem
14.5 Unbounded Knapsack Problem
@@ -3731,7 +3731,7 @@
<span class="md-ellipsis">
14.6 Edit distance problem
14.6 Edit Distance Problem
@@ -3868,7 +3868,7 @@
<span class="md-ellipsis">
15.1 Greedy algorithms
15.1 Greedy Algorithm
@@ -3896,7 +3896,7 @@
<span class="md-ellipsis">
15.2 Fractional knapsack problem
15.2 Fractional Knapsack Problem
@@ -3924,7 +3924,7 @@
<span class="md-ellipsis">
15.3 Maximum capacity problem
15.3 Maximum Capacity Problem
@@ -3952,7 +3952,7 @@
<span class="md-ellipsis">
15.4 Maximum product cutting problem
15.4 Maximum Product Cutting Problem
@@ -4085,7 +4085,7 @@
<span class="md-ellipsis">
16.1 Installation
16.1 Programming Environment Installation
@@ -4113,7 +4113,7 @@
<span class="md-ellipsis">
16.2 Contributing
16.2 Contributing Together
@@ -4141,7 +4141,7 @@
<span class="md-ellipsis">
16.3 Terminology
16.3 Terminology Table
@@ -4306,16 +4306,16 @@
<p><a class="glightbox" href="../assets/covers/chapter_searching.jpg" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Searching" class="cover-image" src="../assets/covers/chapter_searching.jpg" /></a></p>
<div class="admonition abstract">
<p class="admonition-title">Abstract</p>
<p>Searching is an adventure into the unknown; where we may need to traverse every corner of a mysterious space, or perhaps well quickly locate our target.</p>
<p>On this journey of discovery, each exploration may end up with an unexpected answer.</p>
<p>Searching is an adventure into the unknown, where we may need to traverse every corner of the mysterious space, or we may be able to quickly lock onto the target.</p>
<p>In this journey of discovery, each exploration may yield an unexpected answer.</p>
</div>
<h2 id="chapter-contents">Chapter contents<a class="headerlink" href="#chapter-contents" title="Permanent link">&para;</a></h2>
<ul>
<li><a href="binary_search/">10.1 &nbsp; Binary search</a></li>
<li><a href="binary_search_insertion/">10.2 &nbsp; Binary search insertion</a></li>
<li><a href="binary_search_edge/">10.3 &nbsp; Binary search boundaries</a></li>
<li><a href="replace_linear_by_hashing/">10.4 &nbsp; Hashing optimization strategies</a></li>
<li><a href="searching_algorithm_revisited/">10.5 &nbsp; Search algorithms revisited</a></li>
<li><a href="binary_search/">10.1 &nbsp; Binary Search</a></li>
<li><a href="binary_search_insertion/">10.2 &nbsp; Binary Search Insertion</a></li>
<li><a href="binary_search_edge/">10.3 &nbsp; Binary Search Edge Cases</a></li>
<li><a href="replace_linear_by_hashing/">10.4 &nbsp; Hash Optimization Strategy</a></li>
<li><a href="searching_algorithm_revisited/">10.5 &nbsp; Search Algorithms Revisited</a></li>
<li><a href="summary/">10.6 &nbsp; Summary</a></li>
</ul>
@@ -4364,7 +4364,7 @@ aria-label="Footer"
<a
href="binary_search/"
class="md-footer__link md-footer__link--next"
aria-label="Next: 10.1 Binary search"
aria-label="Next: 10.1 Binary Search"
rel="next"
>
<div class="md-footer__title">
@@ -4372,7 +4372,7 @@ aria-label="Footer"
Next
</span>
<div class="md-ellipsis">
10.1 Binary search
10.1 Binary Search
</div>
</div>
<div class="md-footer__button md-icon">
@@ -4482,13 +4482,13 @@ aria-label="Footer"
<a href="binary_search/" class="md-footer__link md-footer__link--next" aria-label="Next: 10.1 Binary search">
<a href="binary_search/" class="md-footer__link md-footer__link--next" aria-label="Next: 10.1 Binary Search">
<div class="md-footer__title">
<span class="md-footer__direction">
Next
</span>
<div class="md-ellipsis">
10.1 Binary search
10.1 Binary Search
</div>
</div>
<div class="md-footer__button md-icon">
File diff suppressed because it is too large Load Diff
@@ -37,7 +37,7 @@
<title>10.5 Search algorithms revisited - Hello Algo</title>
<title>10.5 Search Algorithms Revisited - Hello Algo</title>
@@ -58,8 +58,8 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:300,300i,400,400i,700,700i%7CJetBrains+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Lato";--md-code-font:"JetBrains Mono"}</style>
@@ -99,7 +99,7 @@
<div data-md-component="skip">
<a href="#105-search-algorithms-revisited" class="md-skip">
<a href="#105-searching-algorithms-revisited" class="md-skip">
Skip to content
</a>
@@ -154,7 +154,7 @@
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
10.5 Search algorithms revisited
10.5 Search Algorithms Revisited
</span>
</div>
@@ -371,7 +371,7 @@
<span class="md-ellipsis">
Before starting
Before Starting
@@ -388,7 +388,7 @@
<span class="md-nav__icon md-icon"></span>
Before starting
Before Starting
</label>
@@ -487,7 +487,7 @@
<span class="md-ellipsis">
0.1 About this book
0.1 About This Book
@@ -515,7 +515,7 @@
<span class="md-ellipsis">
0.2 How to read
0.2 How to Use This Book
@@ -604,7 +604,7 @@
<span class="md-ellipsis">
Chapter 1. Encounter with algorithms
Chapter 1. Encounter With Algorithms
@@ -626,7 +626,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 1. Encounter with algorithms
Chapter 1. Encounter With Algorithms
</label>
@@ -648,7 +648,7 @@
<span class="md-ellipsis">
1.1 Algorithms are everywhere
1.1 Algorithms Are Everywhere
@@ -676,7 +676,7 @@
<span class="md-ellipsis">
1.2 What is an algorithm
1.2 What Is an Algorithm
@@ -769,7 +769,7 @@
<span class="md-ellipsis">
Chapter 2. Complexity analysis
Chapter 2. Complexity Analysis
@@ -791,7 +791,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 2. Complexity analysis
Chapter 2. Complexity Analysis
</label>
@@ -813,7 +813,7 @@
<span class="md-ellipsis">
2.1 Algorithm efficiency assessment
2.1 Algorithm Efficiency Evaluation
@@ -841,7 +841,7 @@
<span class="md-ellipsis">
2.2 Iteration and recursion
2.2 Iteration and Recursion
@@ -869,7 +869,7 @@
<span class="md-ellipsis">
2.3 Time complexity
2.3 Time Complexity
@@ -897,7 +897,7 @@
<span class="md-ellipsis">
2.4 Space complexity
2.4 Space Complexity
@@ -990,7 +990,7 @@
<span class="md-ellipsis">
Chapter 3. Data structures
Chapter 3. Data Structures
@@ -1012,7 +1012,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 3. Data structures
Chapter 3. Data Structures
</label>
@@ -1034,7 +1034,7 @@
<span class="md-ellipsis">
3.1 Classification of data structures
3.1 Classification of Data Structures
@@ -1062,7 +1062,7 @@
<span class="md-ellipsis">
3.2 Basic data types
3.2 Basic Data Types
@@ -1090,7 +1090,7 @@
<span class="md-ellipsis">
3.3 Number encoding *
3.3 Number Encoding *
@@ -1118,7 +1118,7 @@
<span class="md-ellipsis">
3.4 Character encoding *
3.4 Character Encoding *
@@ -1211,7 +1211,7 @@
<span class="md-ellipsis">
Chapter 4. Array and linked list
Chapter 4. Array and Linked List
@@ -1233,7 +1233,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 4. Array and linked list
Chapter 4. Array and Linked List
</label>
@@ -1283,7 +1283,7 @@
<span class="md-ellipsis">
4.2 Linked list
4.2 Linked List
@@ -1339,7 +1339,7 @@
<span class="md-ellipsis">
4.4 Memory and cache *
4.4 Memory and Cache *
@@ -1430,7 +1430,7 @@
<span class="md-ellipsis">
Chapter 5. Stack and queue
Chapter 5. Stack and Queue
@@ -1452,7 +1452,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 5. Stack and queue
Chapter 5. Stack and Queue
</label>
@@ -1530,7 +1530,7 @@
<span class="md-ellipsis">
5.3 Double-ended queue
5.3 Double-Ended Queue
@@ -1621,7 +1621,7 @@
<span class="md-ellipsis">
Chapter 6. Hash table
Chapter 6. Hashing
@@ -1643,7 +1643,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 6. Hash table
Chapter 6. Hashing
</label>
@@ -1665,7 +1665,7 @@
<span class="md-ellipsis">
6.1 Hash table
6.1 Hash Table
@@ -1693,7 +1693,7 @@
<span class="md-ellipsis">
6.2 Hash collision
6.2 Hash Collision
@@ -1721,7 +1721,7 @@
<span class="md-ellipsis">
6.3 Hash algorithm
6.3 Hash Algorithm
@@ -1860,7 +1860,7 @@
<span class="md-ellipsis">
7.1 Binary tree
7.1 Binary Tree
@@ -1888,7 +1888,7 @@
<span class="md-ellipsis">
7.2 Binary tree traversal
7.2 Binary Tree Traversal
@@ -1916,7 +1916,7 @@
<span class="md-ellipsis">
7.3 Array Representation of tree
7.3 Array Representation of Tree
@@ -1944,7 +1944,7 @@
<span class="md-ellipsis">
7.4 Binary Search tree
7.4 Binary Search Tree
@@ -1972,7 +1972,7 @@
<span class="md-ellipsis">
7.5 AVL tree *
7.5 AVL Tree *
@@ -2135,7 +2135,7 @@
<span class="md-ellipsis">
8.2 Building a heap
8.2 Building a Heap
@@ -2163,7 +2163,7 @@
<span class="md-ellipsis">
8.3 Top-k problem
8.3 Top-K Problem
@@ -2326,7 +2326,7 @@
<span class="md-ellipsis">
9.2 Basic graph operations
9.2 Basic Operations on Graphs
@@ -2354,7 +2354,7 @@
<span class="md-ellipsis">
9.3 Graph traversal
9.3 Graph Traversal
@@ -2495,7 +2495,7 @@
<span class="md-ellipsis">
10.1 Binary search
10.1 Binary Search
@@ -2523,7 +2523,7 @@
<span class="md-ellipsis">
10.2 Binary search insertion
10.2 Binary Search Insertion
@@ -2551,7 +2551,7 @@
<span class="md-ellipsis">
10.3 Binary search boundaries
10.3 Binary Search Edge Cases
@@ -2579,7 +2579,7 @@
<span class="md-ellipsis">
10.4 Hashing optimization strategies
10.4 Hash Optimization Strategy
@@ -2616,7 +2616,7 @@
<span class="md-ellipsis">
10.5 Search algorithms revisited
10.5 Search Algorithms Revisited
@@ -2634,7 +2634,7 @@
<span class="md-ellipsis">
10.5 Search algorithms revisited
10.5 Search Algorithms Revisited
@@ -2663,7 +2663,7 @@
<a href="#1051-brute-force-search" class="md-nav__link">
<span class="md-ellipsis">
10.5.1 &nbsp; Brute-force search
10.5.1 &nbsp; Brute-Force Search
</span>
</a>
@@ -2674,7 +2674,7 @@
<a href="#1052-adaptive-search" class="md-nav__link">
<span class="md-ellipsis">
10.5.2 &nbsp; Adaptive search
10.5.2 &nbsp; Adaptive Search
</span>
</a>
@@ -2682,10 +2682,10 @@
</li>
<li class="md-nav__item">
<a href="#1053-choosing-a-search-method" class="md-nav__link">
<a href="#1053-search-method-selection" class="md-nav__link">
<span class="md-ellipsis">
10.5.3 &nbsp; Choosing a search method
10.5.3 &nbsp; Search Method Selection
</span>
</a>
@@ -2836,7 +2836,7 @@
<span class="md-ellipsis">
11.1 Sorting algorithms
11.1 Sorting Algorithms
@@ -2864,7 +2864,7 @@
<span class="md-ellipsis">
11.2 Selection sort
11.2 Selection Sort
@@ -2892,7 +2892,7 @@
<span class="md-ellipsis">
11.3 Bubble sort
11.3 Bubble Sort
@@ -2920,7 +2920,7 @@
<span class="md-ellipsis">
11.4 Insertion sort
11.4 Insertion Sort
@@ -2948,7 +2948,7 @@
<span class="md-ellipsis">
11.5 Quick sort
11.5 Quick Sort
@@ -2976,7 +2976,7 @@
<span class="md-ellipsis">
11.6 Merge sort
11.6 Merge Sort
@@ -3004,7 +3004,7 @@
<span class="md-ellipsis">
11.7 Heap sort
11.7 Heap Sort
@@ -3032,7 +3032,7 @@
<span class="md-ellipsis">
11.8 Bucket sort
11.8 Bucket Sort
@@ -3060,7 +3060,7 @@
<span class="md-ellipsis">
11.9 Counting sort
11.9 Counting Sort
@@ -3088,7 +3088,7 @@
<span class="md-ellipsis">
11.10 Radix sort
11.10 Radix Sort
@@ -3181,7 +3181,7 @@
<span class="md-ellipsis">
Chapter 12. Divide and conquer
Chapter 12. Divide and Conquer
@@ -3203,7 +3203,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 12. Divide and conquer
Chapter 12. Divide and Conquer
</label>
@@ -3225,7 +3225,7 @@
<span class="md-ellipsis">
12.1 Divide and conquer algorithms
12.1 Divide and Conquer Algorithms
@@ -3253,7 +3253,7 @@
<span class="md-ellipsis">
12.2 Divide and conquer search strategy
12.2 Divide and Conquer Search Strategy
@@ -3281,7 +3281,7 @@
<span class="md-ellipsis">
12.3 Building binary tree problem
12.3 Building a Binary Tree Problem
@@ -3309,7 +3309,7 @@
<span class="md-ellipsis">
12.4 Tower of Hanoi Problem
12.4 Hanoi Tower Problem
@@ -3446,7 +3446,7 @@
<span class="md-ellipsis">
13.1 Backtracking algorithms
13.1 Backtracking Algorithm
@@ -3474,7 +3474,7 @@
<span class="md-ellipsis">
13.2 Permutation problem
13.2 Permutations Problem
@@ -3502,7 +3502,7 @@
<span class="md-ellipsis">
13.3 Subset sum problem
13.3 Subset-Sum Problem
@@ -3530,7 +3530,7 @@
<span class="md-ellipsis">
13.4 n queens problem
13.4 N-Queens Problem
@@ -3627,7 +3627,7 @@
<span class="md-ellipsis">
Chapter 14. Dynamic programming
Chapter 14. Dynamic Programming
@@ -3649,7 +3649,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 14. Dynamic programming
Chapter 14. Dynamic Programming
</label>
@@ -3671,7 +3671,7 @@
<span class="md-ellipsis">
14.1 Introduction to dynamic programming
14.1 Introduction to Dynamic Programming
@@ -3699,7 +3699,7 @@
<span class="md-ellipsis">
14.2 Characteristics of DP problems
14.2 Characteristics of Dynamic Programming Problems
@@ -3727,7 +3727,7 @@
<span class="md-ellipsis">
14.3 DP problem-solving approach
14.3 Dynamic Programming Problem-Solving Approach
@@ -3755,7 +3755,7 @@
<span class="md-ellipsis">
14.4 0-1 Knapsack problem
14.4 0-1 Knapsack Problem
@@ -3783,7 +3783,7 @@
<span class="md-ellipsis">
14.5 Unbounded knapsack problem
14.5 Unbounded Knapsack Problem
@@ -3811,7 +3811,7 @@
<span class="md-ellipsis">
14.6 Edit distance problem
14.6 Edit Distance Problem
@@ -3948,7 +3948,7 @@
<span class="md-ellipsis">
15.1 Greedy algorithms
15.1 Greedy Algorithm
@@ -3976,7 +3976,7 @@
<span class="md-ellipsis">
15.2 Fractional knapsack problem
15.2 Fractional Knapsack Problem
@@ -4004,7 +4004,7 @@
<span class="md-ellipsis">
15.3 Maximum capacity problem
15.3 Maximum Capacity Problem
@@ -4032,7 +4032,7 @@
<span class="md-ellipsis">
15.4 Maximum product cutting problem
15.4 Maximum Product Cutting Problem
@@ -4165,7 +4165,7 @@
<span class="md-ellipsis">
16.1 Installation
16.1 Programming Environment Installation
@@ -4193,7 +4193,7 @@
<span class="md-ellipsis">
16.2 Contributing
16.2 Contributing Together
@@ -4221,7 +4221,7 @@
<span class="md-ellipsis">
16.3 Terminology
16.3 Terminology Table
@@ -4338,7 +4338,7 @@
<a href="#1051-brute-force-search" class="md-nav__link">
<span class="md-ellipsis">
10.5.1 &nbsp; Brute-force search
10.5.1 &nbsp; Brute-Force Search
</span>
</a>
@@ -4349,7 +4349,7 @@
<a href="#1052-adaptive-search" class="md-nav__link">
<span class="md-ellipsis">
10.5.2 &nbsp; Adaptive search
10.5.2 &nbsp; Adaptive Search
</span>
</a>
@@ -4357,10 +4357,10 @@
</li>
<li class="md-nav__item">
<a href="#1053-choosing-a-search-method" class="md-nav__link">
<a href="#1053-search-method-selection" class="md-nav__link">
<span class="md-ellipsis">
10.5.3 &nbsp; Choosing a search method
10.5.3 &nbsp; Search Method Selection
</span>
</a>
@@ -4404,41 +4404,41 @@
<!-- Page content -->
<h1 id="105-search-algorithms-revisited">10.5 &nbsp; Search algorithms revisited<a class="headerlink" href="#105-search-algorithms-revisited" title="Permanent link">&para;</a></h1>
<p><u>Searching algorithms (search algorithms)</u> are used to retrieve one or more elements that meet specific criteria within data structures such as arrays, linked lists, trees, or graphs.</p>
<p>Searching algorithms can be divided into the following two categories based on their approach.</p>
<h1 id="105-searching-algorithms-revisited">10.5 &nbsp; Searching Algorithms Revisited<a class="headerlink" href="#105-searching-algorithms-revisited" title="Permanent link">&para;</a></h1>
<p><u>Searching algorithms</u> are used to search for one or a group of elements that meet specific conditions in data structures (such as arrays, linked lists, trees, or graphs).</p>
<p>Searching algorithms can be divided into the following two categories based on their implementation approach:</p>
<ul>
<li><strong>Locating the target element by traversing the data structure</strong>, such as traversals of arrays, linked lists, trees, and graphs, etc.</li>
<li><strong>Using the organizational structure of the data or existing data to achieve efficient element searches</strong>, such as binary search, hash search, binary search tree search, etc.</li>
<li><strong>Locating target elements by traversing the data structure</strong>, such as traversing arrays, linked lists, trees, and graphs.</li>
<li><strong>Achieving efficient element search by utilizing data organization structure or prior information contained in the data</strong>, such as binary search, hash-based search, and binary search tree search.</li>
</ul>
<p>These topics were introduced in previous chapters, so they are not unfamiliar to us. In this section, we will revisit searching algorithms from a more systematic perspective.</p>
<h2 id="1051-brute-force-search">10.5.1 &nbsp; Brute-force search<a class="headerlink" href="#1051-brute-force-search" title="Permanent link">&para;</a></h2>
<p>A Brute-force search locates the target element by traversing every element of the data structure.</p>
<p>It's not hard to see that these topics have all been covered in previous chapters, so searching algorithms are not unfamiliar to us. In this section, we will approach from a more systematic perspective and re-examine searching algorithms.</p>
<h2 id="1051-brute-force-search">10.5.1 &nbsp; Brute-Force Search<a class="headerlink" href="#1051-brute-force-search" title="Permanent link">&para;</a></h2>
<p>Brute-force search locates target elements by traversing each element of the data structure.</p>
<ul>
<li>"Linear search" is suitable for linear data structures such as arrays and linked lists. It starts from one end of the data structure and accesses each element one by one until the target element is found or the other end is reached without finding the target element.</li>
<li>"Breadth-first search" and "Depth-first search" are two traversal strategies for graphs and trees. Breadth-first search starts from the initial node and searches layer by layer (left to right), accessing nodes from near to far. Depth-first search starts from the initial node, follows a path until the end (top to bottom), then backtracks and tries other paths until the entire data structure is traversed.</li>
<li>"Linear search" is applicable to linear data structures such as arrays and linked lists. It starts from one end of the data structure and accesses elements one by one until the target element is found or the other end is reached without finding the target element.</li>
<li>"Breadth-first search" and "depth-first search" are two traversal strategies for graphs and trees. Breadth-first search starts from the initial node and searches layer by layer, visiting nodes from near to far. Depth-first search starts from the initial node, follows a path to the end, then backtracks and tries other paths until the entire data structure is traversed.</li>
</ul>
<p>The advantage of brute-force search is its simplicity and versatility, <strong>no need for data preprocessing or the help of additional data structures</strong>.</p>
<p>However, <strong>the time complexity of this type of algorithm is <span class="arithmatex">\(O(n)\)</span></strong>, where <span class="arithmatex">\(n\)</span> is the number of elements, so the performance is poor with large data sets.</p>
<h2 id="1052-adaptive-search">10.5.2 &nbsp; Adaptive search<a class="headerlink" href="#1052-adaptive-search" title="Permanent link">&para;</a></h2>
<p>An Adaptive search uses the unique properties of data (such as order) to optimize the search process, thereby locating the target element more efficiently.</p>
<p>The advantage of brute-force search is that it is simple and has good generality, <strong>requiring no data preprocessing or additional data structures</strong>.</p>
<p>However, <strong>the time complexity of such algorithms is <span class="arithmatex">\(O(n)\)</span></strong>, where <span class="arithmatex">\(n\)</span> is the number of elements, so performance is poor when dealing with large amounts of data.</p>
<h2 id="1052-adaptive-search">10.5.2 &nbsp; Adaptive Search<a class="headerlink" href="#1052-adaptive-search" title="Permanent link">&para;</a></h2>
<p>Adaptive search utilizes the unique properties of data (such as orderliness) to optimize the search process, thereby locating target elements more efficiently.</p>
<ul>
<li>"Binary search" uses the orderliness of data to achieve efficient searching, only suitable for arrays.</li>
<li>"Hash search" uses a hash table to establish a key-value mapping between search data and target data, thus implementing the query operation.</li>
<li>"Tree search" in a specific tree structure (such as a binary search tree), quickly eliminates nodes based on node value comparisons, thus locating the target element.</li>
<li>"Binary search" uses the orderliness of data to achieve efficient searching, applicable only to arrays.</li>
<li>"Hash-based search" uses hash tables to establish key-value pair mappings between search data and target data, thereby achieving query operations.</li>
<li>"Tree search" in specific tree structures (such as binary search trees), quickly eliminates nodes based on comparing node values to locate target elements.</li>
</ul>
<p>The advantage of these algorithms is high efficiency, <strong>with time complexities reaching <span class="arithmatex">\(O(\log n)\)</span> or even <span class="arithmatex">\(O(1)\)</span></strong>.</p>
<p>However, <strong>using these algorithms often requires data preprocessing</strong>. For example, binary search requires sorting the array in advance, and hash search and tree search both require the help of additional data structures. Maintaining these structures also requires more overhead in terms of time and space.</p>
<p>The advantage of such algorithms is high efficiency, <strong>with time complexity reaching <span class="arithmatex">\(O(\log n)\)</span> or even <span class="arithmatex">\(O(1)\)</span></strong>.</p>
<p>However, <strong>using these algorithms often requires data preprocessing</strong>. For example, binary search requires pre-sorting the array, while hash-based search and tree search both require additional data structures, and maintaining these data structures also requires extra time and space overhead.</p>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>Adaptive search algorithms are often referred to as search algorithms, <strong>mainly used for quickly retrieving target elements in specific data structures</strong>.</p>
<p>Adaptive search algorithms are often called lookup algorithms, <strong>mainly used to quickly retrieve target elements in specific data structures</strong>.</p>
</div>
<h2 id="1053-choosing-a-search-method">10.5.3 &nbsp; Choosing a search method<a class="headerlink" href="#1053-choosing-a-search-method" title="Permanent link">&para;</a></h2>
<p>Given a set of data of size <span class="arithmatex">\(n\)</span>, we can use a linear search, binary search, tree search, hash search, or other methods to retrieve the target element. The working principles of these methods are shown in Figure 10-11.</p>
<p><a class="glightbox" href="../searching_algorithm_revisited.assets/searching_algorithms.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Various search strategies" class="animation-figure" src="../searching_algorithm_revisited.assets/searching_algorithms.png" /></a></p>
<p align="center"> Figure 10-11 &nbsp; Various search strategies </p>
<h2 id="1053-search-method-selection">10.5.3 &nbsp; Search Method Selection<a class="headerlink" href="#1053-search-method-selection" title="Permanent link">&para;</a></h2>
<p>Given a dataset of size <span class="arithmatex">\(n\)</span>, we can use linear search, binary search, tree search, hash-based search, and other methods to search for the target element. The working principles of each method are shown in Figure 10-11.</p>
<p><a class="glightbox" href="../searching_algorithm_revisited.assets/searching_algorithms.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Multiple search strategies" class="animation-figure" src="../searching_algorithm_revisited.assets/searching_algorithms.png" /></a></p>
<p align="center"> Figure 10-11 &nbsp; Multiple search strategies </p>
<p>The characteristics and operational efficiency of the aforementioned methods are shown in the following table.</p>
<p>The operational efficiency and characteristics of the above methods are as follows:</p>
<p align="center"> Table 10-1 &nbsp; Comparison of search algorithm efficiency </p>
<div class="center-table">
@@ -4449,7 +4449,7 @@
<th>Linear search</th>
<th>Binary search</th>
<th>Tree search</th>
<th>Hash search</th>
<th>Hash-based search</th>
</tr>
</thead>
<tbody>
@@ -4485,11 +4485,11 @@
<td>Data preprocessing</td>
<td>/</td>
<td>Sorting <span class="arithmatex">\(O(n \log n)\)</span></td>
<td>Building tree <span class="arithmatex">\(O(n \log n)\)</span></td>
<td>Building hash table <span class="arithmatex">\(O(n)\)</span></td>
<td>Tree building <span class="arithmatex">\(O(n \log n)\)</span></td>
<td>Hash table building <span class="arithmatex">\(O(n)\)</span></td>
</tr>
<tr>
<td>Data orderliness</td>
<td>Data ordered</td>
<td>Unordered</td>
<td>Ordered</td>
<td>Ordered</td>
@@ -4498,32 +4498,32 @@
</tbody>
</table>
</div>
<p>The choice of search algorithm also depends on the volume of data, search performance requirements, frequency of data queries and updates, etc.</p>
<p>The choice of search algorithm also depends on data volume, search performance requirements, data query and update frequency, etc.</p>
<p><strong>Linear search</strong></p>
<ul>
<li>Good versatility, no need for any data preprocessing operations. If we only need to query the data once, then the time for data preprocessing in the other three methods would be longer than the time for a linear search.</li>
<li>Suitable for small volumes of data, where time complexity has a smaller impact on efficiency.</li>
<li>Suitable for scenarios with very frequent data updates, because this method does not require any additional maintenance of the data.</li>
<li>Good generality, requiring no data preprocessing operations. If we only need to query the data once, the data preprocessing time for the other three methods would be longer than linear search.</li>
<li>Suitable for small data volumes, where time complexity has less impact on efficiency.</li>
<li>Suitable for scenarios with high data update frequency, as this method does not require any additional data maintenance.</li>
</ul>
<p><strong>Binary search</strong></p>
<ul>
<li>Suitable for larger data volumes, with stable performance and a worst-case time complexity of <span class="arithmatex">\(O(\log n)\)</span>.</li>
<li>However, the data volume cannot be too large, because storing arrays requires contiguous memory space.</li>
<li>Not suitable for scenarios with frequent additions and deletions, because maintaining an ordered array incurs a lot of overhead.</li>
<li>Suitable for large data volumes with stable efficiency performance, worst-case time complexity of <span class="arithmatex">\(O(\log n)\)</span>.</li>
<li>Data volume cannot be too large, as storing arrays requires contiguous memory space.</li>
<li>Not suitable for scenarios with frequent data insertion and deletion, as maintaining a sorted array has high overhead.</li>
</ul>
<p><strong>Hash search</strong></p>
<p><strong>Hash-based search</strong></p>
<ul>
<li>Suitable for scenarios where fast query performance is essential, with an average time complexity of <span class="arithmatex">\(O(1)\)</span>.</li>
<li>Not suitable for scenarios needing ordered data or range searches, because hash tables cannot maintain data orderliness.</li>
<li>High dependency on hash functions and hash collision handling strategies, with significant performance degradation risks.</li>
<li>Not suitable for overly large data volumes, because hash tables need extra space to minimize collisions and provide good query performance.</li>
<li>Suitable for scenarios with high query performance requirements, with an average time complexity of <span class="arithmatex">\(O(1)\)</span>.</li>
<li>Not suitable for scenarios requiring ordered data or range searches, as hash tables cannot maintain data orderliness.</li>
<li>High dependence on hash functions and hash collision handling strategies, with significant risk of performance degradation.</li>
<li>Not suitable for excessively large data volumes, as hash tables require extra space to minimize collisions and thus provide good query performance.</li>
</ul>
<p><strong>Tree search</strong></p>
<ul>
<li>Suitable for massive data, because tree nodes are stored scattered in memory.</li>
<li>Suitable for maintaining ordered data or range searches.</li>
<li>With the continuous addition and deletion of nodes, the binary search tree may become skewed, degrading the time complexity to <span class="arithmatex">\(O(n)\)</span>.</li>
<li>If using AVL trees or red-black trees, operations can run stably at <span class="arithmatex">\(O(\log n)\)</span> efficiency, but the operation to maintain tree balance adds extra overhead.</li>
<li>Suitable for massive data, as tree nodes are stored dispersedly in memory.</li>
<li>Suitable for scenarios requiring maintained ordered data or range searches.</li>
<li>During continuous node insertion and deletion, binary search trees may become skewed, degrading time complexity to <span class="arithmatex">\(O(n)\)</span>.</li>
<li>If using AVL trees or red-black trees, all operations can run stably at <span class="arithmatex">\(O(\log n)\)</span> efficiency, but operations to maintain tree balance add extra overhead.</li>
</ul>
<!-- Source file information -->
@@ -4547,7 +4547,7 @@ aria-label="Footer"
<a
href="../replace_linear_by_hashing/"
class="md-footer__link md-footer__link--prev"
aria-label="Previous: 10.4 Hashing optimization strategies"
aria-label="Previous: 10.4 Hash Optimization Strategy"
rel="prev"
>
<div class="md-footer__button md-icon">
@@ -4559,7 +4559,7 @@ aria-label="Footer"
Previous
</span>
<div class="md-ellipsis">
10.4 Hashing optimization strategies
10.4 Hash Optimization Strategy
</div>
</div>
</a>
@@ -4672,7 +4672,7 @@ aria-label="Footer"
<nav class="md-footer__inner md-grid" aria-label="Footer" >
<a href="../replace_linear_by_hashing/" class="md-footer__link md-footer__link--prev" aria-label="Previous: 10.4 Hashing optimization strategies">
<a href="../replace_linear_by_hashing/" class="md-footer__link md-footer__link--prev" aria-label="Previous: 10.4 Hash Optimization Strategy">
<div class="md-footer__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
@@ -4682,7 +4682,7 @@ aria-label="Footer"
Previous
</span>
<div class="md-ellipsis">
10.4 Hashing optimization strategies
10.4 Hash Optimization Strategy
</div>
</div>
</a>
+161 -93
View File
@@ -58,8 +58,8 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:300,300i,400,400i,700,700i%7CJetBrains+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Lato";--md-code-font:"JetBrains Mono"}</style>
@@ -371,7 +371,7 @@
<span class="md-ellipsis">
Before starting
Before Starting
@@ -388,7 +388,7 @@
<span class="md-nav__icon md-icon"></span>
Before starting
Before Starting
</label>
@@ -487,7 +487,7 @@
<span class="md-ellipsis">
0.1 About this book
0.1 About This Book
@@ -515,7 +515,7 @@
<span class="md-ellipsis">
0.2 How to read
0.2 How to Use This Book
@@ -604,7 +604,7 @@
<span class="md-ellipsis">
Chapter 1. Encounter with algorithms
Chapter 1. Encounter With Algorithms
@@ -626,7 +626,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 1. Encounter with algorithms
Chapter 1. Encounter With Algorithms
</label>
@@ -648,7 +648,7 @@
<span class="md-ellipsis">
1.1 Algorithms are everywhere
1.1 Algorithms Are Everywhere
@@ -676,7 +676,7 @@
<span class="md-ellipsis">
1.2 What is an algorithm
1.2 What Is an Algorithm
@@ -769,7 +769,7 @@
<span class="md-ellipsis">
Chapter 2. Complexity analysis
Chapter 2. Complexity Analysis
@@ -791,7 +791,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 2. Complexity analysis
Chapter 2. Complexity Analysis
</label>
@@ -813,7 +813,7 @@
<span class="md-ellipsis">
2.1 Algorithm efficiency assessment
2.1 Algorithm Efficiency Evaluation
@@ -841,7 +841,7 @@
<span class="md-ellipsis">
2.2 Iteration and recursion
2.2 Iteration and Recursion
@@ -869,7 +869,7 @@
<span class="md-ellipsis">
2.3 Time complexity
2.3 Time Complexity
@@ -897,7 +897,7 @@
<span class="md-ellipsis">
2.4 Space complexity
2.4 Space Complexity
@@ -990,7 +990,7 @@
<span class="md-ellipsis">
Chapter 3. Data structures
Chapter 3. Data Structures
@@ -1012,7 +1012,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 3. Data structures
Chapter 3. Data Structures
</label>
@@ -1034,7 +1034,7 @@
<span class="md-ellipsis">
3.1 Classification of data structures
3.1 Classification of Data Structures
@@ -1062,7 +1062,7 @@
<span class="md-ellipsis">
3.2 Basic data types
3.2 Basic Data Types
@@ -1090,7 +1090,7 @@
<span class="md-ellipsis">
3.3 Number encoding *
3.3 Number Encoding *
@@ -1118,7 +1118,7 @@
<span class="md-ellipsis">
3.4 Character encoding *
3.4 Character Encoding *
@@ -1211,7 +1211,7 @@
<span class="md-ellipsis">
Chapter 4. Array and linked list
Chapter 4. Array and Linked List
@@ -1233,7 +1233,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 4. Array and linked list
Chapter 4. Array and Linked List
</label>
@@ -1283,7 +1283,7 @@
<span class="md-ellipsis">
4.2 Linked list
4.2 Linked List
@@ -1339,7 +1339,7 @@
<span class="md-ellipsis">
4.4 Memory and cache *
4.4 Memory and Cache *
@@ -1430,7 +1430,7 @@
<span class="md-ellipsis">
Chapter 5. Stack and queue
Chapter 5. Stack and Queue
@@ -1452,7 +1452,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 5. Stack and queue
Chapter 5. Stack and Queue
</label>
@@ -1530,7 +1530,7 @@
<span class="md-ellipsis">
5.3 Double-ended queue
5.3 Double-Ended Queue
@@ -1621,7 +1621,7 @@
<span class="md-ellipsis">
Chapter 6. Hash table
Chapter 6. Hashing
@@ -1643,7 +1643,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 6. Hash table
Chapter 6. Hashing
</label>
@@ -1665,7 +1665,7 @@
<span class="md-ellipsis">
6.1 Hash table
6.1 Hash Table
@@ -1693,7 +1693,7 @@
<span class="md-ellipsis">
6.2 Hash collision
6.2 Hash Collision
@@ -1721,7 +1721,7 @@
<span class="md-ellipsis">
6.3 Hash algorithm
6.3 Hash Algorithm
@@ -1860,7 +1860,7 @@
<span class="md-ellipsis">
7.1 Binary tree
7.1 Binary Tree
@@ -1888,7 +1888,7 @@
<span class="md-ellipsis">
7.2 Binary tree traversal
7.2 Binary Tree Traversal
@@ -1916,7 +1916,7 @@
<span class="md-ellipsis">
7.3 Array Representation of tree
7.3 Array Representation of Tree
@@ -1944,7 +1944,7 @@
<span class="md-ellipsis">
7.4 Binary Search tree
7.4 Binary Search Tree
@@ -1972,7 +1972,7 @@
<span class="md-ellipsis">
7.5 AVL tree *
7.5 AVL Tree *
@@ -2135,7 +2135,7 @@
<span class="md-ellipsis">
8.2 Building a heap
8.2 Building a Heap
@@ -2163,7 +2163,7 @@
<span class="md-ellipsis">
8.3 Top-k problem
8.3 Top-K Problem
@@ -2326,7 +2326,7 @@
<span class="md-ellipsis">
9.2 Basic graph operations
9.2 Basic Operations on Graphs
@@ -2354,7 +2354,7 @@
<span class="md-ellipsis">
9.3 Graph traversal
9.3 Graph Traversal
@@ -2495,7 +2495,7 @@
<span class="md-ellipsis">
10.1 Binary search
10.1 Binary Search
@@ -2523,7 +2523,7 @@
<span class="md-ellipsis">
10.2 Binary search insertion
10.2 Binary Search Insertion
@@ -2551,7 +2551,7 @@
<span class="md-ellipsis">
10.3 Binary search boundaries
10.3 Binary Search Edge Cases
@@ -2579,7 +2579,7 @@
<span class="md-ellipsis">
10.4 Hashing optimization strategies
10.4 Hash Optimization Strategy
@@ -2607,7 +2607,7 @@
<span class="md-ellipsis">
10.5 Search algorithms revisited
10.5 Search Algorithms Revisited
@@ -2637,6 +2637,24 @@
<label class="md-nav__link md-nav__link--active" for="__toc">
<span class="md-ellipsis">
10.6 Summary
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
@@ -2654,6 +2672,36 @@
</a>
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#1-key-review" class="md-nav__link">
<span class="md-ellipsis">
1. &nbsp; Key Review
</span>
</a>
</li>
</ul>
</nav>
</li>
@@ -2766,7 +2814,7 @@
<span class="md-ellipsis">
11.1 Sorting algorithms
11.1 Sorting Algorithms
@@ -2794,7 +2842,7 @@
<span class="md-ellipsis">
11.2 Selection sort
11.2 Selection Sort
@@ -2822,7 +2870,7 @@
<span class="md-ellipsis">
11.3 Bubble sort
11.3 Bubble Sort
@@ -2850,7 +2898,7 @@
<span class="md-ellipsis">
11.4 Insertion sort
11.4 Insertion Sort
@@ -2878,7 +2926,7 @@
<span class="md-ellipsis">
11.5 Quick sort
11.5 Quick Sort
@@ -2906,7 +2954,7 @@
<span class="md-ellipsis">
11.6 Merge sort
11.6 Merge Sort
@@ -2934,7 +2982,7 @@
<span class="md-ellipsis">
11.7 Heap sort
11.7 Heap Sort
@@ -2962,7 +3010,7 @@
<span class="md-ellipsis">
11.8 Bucket sort
11.8 Bucket Sort
@@ -2990,7 +3038,7 @@
<span class="md-ellipsis">
11.9 Counting sort
11.9 Counting Sort
@@ -3018,7 +3066,7 @@
<span class="md-ellipsis">
11.10 Radix sort
11.10 Radix Sort
@@ -3111,7 +3159,7 @@
<span class="md-ellipsis">
Chapter 12. Divide and conquer
Chapter 12. Divide and Conquer
@@ -3133,7 +3181,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 12. Divide and conquer
Chapter 12. Divide and Conquer
</label>
@@ -3155,7 +3203,7 @@
<span class="md-ellipsis">
12.1 Divide and conquer algorithms
12.1 Divide and Conquer Algorithms
@@ -3183,7 +3231,7 @@
<span class="md-ellipsis">
12.2 Divide and conquer search strategy
12.2 Divide and Conquer Search Strategy
@@ -3211,7 +3259,7 @@
<span class="md-ellipsis">
12.3 Building binary tree problem
12.3 Building a Binary Tree Problem
@@ -3239,7 +3287,7 @@
<span class="md-ellipsis">
12.4 Tower of Hanoi Problem
12.4 Hanoi Tower Problem
@@ -3376,7 +3424,7 @@
<span class="md-ellipsis">
13.1 Backtracking algorithms
13.1 Backtracking Algorithm
@@ -3404,7 +3452,7 @@
<span class="md-ellipsis">
13.2 Permutation problem
13.2 Permutations Problem
@@ -3432,7 +3480,7 @@
<span class="md-ellipsis">
13.3 Subset sum problem
13.3 Subset-Sum Problem
@@ -3460,7 +3508,7 @@
<span class="md-ellipsis">
13.4 n queens problem
13.4 N-Queens Problem
@@ -3557,7 +3605,7 @@
<span class="md-ellipsis">
Chapter 14. Dynamic programming
Chapter 14. Dynamic Programming
@@ -3579,7 +3627,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 14. Dynamic programming
Chapter 14. Dynamic Programming
</label>
@@ -3601,7 +3649,7 @@
<span class="md-ellipsis">
14.1 Introduction to dynamic programming
14.1 Introduction to Dynamic Programming
@@ -3629,7 +3677,7 @@
<span class="md-ellipsis">
14.2 Characteristics of DP problems
14.2 Characteristics of Dynamic Programming Problems
@@ -3657,7 +3705,7 @@
<span class="md-ellipsis">
14.3 DP problem-solving approach
14.3 Dynamic Programming Problem-Solving Approach
@@ -3685,7 +3733,7 @@
<span class="md-ellipsis">
14.4 0-1 Knapsack problem
14.4 0-1 Knapsack Problem
@@ -3713,7 +3761,7 @@
<span class="md-ellipsis">
14.5 Unbounded knapsack problem
14.5 Unbounded Knapsack Problem
@@ -3741,7 +3789,7 @@
<span class="md-ellipsis">
14.6 Edit distance problem
14.6 Edit Distance Problem
@@ -3878,7 +3926,7 @@
<span class="md-ellipsis">
15.1 Greedy algorithms
15.1 Greedy Algorithm
@@ -3906,7 +3954,7 @@
<span class="md-ellipsis">
15.2 Fractional knapsack problem
15.2 Fractional Knapsack Problem
@@ -3934,7 +3982,7 @@
<span class="md-ellipsis">
15.3 Maximum capacity problem
15.3 Maximum Capacity Problem
@@ -3962,7 +4010,7 @@
<span class="md-ellipsis">
15.4 Maximum product cutting problem
15.4 Maximum Product Cutting Problem
@@ -4095,7 +4143,7 @@
<span class="md-ellipsis">
16.1 Installation
16.1 Programming Environment Installation
@@ -4123,7 +4171,7 @@
<span class="md-ellipsis">
16.2 Contributing
16.2 Contributing Together
@@ -4151,7 +4199,7 @@
<span class="md-ellipsis">
16.3 Terminology
16.3 Terminology Table
@@ -4258,6 +4306,25 @@
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#1-key-review" class="md-nav__link">
<span class="md-ellipsis">
1. &nbsp; Key Review
</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
@@ -4294,13 +4361,14 @@
<!-- Page content -->
<h1 id="106-summary">10.6 &nbsp; Summary<a class="headerlink" href="#106-summary" title="Permanent link">&para;</a></h1>
<h3 id="1-key-review">1. &nbsp; Key Review<a class="headerlink" href="#1-key-review" title="Permanent link">&para;</a></h3>
<ul>
<li>Binary search depends on the order of data and performs the search by iteratively halving the search interval. It requires the input data to be sorted and is only applicable to arrays or array-based data structures.</li>
<li>Brute force search may be required to locate an entry in an unordered dataset. Different search algorithms can be applied based on the data structure: Linear search is suitable for arrays and linked lists, while breadth-first search (BFS) and depth-first search (DFS) are suitable for graphs and trees. These algorithms are highly versatile, requiring no preprocessing of data, but they have a higher time complexity of <span class="arithmatex">\(O(n)\)</span>.</li>
<li>Hash search, tree search, and binary search are efficient search methods that can quickly locate target elements within specific data structures. These algorithms are highly efficient, with time complexities reaching <span class="arithmatex">\(O(\log n)\)</span> or even <span class="arithmatex">\(O(1)\)</span>, but they usually require extra space to accommodate additional data structures.</li>
<li>In practice, we need to analyze factors such as data volume, search performance requirements, data query and update frequencies, etc., to choose an appropriate search method.</li>
<li>Linear search is ideal for small or frequently updated (volatile) data. Binary search works well for large and sorted data. Hash search is suitable for data that requires high query efficiency and does not need range queries. Tree search is best suited for large dynamic data that require maintaining order and need to support range queries.</li>
<li>Replacing linear search with hash search is a common strategy to optimize runtime performance, reducing the time complexity from <span class="arithmatex">\(O(n)\)</span> to <span class="arithmatex">\(O(1)\)</span>.</li>
<li>Binary search relies on data orderliness and progressively reduces the search interval by half through loops. It requires input data to be sorted and is only applicable to arrays or data structures based on array implementations.</li>
<li>Brute-force search locates data by traversing the data structure. Linear search is applicable to arrays and linked lists, while breadth-first search and depth-first search are applicable to graphs and trees. Such algorithms have good generality and require no data preprocessing, but have a relatively high time complexity of <span class="arithmatex">\(O(n)\)</span>.</li>
<li>Hash-based search, tree search, and binary search are efficient search methods that can quickly locate target elements in specific data structures. Such algorithms are highly efficient with time complexity reaching <span class="arithmatex">\(O(\log n)\)</span> or even <span class="arithmatex">\(O(1)\)</span>, but typically require additional data structures.</li>
<li>In practice, we need to analyze factors such as data scale, search performance requirements, and data query and update frequency to choose the appropriate search method.</li>
<li>Linear search is suitable for small-scale or frequently updated data; binary search is suitable for large-scale, sorted data; hash-based search is suitable for data with high query efficiency requirements and no need for range queries; tree search is suitable for large-scale dynamic data that needs to maintain order and support range queries.</li>
<li>Replacing linear search with hash-based search is a commonly used strategy to optimize runtime, reducing time complexity from <span class="arithmatex">\(O(n)\)</span> to <span class="arithmatex">\(O(1)\)</span>.</li>
</ul>
<!-- Source file information -->
@@ -4324,7 +4392,7 @@ aria-label="Footer"
<a
href="../searching_algorithm_revisited/"
class="md-footer__link md-footer__link--prev"
aria-label="Previous: 10.5 Search algorithms revisited"
aria-label="Previous: 10.5 Search Algorithms Revisited"
rel="prev"
>
<div class="md-footer__button md-icon">
@@ -4336,7 +4404,7 @@ aria-label="Footer"
Previous
</span>
<div class="md-ellipsis">
10.5 Search algorithms revisited
10.5 Search Algorithms Revisited
</div>
</div>
</a>
@@ -4449,7 +4517,7 @@ aria-label="Footer"
<nav class="md-footer__inner md-grid" aria-label="Footer" >
<a href="../searching_algorithm_revisited/" class="md-footer__link md-footer__link--prev" aria-label="Previous: 10.5 Search algorithms revisited">
<a href="../searching_algorithm_revisited/" class="md-footer__link md-footer__link--prev" aria-label="Previous: 10.5 Search Algorithms Revisited">
<div class="md-footer__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
@@ -4459,7 +4527,7 @@ aria-label="Footer"
Previous
</span>
<div class="md-ellipsis">
10.5 Search algorithms revisited
10.5 Search Algorithms Revisited
</div>
</div>
</a>