Final Review Solutions (Cấu trúc dữ liệu heap, hàng đợi ưu tiên và duyệt đồ thị) - Ching and Christines
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.
미리보기 생성 중...
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
… 전체 문서를 읽으려면 원본 파일을 다운로드하세요.
- 문서명
- Final Review Solutions (Cấu trúc dữ liệu heap, hàng đợi ưu tiên và duyệt đồ thị) - Ching and Christines
- 학교 / 강의
- University of California, Berkeley · Lập trình Java
- 내용
- 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.
- 목차
- Final Review Solutions
- Heaps
- Graph Traversals
- BFS/DFS
- 페이지 수
- 15 페이지
- 업로더
- Giang Le
자주 묻는 질문
이 문서는 무료인가요?
네. “Final Review Solutions (Cấu trúc dữ liệu heap, hàng đợi ưu tiên và duyệt đồ thị) - Ching and Christines” 문서는 무료입니다. 로그인 후 '다운로드'를 클릭하여 원본 파일을 받으세요.
이 문서는 몇 페이지로 되어 있나요?
이 문서는 15페이지입니다, Lập trình Java 과정용. 다운로드하기 전에 온라인으로 미리 볼 수 있습니다.
다운로드하기 전에 미리 볼 수 있나요?
네. 이 페이지의 온라인 리더를 통해 문서를 미리 본 후 다운로드 여부를 결정할 수 있습니다.

댓글 (0)
댓글이 없습니다. 첫 댓글을 남겨보세요!