Final Review Solutions (Cấu trúc dữ liệu heap, hàng đợi ưu tiên và duyệt đồ thị) - Ching and Christines
Génération de l'aperçu...
Tài liệu ôn tập cuối kỳ về các chủ đề cấu trúc dữ liệu như heap, hàng đợi ưu tiên và duyệt đồ thị, bao gồm giải thích và bài tập luyện tập.
Description
Final Review Solutions 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. Consequence: 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. Consequence: the root will always contain the (lowest/highest) priority value element Methods (of a min-heap) peek(): returns (but does not remove) the item with the minimum priority value; runtime is Θ(1) removeMin(): returns (and does remove) the item with the minimum priority value; 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 bottom-rightmost position ∗ Bubble up the new inserted value Bubbling (of 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 (always pick the lesser of the two children if both have priority value less than the current node) 1 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 min
Résumé IA
- Nom du document
- Final Review Solutions (Cấu trúc dữ liệu heap, hàng đợi ưu tiên và duyệt đồ thị) - Ching and Christines
- École / Cours
- University of California, Berkeley · Lập trình Java
- Contenu
- Tài liệu cung cấp giải pháp ôn tập cuối kỳ về Heaps (cấu trúc, phương thức, biểu diễn) và Graph Traversals (BFS/DFS). Bao gồm các bài tập thực hành về Heaps kết hợp BST và lời giải.
- Table des matières
- Final Review Solutions
- Heaps
- Graph Traversals
- BFS/DFS
- Pages
- 15 pages
- Téléversé par
- Uni24h
Foire aux questions
Ce document est-il gratuit ?
Oui. « Final Review Solutions (Cấu trúc dữ liệu heap, hàng đợi ưu tiên và duyệt đồ thị) - Ching and Christines » est gratuit — il suffit de vous connecter et de cliquer sur Télécharger pour obtenir le fichier original.
Combien de pages compte ce document ?
Le document contient 15 pages, pour le cours Lập trình Java. Vous pouvez le prévisualiser en ligne avant de le télécharger.
Puis-je prévisualiser avant de télécharger ?
Oui. Vous pouvez prévisualiser ce document directement sur cette page avec le lecteur en ligne, puis décider de le télécharger ou non.
Final Review Solutions (Cấu trúc dữ liệu heap, hàng đợi ưu tiên và duyệt đồ thị) - Ching and Christines
Génération de l'aperçu...
Final Review Solutions 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. Consequence: 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. Consequence: the root will always contain the (lowest/highest) priority value element Methods (of a min-heap) peek(): returns (but does not remove) the item with the minimum priority value; runtime is Θ(1) removeMin(): returns (and does remove) the item with the minimum priority value; 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 bottom-rightmost position ∗ Bubble up the new inserted value Bubbling (of 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 (always pick the lesser of the two children if both have priority value less than the current node) 1 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 min
Lire le document entier
- Nom du document
- Final Review Solutions (Cấu trúc dữ liệu heap, hàng đợi ưu tiên và duyệt đồ thị) - Ching and Christines
- École / Cours
- University of California, Berkeley · Lập trình Java
- Contenu
- Tài liệu cung cấp giải pháp ôn tập cuối kỳ về Heaps (cấu trúc, phương thức, biểu diễn) và Graph Traversals (BFS/DFS). Bao gồm các bài tập thực hành về Heaps kết hợp BST và lời giải.
- Table des matières
- Final Review Solutions
- Heaps
- Graph Traversals
- BFS/DFS
- Pages
- 15 pages
- Téléversé par
- Uni24h
Commentaires (0)
Aucun commentaire pour le moment. Soyez le premier !
Misc.onclusion (Discussion 14-END) (Ôn tập cấu trúc dữ liệu) - Christine Zhou
Giáo trình Lập trình Java
Inheritance (Discussion 4) (Kế thừa trong Java) - Christine Zhou
Ôn tập lập trình Java (MT2 Review Solutions) - Ching and Christines
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
Commentaires (0)
Aucun commentaire pour le moment. Soyez le premier !