{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture16-Heaps

lecture16-Heaps - Binary and Binomial Heaps Lecture 16...

This preview shows pages 1–8. Sign up to view the full content.

Binary and Binomial Heaps These lecture slides are adopted from CLRS, Chapters 6, 19. Source: internet Lecture 16

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Binary Heap: Definition Binary heap. Almost complete binary tree. filled on all levels, except last, where filled from left to right Min-heap ordered. every child greater than (or equal to) parent 06 14 78 18 81 77 91 45 53 47 64 84 99 83
3 Binary Heap: Properties Properties. Min element is in root. Heap with N elements has height = log 2 N . 06 14 78 18 81 77 91 45 53 47 64 84 99 83 N = 14 Height = 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Binary Heaps: Array Implementation Implementing binary heaps. Use an array: no need for explicit parent or child pointers. Parent(i) = i/2 Left(i) = 2i Right(i) = 2i + 1 06 14 78 18 81 77 91 45 53 47 64 84 99 83 1 2 3 4 5 6 7 8 9 10 11 12 13 14
5 Binary Heap: Insertion Insert element x into heap. 06 14 78 18 81 77 91 45 53 47 64 84 99 83 42 next free slot

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
6 Binary Heap: Insertion Insert element x into heap. 06 14 78 18 81 77 91 45 53 47 64 84 99 83 42 swap with parent
7 Binary Heap: Insertion Insert element x into heap.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 19

lecture16-Heaps - Binary and Binomial Heaps Lecture 16...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online