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
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
@@ -1862,7 +1862,7 @@
<span class="md-ellipsis">
7.1 Binary tree
7.1 Binary Tree
@@ -1890,7 +1890,7 @@
<span class="md-ellipsis">
7.2 Binary tree traversal
7.2 Binary Tree Traversal
@@ -1918,7 +1918,7 @@
<span class="md-ellipsis">
7.3 Array Representation of tree
7.3 Array Representation of Tree
@@ -1946,7 +1946,7 @@
<span class="md-ellipsis">
7.4 Binary Search tree
7.4 Binary Search Tree
@@ -1974,7 +1974,7 @@
<span class="md-ellipsis">
7.5 AVL tree *
7.5 AVL Tree *
@@ -2137,7 +2137,7 @@
<span class="md-ellipsis">
8.2 Building a heap
8.2 Building a Heap
@@ -2165,7 +2165,7 @@
<span class="md-ellipsis">
8.3 Top-k problem
8.3 Top-K Problem
@@ -2328,7 +2328,7 @@
<span class="md-ellipsis">
9.2 Basic graph operations
9.2 Basic Operations on Graphs
@@ -2356,7 +2356,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_tree.jpg" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Tree" class="cover-image" src="../assets/covers/chapter_tree.jpg" /></a></p>
<div class="admonition abstract">
<p class="admonition-title">Abstract</p>
<p>The towering tree exudes a vibrant essence, boasting profound roots and abundant foliage, yet its branches are sparsely scattered, creating an ethereal aura.</p>
<p>It shows us the vivid form of divide-and-conquer in data.</p>
<p>Towering trees are full of vitality, with deep roots and lush leaves, spreading branches and flourishing.</p>
<p>They show us the vivid form of divide and conquer in data.</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_tree/">7.1 &nbsp; Binary tree</a></li>
<li><a href="binary_tree_traversal/">7.2 &nbsp; Binary tree traversal</a></li>
<li><a href="array_representation_of_tree/">7.3 &nbsp; Array Representation of tree</a></li>
<li><a href="binary_search_tree/">7.4 &nbsp; Binary Search tree</a></li>
<li><a href="avl_tree/">7.5 &nbsp; AVL tree *</a></li>
<li><a href="binary_tree/">7.1 &nbsp; Binary Tree</a></li>
<li><a href="binary_tree_traversal/">7.2 &nbsp; Binary Tree Traversal</a></li>
<li><a href="array_representation_of_tree/">7.3 &nbsp; Array Representation of Tree</a></li>
<li><a href="binary_search_tree/">7.4 &nbsp; Binary Search Tree</a></li>
<li><a href="avl_tree/">7.5 &nbsp; AVL Tree *</a></li>
<li><a href="summary/">7.6 &nbsp; Summary</a></li>
</ul>
@@ -4364,7 +4364,7 @@ aria-label="Footer"
<a
href="binary_tree/"
class="md-footer__link md-footer__link--next"
aria-label="Next: 7.1 Binary tree"
aria-label="Next: 7.1 Binary Tree"
rel="next"
>
<div class="md-footer__title">
@@ -4372,7 +4372,7 @@ aria-label="Footer"
Next
</span>
<div class="md-ellipsis">
7.1 Binary tree
7.1 Binary Tree
</div>
</div>
<div class="md-footer__button md-icon">
@@ -4482,13 +4482,13 @@ aria-label="Footer"
<a href="binary_tree/" class="md-footer__link md-footer__link--next" aria-label="Next: 7.1 Binary tree">
<a href="binary_tree/" class="md-footer__link md-footer__link--next" aria-label="Next: 7.1 Binary Tree">
<div class="md-footer__title">
<span class="md-footer__direction">
Next
</span>
<div class="md-ellipsis">
7.1 Binary tree
7.1 Binary Tree
</div>
</div>
<div class="md-footer__button md-icon">
+108 -108
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
@@ -1862,7 +1862,7 @@
<span class="md-ellipsis">
7.1 Binary tree
7.1 Binary Tree
@@ -1890,7 +1890,7 @@
<span class="md-ellipsis">
7.2 Binary tree traversal
7.2 Binary Tree Traversal
@@ -1918,7 +1918,7 @@
<span class="md-ellipsis">
7.3 Array Representation of tree
7.3 Array Representation of Tree
@@ -1946,7 +1946,7 @@
<span class="md-ellipsis">
7.4 Binary Search tree
7.4 Binary Search Tree
@@ -1974,7 +1974,7 @@
<span class="md-ellipsis">
7.5 AVL tree *
7.5 AVL Tree *
@@ -2058,7 +2058,7 @@
<a href="#1-key-review" class="md-nav__link">
<span class="md-ellipsis">
1. &nbsp; Key review
1. &nbsp; Key Review
</span>
</a>
@@ -2206,7 +2206,7 @@
<span class="md-ellipsis">
8.2 Building a heap
8.2 Building a Heap
@@ -2234,7 +2234,7 @@
<span class="md-ellipsis">
8.3 Top-k problem
8.3 Top-K Problem
@@ -2397,7 +2397,7 @@
<span class="md-ellipsis">
9.2 Basic graph operations
9.2 Basic Operations on Graphs
@@ -2425,7 +2425,7 @@
<span class="md-ellipsis">
9.3 Graph traversal
9.3 Graph Traversal
@@ -2564,7 +2564,7 @@
<span class="md-ellipsis">
10.1 Binary search
10.1 Binary Search
@@ -2592,7 +2592,7 @@
<span class="md-ellipsis">
10.2 Binary search insertion
10.2 Binary Search Insertion
@@ -2620,7 +2620,7 @@
<span class="md-ellipsis">
10.3 Binary search boundaries
10.3 Binary Search Edge Cases
@@ -2648,7 +2648,7 @@
<span class="md-ellipsis">
10.4 Hashing optimization strategies
10.4 Hash Optimization Strategy
@@ -2676,7 +2676,7 @@
<span class="md-ellipsis">
10.5 Search algorithms revisited
10.5 Search Algorithms Revisited
@@ -2825,7 +2825,7 @@
<span class="md-ellipsis">
11.1 Sorting algorithms
11.1 Sorting Algorithms
@@ -2853,7 +2853,7 @@
<span class="md-ellipsis">
11.2 Selection sort
11.2 Selection Sort
@@ -2881,7 +2881,7 @@
<span class="md-ellipsis">
11.3 Bubble sort
11.3 Bubble Sort
@@ -2909,7 +2909,7 @@
<span class="md-ellipsis">
11.4 Insertion sort
11.4 Insertion Sort
@@ -2937,7 +2937,7 @@
<span class="md-ellipsis">
11.5 Quick sort
11.5 Quick Sort
@@ -2965,7 +2965,7 @@
<span class="md-ellipsis">
11.6 Merge sort
11.6 Merge Sort
@@ -2993,7 +2993,7 @@
<span class="md-ellipsis">
11.7 Heap sort
11.7 Heap Sort
@@ -3021,7 +3021,7 @@
<span class="md-ellipsis">
11.8 Bucket sort
11.8 Bucket Sort
@@ -3049,7 +3049,7 @@
<span class="md-ellipsis">
11.9 Counting sort
11.9 Counting Sort
@@ -3077,7 +3077,7 @@
<span class="md-ellipsis">
11.10 Radix sort
11.10 Radix Sort
@@ -3170,7 +3170,7 @@
<span class="md-ellipsis">
Chapter 12. Divide and conquer
Chapter 12. Divide and Conquer
@@ -3192,7 +3192,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 12. Divide and conquer
Chapter 12. Divide and Conquer
</label>
@@ -3214,7 +3214,7 @@
<span class="md-ellipsis">
12.1 Divide and conquer algorithms
12.1 Divide and Conquer Algorithms
@@ -3242,7 +3242,7 @@
<span class="md-ellipsis">
12.2 Divide and conquer search strategy
12.2 Divide and Conquer Search Strategy
@@ -3270,7 +3270,7 @@
<span class="md-ellipsis">
12.3 Building binary tree problem
12.3 Building a Binary Tree Problem
@@ -3298,7 +3298,7 @@
<span class="md-ellipsis">
12.4 Tower of Hanoi Problem
12.4 Hanoi Tower Problem
@@ -3435,7 +3435,7 @@
<span class="md-ellipsis">
13.1 Backtracking algorithms
13.1 Backtracking Algorithm
@@ -3463,7 +3463,7 @@
<span class="md-ellipsis">
13.2 Permutation problem
13.2 Permutations Problem
@@ -3491,7 +3491,7 @@
<span class="md-ellipsis">
13.3 Subset sum problem
13.3 Subset-Sum Problem
@@ -3519,7 +3519,7 @@
<span class="md-ellipsis">
13.4 n queens problem
13.4 N-Queens Problem
@@ -3616,7 +3616,7 @@
<span class="md-ellipsis">
Chapter 14. Dynamic programming
Chapter 14. Dynamic Programming
@@ -3638,7 +3638,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 14. Dynamic programming
Chapter 14. Dynamic Programming
</label>
@@ -3660,7 +3660,7 @@
<span class="md-ellipsis">
14.1 Introduction to dynamic programming
14.1 Introduction to Dynamic Programming
@@ -3688,7 +3688,7 @@
<span class="md-ellipsis">
14.2 Characteristics of DP problems
14.2 Characteristics of Dynamic Programming Problems
@@ -3716,7 +3716,7 @@
<span class="md-ellipsis">
14.3 DP problem-solving approach
14.3 Dynamic Programming Problem-Solving Approach
@@ -3744,7 +3744,7 @@
<span class="md-ellipsis">
14.4 0-1 Knapsack problem
14.4 0-1 Knapsack Problem
@@ -3772,7 +3772,7 @@
<span class="md-ellipsis">
14.5 Unbounded knapsack problem
14.5 Unbounded Knapsack Problem
@@ -3800,7 +3800,7 @@
<span class="md-ellipsis">
14.6 Edit distance problem
14.6 Edit Distance Problem
@@ -3937,7 +3937,7 @@
<span class="md-ellipsis">
15.1 Greedy algorithms
15.1 Greedy Algorithm
@@ -3965,7 +3965,7 @@
<span class="md-ellipsis">
15.2 Fractional knapsack problem
15.2 Fractional Knapsack Problem
@@ -3993,7 +3993,7 @@
<span class="md-ellipsis">
15.3 Maximum capacity problem
15.3 Maximum Capacity Problem
@@ -4021,7 +4021,7 @@
<span class="md-ellipsis">
15.4 Maximum product cutting problem
15.4 Maximum Product Cutting Problem
@@ -4154,7 +4154,7 @@
<span class="md-ellipsis">
16.1 Installation
16.1 Programming Environment Installation
@@ -4182,7 +4182,7 @@
<span class="md-ellipsis">
16.2 Contributing
16.2 Contributing Together
@@ -4210,7 +4210,7 @@
<span class="md-ellipsis">
16.3 Terminology
16.3 Terminology Table
@@ -4327,7 +4327,7 @@
<a href="#1-key-review" class="md-nav__link">
<span class="md-ellipsis">
1. &nbsp; Key review
1. &nbsp; Key Review
</span>
</a>
@@ -4383,40 +4383,40 @@
<!-- Page content -->
<h1 id="76-summary">7.6 &nbsp; Summary<a class="headerlink" href="#76-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>
<h3 id="1-key-review">1. &nbsp; Key Review<a class="headerlink" href="#1-key-review" title="Permanent link">&para;</a></h3>
<ul>
<li>A binary tree is a non-linear data structure that reflects the "divide and conquer" logic of splitting one into two. Each binary tree node contains a value and two pointers, which point to its left and right child nodes, respectively.</li>
<li>For a node in a binary tree, its left (right) child node and the tree formed below it are collectively called the node's left (right) subtree.</li>
<li>Terms related to binary trees include root node, leaf node, level, degree, edge, height, and depth.</li>
<li>The operations of initializing a binary tree, inserting nodes, and removing nodes are similar to those of linked list operations.</li>
<li>Common types of binary trees include perfect binary trees, complete binary trees, full binary trees, and balanced binary trees. The perfect binary tree represents the ideal state, while the linked list is the worst state after degradation.</li>
<li>A binary tree can be represented using an array by arranging the node values and empty slots in a level-order traversal sequence and implementing pointers based on the index mapping relationship between parent nodes and child nodes.</li>
<li>The level-order traversal of a binary tree is a breadth-first search method, which reflects a layer-by-layer traversal manner of "expanding circle by circle." It is usually implemented using a queue.</li>
<li>Pre-order, in-order, and post-order traversals are all depth-first search methods, reflecting the traversal manner of "going to the end first, then backtracking to continue." They are usually implemented using recursion.</li>
<li>A binary search tree is an efficient data structure for element searching, with the time complexity of search, insert, and remove operations all being <span class="arithmatex">\(O(\log n)\)</span>. When a binary search tree degrades into a linked list, these time complexities deteriorate to <span class="arithmatex">\(O(n)\)</span>.</li>
<li>An AVL tree, also known as a balanced binary search tree, ensures that the tree remains balanced after continuous node insertions and removals through rotation operations.</li>
<li>Rotation operations in an AVL tree include right rotation, left rotation, right-left rotation, and left-right rotation. After node insertion or removal, the AVL tree rebalances itself by performing these rotations in a bottom-up manner.</li>
<li>A binary tree is a non-linear data structure that embodies the divide-and-conquer logic of "one divides into two". Each binary tree node contains a value and two pointers, which respectively point to its left and right child nodes.</li>
<li>For a certain node in a binary tree, the tree formed by its left (right) child node and all nodes below is called the left (right) subtree of that node.</li>
<li>Related terminology of binary trees includes root node, leaf node, level, degree, edge, height, and depth.</li>
<li>The initialization, node insertion, and node removal operations of binary trees are similar to those of linked lists.</li>
<li>Common types of binary trees include perfect binary trees, complete binary trees, full binary trees, and balanced binary trees. The perfect binary tree is the ideal state, while the linked list is the worst state after degradation.</li>
<li>A binary tree can be represented using an array by arranging node values and empty slots in level-order traversal sequence, and implementing pointers based on the index mapping relationship between parent and child nodes.</li>
<li>Level-order traversal of a binary tree is a breadth-first search method, embodying a layer-by-layer traversal approach of "expanding outward circle by circle", typically implemented using a queue.</li>
<li>Preorder, inorder, and postorder traversals all belong to depth-first search, embodying a traversal approach of "first go to the end, then backtrack and continue", typically implemented using recursion.</li>
<li>A binary search tree is an efficient data structure for element searching, with search, insertion, and removal operations all having time complexity of <span class="arithmatex">\(O(\log n)\)</span>. When a binary search tree degenerates into a linked list, all time complexities degrade to <span class="arithmatex">\(O(n)\)</span>.</li>
<li>An AVL tree, also known as a balanced binary search tree, ensures the tree remains balanced after continuous node insertions and removals through rotation operations.</li>
<li>Rotation operations in AVL trees include right rotation, left rotation, left rotation then right rotation, and right rotation then left rotation. After inserting or removing nodes, AVL trees perform rotation operations from bottom to top to restore the tree to balance.</li>
</ul>
<h3 id="2-q-a">2. &nbsp; Q &amp; A<a class="headerlink" href="#2-q-a" title="Permanent link">&para;</a></h3>
<p><strong>Q</strong>: For a binary tree with only one node, are both the height of the tree and the depth of the root node <span class="arithmatex">\(0\)</span>?</p>
<p>Yes, because height and depth are typically defined as "the number of edges passed."</p>
<p><strong>Q</strong>: The insertion and removal in a binary tree are generally accomplished by a set of operations. What does "a set of operations" refer to here? Does it imply releasing the resources of the child nodes?</p>
<p>Taking the binary search tree as an example, the operation of removing a node needs to be handled in three different scenarios, each requiring multiple steps of node operations.</p>
<p><strong>Q</strong>: Why are there three sequences: pre-order, in-order, and post-order for DFS traversal of a binary tree, and what are their uses?</p>
<p>Similar to sequential and reverse traversal of arrays, pre-order, in-order, and post-order traversals are three methods of traversing a binary tree, allowing us to obtain a traversal result in a specific order. For example, in a binary search tree, since the node sizes satisfy <code>left child node value &lt; root node value &lt; right child node value</code>, we can obtain an ordered node sequence by traversing the tree in the "left <span class="arithmatex">\(\rightarrow\)</span> root <span class="arithmatex">\(\rightarrow\)</span> right" priority.</p>
<p><strong>Q</strong>: In a right rotation operation that deals with the relationship between the imbalance nodes <code>node</code>, <code>child</code>, <code>grand_child</code>, isn't the connection between <code>node</code> and its parent node and the original link of <code>node</code> lost after the right rotation?</p>
<p>We need to view this problem from a recursive perspective. The <code>right_rotate(root)</code> operation passes the root node of the subtree and eventually returns the root node of the rotated subtree with <code>return child</code>. The connection between the subtree's root node and its parent node is established after this function returns, which is outside the scope of the right rotation operation's maintenance.</p>
<p><strong>Q</strong>: Why does DFS traversal of binary trees have three orders: preorder, inorder, and postorder, and what are their uses?</p>
<p>Similar to forward and reverse traversal of arrays, preorder, inorder, and postorder traversals are three methods of binary tree traversal that allow us to obtain a traversal result in a specific order. For example, in a binary search tree, since nodes satisfy the relationship <code>left child node value &lt; root node value &lt; right child node value</code>, we only need to traverse the tree with the priority of "left <span class="arithmatex">\(\rightarrow\)</span> root <span class="arithmatex">\(\rightarrow\)</span> right" to obtain an ordered node sequence.</p>
<p><strong>Q</strong>: In a right rotation operation handling the relationship between unbalanced nodes <code>node</code>, <code>child</code>, and <code>grand_child</code>, doesn't the connection between <code>node</code> and its parent node get lost after the right rotation?</p>
<p>We need to view this problem from a recursive perspective. The right rotation operation <code>right_rotate(root)</code> passes in the root node of the subtree and eventually returns the root node of the subtree after rotation with <code>return child</code>. The connection between the subtree's root node and its parent node is completed after the function returns, which is not within the maintenance scope of the right rotation operation.</p>
<p><strong>Q</strong>: In C++, functions are divided into <code>private</code> and <code>public</code> sections. What considerations are there for this? Why are the <code>height()</code> function and the <code>updateHeight()</code> function placed in <code>public</code> and <code>private</code>, respectively?</p>
<p>It depends on the scope of the method's use. If a method is only used within the class, then it is designed to be <code>private</code>. For example, it makes no sense for users to call <code>updateHeight()</code> on their own, as it is just a step in the insertion or removal operations. However, <code>height()</code> is for accessing node height, similar to <code>vector.size()</code>, thus it is set to <code>public</code> for use.</p>
<p>It mainly depends on the method's usage scope. If a method is only used within the class, then it is designed as <code>private</code>. For example, calling <code>updateHeight()</code> alone by the user makes no sense, as it is only a step in insertion or removal operations. However, <code>height()</code> is used to access node height, similar to <code>vector.size()</code>, so it is set to <code>public</code> for ease of use.</p>
<p><strong>Q</strong>: How do you build a binary search tree from a set of input data? Is the choice of root node very important?</p>
<p>Yes, the method for building the tree is provided in the <code>build_tree()</code> method in the binary search tree code. As for the choice of the root node, we usually sort the input data and then select the middle element as the root node, recursively building the left and right subtrees. This approach maximizes the balance of the tree.</p>
<p>Yes, the method for building a tree is provided in the <code>build_tree()</code> method in the binary search tree code. As for the choice of root node, we typically sort the input data, then select the middle element as the root node, and recursively build the left and right subtrees. This approach maximizes the tree's balance.</p>
<p><strong>Q</strong>: In Java, do you always have to use the <code>equals()</code> method for string comparison?</p>
<p>In Java, for primitive data types, <code>==</code> is used to compare whether the values of two variables are equal. For reference types, the working principles of the two symbols are different.</p>
<ul>
<li><code>==</code>: Used to compare whether two variables point to the same object, i.e., whether their positions in memory are the same.</li>
<li><code>equals()</code>: Used to compare whether the values of two objects are equal.</li>
</ul>
<p>Therefore, to compare values, we should use <code>equals()</code>. However, strings initialized with <code>String a = "hi"; String b = "hi";</code> are stored in the string constant pool and point to the same object, so <code>a == b</code> can also be used to compare the contents of two strings.</p>
<p>Therefore, if we want to compare values, we should use <code>equals()</code>. However, strings initialized via <code>String a = "hi"; String b = "hi";</code> are stored in the string constant pool and point to the same object, so <code>a == b</code> can also be used to compare the contents of the two strings.</p>
<p><strong>Q</strong>: Before reaching the bottom level, is the number of nodes in the queue <span class="arithmatex">\(2^h\)</span> in breadth-first traversal?</p>
<p>Yes, for example, a full binary tree with height <span class="arithmatex">\(h = 2\)</span> has a total of <span class="arithmatex">\(n = 7\)</span> nodes, then the bottom level has <span class="arithmatex">\(4 = 2^h = (n + 1) / 2\)</span> nodes.</p>
@@ -4441,7 +4441,7 @@ aria-label="Footer"
<a
href="../avl_tree/"
class="md-footer__link md-footer__link--prev"
aria-label="Previous: 7.5 AVL tree *"
aria-label="Previous: 7.5 AVL Tree *"
rel="prev"
>
<div class="md-footer__button md-icon">
@@ -4453,7 +4453,7 @@ aria-label="Footer"
Previous
</span>
<div class="md-ellipsis">
7.5 AVL tree *
7.5 AVL Tree *
</div>
</div>
</a>
@@ -4566,7 +4566,7 @@ aria-label="Footer"
<nav class="md-footer__inner md-grid" aria-label="Footer" >
<a href="../avl_tree/" class="md-footer__link md-footer__link--prev" aria-label="Previous: 7.5 AVL tree *">
<a href="../avl_tree/" class="md-footer__link md-footer__link--prev" aria-label="Previous: 7.5 AVL Tree *">
<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>
@@ -4576,7 +4576,7 @@ aria-label="Footer"
Previous
</span>
<div class="md-ellipsis">
7.5 AVL tree *
7.5 AVL Tree *
</div>
</div>
</a>