COP3502_29_Heaps - Binary Heaps Priority Queues Computer...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Science Department University of Central Florida Priority Queues COP 3502 – Computer Science I
Background image of page 1

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

View Full DocumentRight Arrow Icon
page 2 Binary Heaps Heap: A heap is an Abstract Data Type Just like stacks and queues are ADTs Meaning, we will define certain behaviors that dictate whether or not a certain data structure is a heap So what is a heap? More specifically, what does it do or how do they work? A heap looks similar to a tree But a heap has a specific property/invariant that each node in the tree MUST follow
Background image of page 2
page 3 Binary Heaps Heap: In a heap, all values stored in the subtree of a given node must be less than or equal to the value stored in that node This is known as the heap property And it is this property that makes a heap a heap!
Background image of page 3

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

View Full DocumentRight Arrow Icon
page 4 Binary Heaps Heap: In a heap, all values stored in the subtree of a given node must be less than or equal to the value stored in that node If B is a child of node A, then the value of node A must be greater than or equal to the value of node B This is a called a Max-Heap Where the root stores the highest value of any given subtree
Background image of page 4
page 5 Binary Heaps Heap: Alternatively, if all values stored in the subtree of a given node are greater than or equal to the value stored in that node This is called a Min-Heap (where root is smallest value)
Background image of page 5

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

View Full DocumentRight Arrow Icon
page 6 Binary Heaps Binary Heap: What we just described was a basic Heap Now for a heap to be Binary Heap , it must adhere to one other property: The Shape Property : The heap must be a complete binary tree Meaning, all levels of the tree, except possibly the last one, must be fully filled And if the last level is not complete, the nodes of the level are filled from left to right ***And it just so happens that the previous pictures shown were all examples of binary heaps
Background image of page 6
page 7 Binary Heaps Building a Complete Binary Tree: When a complete binary tree is built, its first node must be the root. Root
Background image of page 7

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

View Full DocumentRight Arrow Icon
page 8 Binary Heaps Building a Complete Binary Tree: Left child of the root The second node is always the left child of the root.
Background image of page 8
page 9 Binary Heaps Building a Complete Binary Tree: Right child of the root The third node is always the right child of the root.
Background image of page 9

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

View Full DocumentRight Arrow Icon
page 10 Binary Heaps Building a Complete Binary Tree: The next nodes always fill the next level from left-to- right.
Background image of page 10
page 11 Binary Heaps Building a Complete Binary Tree: The next nodes always fill the next level from left-to- right.
Background image of page 11

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

View Full DocumentRight Arrow Icon
page 12 Binary Heaps Building a Complete Binary Tree: The next nodes always fill the next level from left-to- right.
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 09/21/2011.

Page1 / 45

COP3502_29_Heaps - Binary Heaps Priority Queues Computer...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online