lecture11

# lecture11 - Sorting Dr.YingwuZhu Heaps 1 Itiscomplete 2...

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

Sorting Dr. Yingwu Zhu

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

View Full Document
Heaps heap  is a binary tree with properties: 1. It is  complete Each level of tree completely filled Except possibly bottom level (nodes in  left most positions) 2. It satisfies  heap-order property Data in each node >= data in children
Heaps Which of the following are heaps? A B C

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

View Full Document
Heaps Maxheap?– by default Minheap?
Implementing a Heap What data structure is good for its  implementation?

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

View Full Document
Implementing a Heap Use an array or vector, why? Number the nodes from top to bottom Number nodes on each row from left to right Store data in i th  node in i th  location of array  (vector) 0 1 2 3 4
Implementing a Heap Note the placement of the nodes in the array 0 1   2 3 4 5

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

View Full Document
Implementing a Heap
Basic Heap Operations Constructor Set  mySize  to 0, allocate array  Empty Check value of  mySize Retrieve max item Return root of the binary tree,  myArray[0] How about delete max item? Think about it?

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

View Full Document
Basic Heap Operations Delete max item Max item is the root, replace with last node in tree Then interchange root with larger of two children Continue this with the resulting sub-tree(s) Semiheap:  [1] complete [2] both subtrees are heaps Result called a semiheap
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 03/01/2011 for the course CSSE 250 taught by Professor Dr.yingwuzhu during the Fall '11 term at UH Clear Lake.

### Page1 / 30

lecture11 - Sorting Dr.YingwuZhu Heaps 1 Itiscomplete 2...

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

View Full Document
Ask a homework question - tutors are online