mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-04 11:44:21 +00:00
deploy
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -37,7 +37,7 @@
|
||||
|
||||
|
||||
|
||||
<title>Chapter 5. Stack and queue - Hello Algo</title>
|
||||
<title>Chapter 5. Stack and Queue - 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>
|
||||
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@
|
||||
<div class="md-header__topic" data-md-component="header-topic">
|
||||
<span class="md-ellipsis">
|
||||
|
||||
Chapter 5. Stack and queue
|
||||
Chapter 5. Stack and Queue
|
||||
|
||||
</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 *
|
||||
|
||||
|
||||
|
||||
@@ -1432,7 +1432,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
Chapter 5. Stack and queue
|
||||
Chapter 5. Stack and Queue
|
||||
|
||||
|
||||
|
||||
@@ -1454,7 +1454,7 @@
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
|
||||
|
||||
Chapter 5. Stack and queue
|
||||
Chapter 5. Stack and Queue
|
||||
|
||||
|
||||
</label>
|
||||
@@ -1532,7 +1532,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
5.3 Double-ended queue
|
||||
5.3 Double-Ended Queue
|
||||
|
||||
|
||||
|
||||
@@ -1623,7 +1623,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
Chapter 6. Hash table
|
||||
Chapter 6. Hashing
|
||||
|
||||
|
||||
|
||||
@@ -1645,7 +1645,7 @@
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
|
||||
|
||||
Chapter 6. Hash table
|
||||
Chapter 6. Hashing
|
||||
|
||||
|
||||
</label>
|
||||
@@ -1667,7 +1667,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
6.1 Hash table
|
||||
6.1 Hash Table
|
||||
|
||||
|
||||
|
||||
@@ -1695,7 +1695,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
6.2 Hash collision
|
||||
6.2 Hash Collision
|
||||
|
||||
|
||||
|
||||
@@ -1723,7 +1723,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
|
||||
|
||||
|
||||
|
||||
@@ -4302,18 +4302,18 @@
|
||||
|
||||
|
||||
<!-- Page content -->
|
||||
<h1 id="chapter-5-stack-and-queue">Chapter 5. Stack and queue<a class="headerlink" href="#chapter-5-stack-and-queue" title="Permanent link">¶</a></h1>
|
||||
<p><a class="glightbox" href="../assets/covers/chapter_stack_and_queue.jpg" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Stack and queue" class="cover-image" src="../assets/covers/chapter_stack_and_queue.jpg" /></a></p>
|
||||
<h1 id="chapter-5-stack-and-queue">Chapter 5. Stack and Queue<a class="headerlink" href="#chapter-5-stack-and-queue" title="Permanent link">¶</a></h1>
|
||||
<p><a class="glightbox" href="../assets/covers/chapter_stack_and_queue.jpg" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Stack and Queue" class="cover-image" src="../assets/covers/chapter_stack_and_queue.jpg" /></a></p>
|
||||
<div class="admonition abstract">
|
||||
<p class="admonition-title">Abstract</p>
|
||||
<p>A stack is like cats placed on top of each other, while a queue is like cats lined up one by one.</p>
|
||||
<p>They represent the logical relationships of Last-In-First-Out (LIFO) and First-In-First-Out (FIFO), respectively.</p>
|
||||
<p>Stacks are like stacking cats, while queues are like cats lining up.</p>
|
||||
<p>They represent LIFO (Last In First Out) and FIFO (First In First Out) logic, respectively.</p>
|
||||
</div>
|
||||
<h2 id="chapter-contents">Chapter contents<a class="headerlink" href="#chapter-contents" title="Permanent link">¶</a></h2>
|
||||
<ul>
|
||||
<li><a href="stack/">5.1 Stack</a></li>
|
||||
<li><a href="queue/">5.2 Queue</a></li>
|
||||
<li><a href="deque/">5.3 Double-ended queue</a></li>
|
||||
<li><a href="deque/">5.3 Double-Ended Queue</a></li>
|
||||
<li><a href="summary/">5.4 Summary</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -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 *
|
||||
|
||||
|
||||
|
||||
@@ -1432,7 +1432,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
Chapter 5. Stack and queue
|
||||
Chapter 5. Stack and Queue
|
||||
|
||||
|
||||
|
||||
@@ -1454,7 +1454,7 @@
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
|
||||
|
||||
Chapter 5. Stack and queue
|
||||
Chapter 5. Stack and Queue
|
||||
|
||||
|
||||
</label>
|
||||
@@ -1532,7 +1532,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
5.3 Double-ended queue
|
||||
5.3 Double-Ended Queue
|
||||
|
||||
|
||||
|
||||
@@ -1616,7 +1616,7 @@
|
||||
<a href="#1-key-review" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
|
||||
1. Key review
|
||||
1. Key Review
|
||||
|
||||
</span>
|
||||
</a>
|
||||
@@ -1692,7 +1692,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
Chapter 6. Hash table
|
||||
Chapter 6. Hashing
|
||||
|
||||
|
||||
|
||||
@@ -1714,7 +1714,7 @@
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
|
||||
|
||||
Chapter 6. Hash table
|
||||
Chapter 6. Hashing
|
||||
|
||||
|
||||
</label>
|
||||
@@ -1736,7 +1736,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
6.1 Hash table
|
||||
6.1 Hash Table
|
||||
|
||||
|
||||
|
||||
@@ -1764,7 +1764,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
6.2 Hash collision
|
||||
6.2 Hash Collision
|
||||
|
||||
|
||||
|
||||
@@ -1792,7 +1792,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
6.3 Hash algorithm
|
||||
6.3 Hash Algorithm
|
||||
|
||||
|
||||
|
||||
@@ -1931,7 +1931,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
7.1 Binary tree
|
||||
7.1 Binary Tree
|
||||
|
||||
|
||||
|
||||
@@ -1959,7 +1959,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
7.2 Binary tree traversal
|
||||
7.2 Binary Tree Traversal
|
||||
|
||||
|
||||
|
||||
@@ -1987,7 +1987,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
7.3 Array Representation of tree
|
||||
7.3 Array Representation of Tree
|
||||
|
||||
|
||||
|
||||
@@ -2015,7 +2015,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
7.4 Binary Search tree
|
||||
7.4 Binary Search Tree
|
||||
|
||||
|
||||
|
||||
@@ -2043,7 +2043,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
7.5 AVL tree *
|
||||
7.5 AVL Tree *
|
||||
|
||||
|
||||
|
||||
@@ -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. Key review
|
||||
1. Key Review
|
||||
|
||||
</span>
|
||||
</a>
|
||||
@@ -4383,27 +4383,27 @@
|
||||
|
||||
<!-- Page content -->
|
||||
<h1 id="54-summary">5.4 Summary<a class="headerlink" href="#54-summary" title="Permanent link">¶</a></h1>
|
||||
<h3 id="1-key-review">1. Key review<a class="headerlink" href="#1-key-review" title="Permanent link">¶</a></h3>
|
||||
<h3 id="1-key-review">1. Key Review<a class="headerlink" href="#1-key-review" title="Permanent link">¶</a></h3>
|
||||
<ul>
|
||||
<li>Stack is a data structure that follows the Last-In-First-Out (LIFO) principle and can be implemented using arrays or linked lists.</li>
|
||||
<li>In terms of time efficiency, the array implementation of the stack has a higher average efficiency. However, during expansion, the time complexity for a single push operation can degrade to <span class="arithmatex">\(O(n)\)</span>. In contrast, the linked list implementation of a stack offers more stable efficiency.</li>
|
||||
<li>Regarding space efficiency, the array implementation of the stack may lead to a certain degree of space wastage. However, it's important to note that the memory space occupied by nodes in a linked list is generally larger than that for elements in an array.</li>
|
||||
<li>A queue is a data structure that follows the First-In-First-Out (FIFO) principle, and it can also be implemented using arrays or linked lists. The conclusions regarding time and space efficiency for queues are similar to those for stacks.</li>
|
||||
<li>A double-ended queue (deque) is a more flexible type of queue that allows adding and removing elements at both ends.</li>
|
||||
<li>A stack is a data structure that follows the LIFO principle and can be implemented using arrays or linked lists.</li>
|
||||
<li>In terms of time efficiency, the array implementation of a stack has higher average efficiency, but during expansion, the time complexity of a single push operation degrades to <span class="arithmatex">\(O(n)\)</span>. In contrast, the linked list implementation of a stack provides more stable efficiency performance.</li>
|
||||
<li>In terms of space efficiency, the array implementation of a stack may lead to some degree of space wastage. However, it should be noted that the memory space occupied by linked list nodes is larger than that of array elements.</li>
|
||||
<li>A queue is a data structure that follows the FIFO principle and can also be implemented using arrays or linked lists. The conclusions regarding time efficiency and space efficiency comparisons for queues are similar to those for stacks mentioned above.</li>
|
||||
<li>A deque is a queue with greater flexibility that allows adding and removing elements at both ends.</li>
|
||||
</ul>
|
||||
<h3 id="2-q-a">2. Q & A<a class="headerlink" href="#2-q-a" title="Permanent link">¶</a></h3>
|
||||
<p><strong>Q</strong>: Is the browser's forward and backward functionality implemented with a doubly linked list?</p>
|
||||
<p>A browser's forward and backward navigation is essentially a manifestation of the "stack" concept. When a user visits a new page, the page is added to the top of the stack; when they click the back button, the page is popped from the top of the stack. A double-ended queue (deque) can conveniently implement some additional operations, as mentioned in the "Double-Ended Queue" section.</p>
|
||||
<p><strong>Q</strong>: After popping from a stack, is it necessary to free the memory of the popped node?</p>
|
||||
<p>If the popped node will still be used later, it's not necessary to free its memory. In languages like Java and Python that have automatic garbage collection, manual memory release is not necessary; in C and C++, manual memory release is required.</p>
|
||||
<p><strong>Q</strong>: A double-ended queue seems like two stacks joined together. What are its uses?</p>
|
||||
<p>A double-ended queue, which is a combination of a stack and a queue or two stacks joined together, exhibits both stack and queue logic. Thus, it can implement all applications of stacks and queues while offering more flexibility.</p>
|
||||
<p><strong>Q</strong>: How exactly are undo and redo implemented?</p>
|
||||
<p>Undo and redo operations are implemented using two stacks: Stack <code>A</code> for undo and Stack <code>B</code> for redo.</p>
|
||||
<p>The forward and backward functionality of a browser is essentially a manifestation of a "stack." When a user visits a new page, that page is added to the top of the stack; when the user clicks the back button, that page is popped from the top of the stack. Using a deque can conveniently implement some additional operations, as mentioned in the "Deque" section.</p>
|
||||
<p><strong>Q</strong>: After popping from the stack, do we need to free the memory of the popped node?</p>
|
||||
<p>If the popped node will still be needed later, then memory does not need to be freed. If it won't be used afterward, languages like Java and Python have automatic garbage collection, so manual memory deallocation is not required; in C and C++, manual memory deallocation is necessary.</p>
|
||||
<p><strong>Q</strong>: A deque seems like two stacks joined together. What is its purpose?</p>
|
||||
<p>A deque is like a combination of a stack and a queue, or two stacks joined together. It exhibits the logic of both stack and queue, so it can implement all applications of stacks and queues, and is more flexible.</p>
|
||||
<p><strong>Q</strong>: How are undo and redo specifically implemented?</p>
|
||||
<p>Use two stacks: stack <code>A</code> for undo and stack <code>B</code> for redo.</p>
|
||||
<ol>
|
||||
<li>Each time a user performs an operation, it is pushed onto Stack <code>A</code>, and Stack <code>B</code> is cleared.</li>
|
||||
<li>When the user executes an "undo", the most recent operation is popped from Stack <code>A</code> and pushed onto Stack <code>B</code>.</li>
|
||||
<li>When the user executes a "redo", the most recent operation is popped from Stack <code>B</code> and pushed back onto Stack <code>A</code>.</li>
|
||||
<li>Whenever the user performs an operation, push this operation onto stack <code>A</code> and clear stack <code>B</code>.</li>
|
||||
<li>When the user performs "undo," pop the most recent operation from stack <code>A</code> and push it onto stack <code>B</code>.</li>
|
||||
<li>When the user performs "redo," pop the most recent operation from stack <code>B</code> and push it onto stack <code>A</code>.</li>
|
||||
</ol>
|
||||
|
||||
<!-- Source file information -->
|
||||
@@ -4427,7 +4427,7 @@ aria-label="Footer"
|
||||
<a
|
||||
href="../deque/"
|
||||
class="md-footer__link md-footer__link--prev"
|
||||
aria-label="Previous: 5.3 Double-ended queue"
|
||||
aria-label="Previous: 5.3 Double-Ended Queue"
|
||||
rel="prev"
|
||||
>
|
||||
<div class="md-footer__button md-icon">
|
||||
@@ -4439,7 +4439,7 @@ aria-label="Footer"
|
||||
Previous
|
||||
</span>
|
||||
<div class="md-ellipsis">
|
||||
5.3 Double-ended queue
|
||||
5.3 Double-Ended Queue
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
@@ -4451,7 +4451,7 @@ aria-label="Footer"
|
||||
<a
|
||||
href="../../chapter_hashing/"
|
||||
class="md-footer__link md-footer__link--next"
|
||||
aria-label="Next: Chapter 6. &nbsp; Hash table"
|
||||
aria-label="Next: Chapter 6. &nbsp; Hashing"
|
||||
rel="next"
|
||||
>
|
||||
<div class="md-footer__title">
|
||||
@@ -4459,7 +4459,7 @@ aria-label="Footer"
|
||||
Next
|
||||
</span>
|
||||
<div class="md-ellipsis">
|
||||
Chapter 6. Hash table
|
||||
Chapter 6. Hashing
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-footer__button md-icon">
|
||||
@@ -4552,7 +4552,7 @@ aria-label="Footer"
|
||||
<nav class="md-footer__inner md-grid" aria-label="Footer" >
|
||||
|
||||
|
||||
<a href="../deque/" class="md-footer__link md-footer__link--prev" aria-label="Previous: 5.3 Double-ended queue">
|
||||
<a href="../deque/" class="md-footer__link md-footer__link--prev" aria-label="Previous: 5.3 Double-Ended Queue">
|
||||
<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>
|
||||
@@ -4562,20 +4562,20 @@ aria-label="Footer"
|
||||
Previous
|
||||
</span>
|
||||
<div class="md-ellipsis">
|
||||
5.3 Double-ended queue
|
||||
5.3 Double-Ended Queue
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<a href="../../chapter_hashing/" class="md-footer__link md-footer__link--next" aria-label="Next: Chapter 6. &nbsp; Hash table">
|
||||
<a href="../../chapter_hashing/" class="md-footer__link md-footer__link--next" aria-label="Next: Chapter 6. &nbsp; Hashing">
|
||||
<div class="md-footer__title">
|
||||
<span class="md-footer__direction">
|
||||
Next
|
||||
</span>
|
||||
<div class="md-ellipsis">
|
||||
Chapter 6. Hash table
|
||||
Chapter 6. Hashing
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-footer__button md-icon">
|
||||
|
||||
Reference in New Issue
Block a user