Tài liệu ôn tập cuối kỳ Heap, hàng đợi ưu tiên (Final Review) - Ching and Christines
Tài liệu ôn tập cuối kỳ của Ching và Christine về cấu trúc dữ liệu Heap, hàng đợi ưu tiên, duyệt đồ thị và thuật toán Dijkstra.
正在生成预览...
Final Review Heaps Motivation: What if we always want to find the minimum or maximum element? Keep high priority items at the top Min heap: high priority corresponds to low priority value Max heap: high priority corresponds to high priority value Notice the difference between priority and priority value! Represented as a binary tree with two more properties: Complete: no empty spaces other than on the right-hand side of the bottommost level; height will be Θ(log N ) where N is the number of nodes (Min/Max)-heap property: for a particular node n, the children of n must have (greater/lesser) priority value than n; the root will always contain the (lowest/highest) priority value element Methods peek(): returns (but does not remove) the item with the highest priority; runtime is Θ(1) removeMin(): returns (and does remove) the item with the highest priority; runtime is O(log N ) ∗ Take the item in the bottom-rightmost position and replace the value at the root ∗ Bubble down the new root value insert(T item, int priorityVal): Insert the item with priority value of priorityVal into the heap; runtime is O(log N ) ∗ Insert the item in the first open bottom-left position ∗ Bubble up the new inserted value Bubbling (in a min-heap) Bubble up: while the priority value of a particular node n is less than the priority value of its parent, swap the two Bubble down: while the priority value of a particular node n is greater than the priority value of its child/children, swap the two (pick the lesser of the children if both have priority value less than n) Representation Number each element in the heap, starting from 1, left to right top to bottom, this will represent the index of the item in the array For a particular node at index i : ∗ Parent is at index 2i ∗ Left child is at index 2i ∗ Right child is at index 2i + 1 PriorityQueue<T> Implemented with a min heap, methods include T poll(), T peek(), void push(T item) Can use own Comparat
… 下载原始文件以阅读完整文档。
- 文档名称
- Tài liệu ôn tập cuối kỳ Heap, hàng đợi ưu tiên (Final Review) - Ching and Christines
- 学校 / 课程
- University of California, Berkeley · Lập trình Java
- 内容
- Tài liệu cung cấp kiến thức về heap, biểu diễn đồ thị và các thuật toán liên quan
- 目录
- Final Review
- Heaps
- Graph Traversals
- Dijkstra’s Algorithm
- 页数
- 13 页
- 上传者
- Giang Le
常见问题
此文档免费吗?
是的。“Tài liệu ôn tập cuối kỳ Heap, hàng đợi ưu tiên (Final Review) - Ching and Christines”是免费的 — 只需登录并点击“下载”即可获取原始文件。
这份文档有多少页?
该文档共有 13 页,适用于课程 Lập trình Java。您可以在下载前进行在线预览。
我可以在下载前预览吗?
是的。您可以通过在线阅读器直接在本页面预览此文档,然后再决定是否下载。

评论 (0)
暂无评论。快来抢沙发吧!