This commit is contained in:
krahets
2026-04-02 03:08:50 +08:00
parent 09a136c9fa
commit aaf9f58eb3
157 changed files with 3002 additions and 2994 deletions
+29 -29
View File
@@ -6,7 +6,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="description" content="Data Structures and Algorithms Crash Course with Animated Illustrations and Off-the-Shelf Code">
<meta name="description" content="Data structures and algorithms tutorial with animated illustrations and ready-to-run code">
<meta name="author" content="krahets">
@@ -576,7 +576,7 @@
<span class="md-ellipsis">
Chapter 1. Encounter With Algorithms
Chapter 1. Encounter with Algorithms
@@ -598,7 +598,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 1. Encounter With Algorithms
Chapter 1. Encounter with Algorithms
</label>
@@ -1183,7 +1183,7 @@
<span class="md-ellipsis">
Chapter 4. Array and Linked List
Chapter 4. Arrays and Linked Lists
@@ -1205,7 +1205,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 4. Array and Linked List
Chapter 4. Arrays and Linked Lists
</label>
@@ -1311,7 +1311,7 @@
<span class="md-ellipsis">
4.4 Memory and Cache *
4.4 Random-Access Memory and Cache *
@@ -1402,7 +1402,7 @@
<span class="md-ellipsis">
Chapter 5. Stack and Queue
Chapter 5. Stacks and Queues
@@ -1424,7 +1424,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 5. Stack and Queue
Chapter 5. Stacks and Queues
</label>
@@ -1502,7 +1502,7 @@
<span class="md-ellipsis">
5.3 Double-Ended Queue
5.3 Deque
@@ -1593,7 +1593,7 @@
<span class="md-ellipsis">
Chapter 6. Hashing
Chapter 6. Hash Table
@@ -1615,7 +1615,7 @@
<span class="md-nav__icon md-icon"></span>
Chapter 6. Hashing
Chapter 6. Hash Table
</label>
@@ -1888,7 +1888,7 @@
<span class="md-ellipsis">
7.3 Array Representation of Tree
7.3 Array Representation of Binary Trees
@@ -2109,7 +2109,7 @@
<span class="md-ellipsis">
8.2 Building a Heap
8.2 Heap Construction Operation
@@ -2137,7 +2137,7 @@
<span class="md-ellipsis">
8.3 Top-K Problem
8.3 Top-k Problem
@@ -2565,7 +2565,7 @@
<span class="md-ellipsis">
10.2 Binary Search Insertion
10.2 Binary Search Insertion Point
@@ -2593,7 +2593,7 @@
<span class="md-ellipsis">
10.3 Binary Search Edge Cases
10.3 Binary Search Boundaries
@@ -2649,7 +2649,7 @@
<span class="md-ellipsis">
10.5 Search Algorithms Revisited
10.5 Searching Algorithms Revisited
@@ -2798,7 +2798,7 @@
<span class="md-ellipsis">
11.1 Sorting Algorithms
11.1 Sorting Algorithm
@@ -3271,7 +3271,7 @@
<span class="md-ellipsis">
12.4 Hanoi Tower Problem
12.4 Hanota Problem
@@ -4183,7 +4183,7 @@
<span class="md-ellipsis">
16.3 Terminology Table
16.3 Glossary
@@ -4359,17 +4359,17 @@
<h1 id="84-summary">8.4 &nbsp; Summary<a class="headerlink" href="#84-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>A heap is a complete binary tree that can be categorized as a max heap or min heap based on its property. The heap top element of a max heap (min heap) is the largest (smallest).</li>
<li>A priority queue is defined as a queue with priority sorting, typically implemented using heaps.</li>
<li>Common heap operations and their corresponding time complexities include: element insertion <span class="arithmatex">\(O(\log n)\)</span>, heap top element removal <span class="arithmatex">\(O(\log n)\)</span>, and accessing the heap top element <span class="arithmatex">\(O(1)\)</span>.</li>
<li>A heap is a complete binary tree. Depending on the property it satisfies, it can be classified as either a max heap or a min heap. The top element of a max heap (min heap) is the largest (smallest) element.</li>
<li>A priority queue is a queue in which elements are dequeued according to priority, and it is typically implemented using a heap.</li>
<li>Common heap operations and their corresponding time complexities include inserting an element <span class="arithmatex">\(O(\log n)\)</span>, removing the top element <span class="arithmatex">\(O(\log n)\)</span>, and accessing the top element <span class="arithmatex">\(O(1)\)</span>.</li>
<li>Complete binary trees are well-suited for array representation, so we typically use arrays to store heaps.</li>
<li>Heapify operations are used to maintain the heap property and are employed in both element insertion and removal operations.</li>
<li>The time complexity of building a heap with <span class="arithmatex">\(n\)</span> input elements can be optimized to <span class="arithmatex">\(O(n)\)</span>, which is highly efficient.</li>
<li>Top-k is a classic algorithm problem that can be efficiently solved using the heap data structure, with a time complexity of <span class="arithmatex">\(O(n \log k)\)</span>.</li>
<li>Building a heap from <span class="arithmatex">\(n\)</span> input elements can be optimized to <span class="arithmatex">\(O(n)\)</span>, which is highly efficient.</li>
<li>Top-k is a classic algorithmic problem that can be solved efficiently using a heap, with a time complexity of <span class="arithmatex">\(O(n \log k)\)</span>.</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>: Are the "heap" in data structures and the "heap" in memory management the same concept?</p>
<p>The two are not the same concept; they just happen to share the name "heap." The heap in computer system memory is part of dynamic memory allocation, where programs can use it to store data during runtime. Programs can request a certain amount of heap memory to store complex structures such as objects and arrays. When this data is no longer needed, the program needs to release this memory to prevent memory leaks. Compared to stack memory, heap memory management and usage require more caution, as improper use can lead to issues such as memory leaks and dangling pointers.</p>
<p><strong>Q</strong>: Does the term "heap" in data structures mean the same thing as "heap" in memory management?</p>
<p>They are not the same concept; they simply share the same name. In computer systems, the heap is part of dynamic memory allocation, and programs can use it to store data at runtime. A program can request a certain amount of heap memory to store complex structures such as objects and arrays. When the data is no longer needed, the program must release that memory to prevent memory leaks. Compared with stack memory, heap memory requires more careful management and use; improper handling can lead to problems such as memory leaks and dangling pointers.</p>
<!-- Source file information -->
@@ -4392,7 +4392,7 @@ aria-label="Footer"
<a
href="../top_k/"
class="md-footer__link md-footer__link--prev"
aria-label="Previous: 8.3 Top-K Problem"
aria-label="Previous: 8.3 Top-k Problem"
rel="prev"
>
<div class="md-footer__button md-icon">
@@ -4404,7 +4404,7 @@ aria-label="Footer"
Previous
</span>
<div class="md-ellipsis">
8.3 Top-K Problem
8.3 Top-k Problem
</div>
</div>
</a>