Tài liệu ôn tập cuối kỳ Heap, hàng đợi ưu tiên (Final Review) - Ching and Christines
Generating preview...
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.
Description
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
AI summary
- Document name
- Tài liệu ôn tập cuối kỳ Heap, hàng đợi ưu tiên (Final Review) - Ching and Christines
- School / Course
- University of California, Berkeley · Lập trình Java
- Content
- 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
- Table of contents
- Final Review
- Heaps
- Graph Traversals
- Dijkstra’s Algorithm
- Pages
- 13 pages
- Uploaded by
- Uni24h
Frequently asked questions
Is this document free?
Yes. “Tài liệu ôn tập cuối kỳ Heap, hàng đợi ưu tiên (Final Review) - Ching and Christines” is free — just sign in and click Download to get the original file.
How many pages is this document?
The document has 13 pages, for the course Lập trình Java. You can preview it online before downloading.
Can I preview before downloading?
Yes. You can preview this document right on this page with the online reader, then decide whether to download.
Tài liệu ôn tập cuối kỳ Heap, hàng đợi ưu tiên (Final Review) - Ching and Christines
Generating preview...
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
Read full document
- Document name
- Tài liệu ôn tập cuối kỳ Heap, hàng đợi ưu tiên (Final Review) - Ching and Christines
- School / Course
- University of California, Berkeley · Lập trình Java
- Content
- 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
- Table of contents
- Final Review
- Heaps
- Graph Traversals
- Dijkstra’s Algorithm
- Pages
- 13 pages
- Uploaded by
- Uni24h
Comments (0)
No comments yet. Be the first!
Misc.onclusion (Discussion 14-END) (Ôn tập cấu trúc dữ liệu) - Christine Zhou
Final Review Solutions (Cấu trúc dữ liệu heap, hàng đợi ưu tiên và duyệt đồ thị) - Ching and Christines
Giáo trình Lập trình Java
Inheritance (Discussion 4) (Kế thừa trong Java) - Christine Zhou
Asymptotic Analysis (Discussion 7) (Phân tích tiệm cận) - Christine Zhou
Chương 7.Cơ học lượng tử - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Chương 6.Quang học lượng tử - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Chương 5.Thuyết tương đối - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Chương 4. Tán xạ ánh sáng - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Chương 3.Phân cực ánh sáng - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Comments (0)
No comments yet. Be the first!