mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-26 18:17:13 +00:00
build
This commit is contained in:
@@ -6,16 +6,16 @@ comments: true
|
||||
|
||||
### 1. Key Review
|
||||
|
||||
- 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).
|
||||
- A priority queue is defined as a queue with priority sorting, typically implemented using heaps.
|
||||
- Common heap operations and their corresponding time complexities include: element insertion $O(\log n)$, heap top element removal $O(\log n)$, and accessing the heap top element $O(1)$.
|
||||
- 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.
|
||||
- A priority queue is a queue in which elements are dequeued according to priority, and it is typically implemented using a heap.
|
||||
- Common heap operations and their corresponding time complexities include inserting an element $O(\log n)$, removing the top element $O(\log n)$, and accessing the top element $O(1)$.
|
||||
- Complete binary trees are well-suited for array representation, so we typically use arrays to store heaps.
|
||||
- Heapify operations are used to maintain the heap property and are employed in both element insertion and removal operations.
|
||||
- The time complexity of building a heap with $n$ input elements can be optimized to $O(n)$, which is highly efficient.
|
||||
- Top-k is a classic algorithm problem that can be efficiently solved using the heap data structure, with a time complexity of $O(n \log k)$.
|
||||
- Building a heap from $n$ input elements can be optimized to $O(n)$, which is highly efficient.
|
||||
- Top-k is a classic algorithmic problem that can be solved efficiently using a heap, with a time complexity of $O(n \log k)$.
|
||||
|
||||
### 2. Q & A
|
||||
|
||||
**Q**: Are the "heap" in data structures and the "heap" in memory management the same concept?
|
||||
**Q**: Does the term "heap" in data structures mean the same thing as "heap" in memory management?
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user