lecture11 - Sorting Dr.YingwuZhu Heaps...

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

View Full Document Right Arrow Icon
    Sorting Dr. Yingwu Zhu
Background image of page 1

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

View Full DocumentRight Arrow Icon
    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
Background image of page 2
    Heaps Which of the following are heaps? A B C
Background image of page 3

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

View Full DocumentRight Arrow Icon
    Heaps Maxheap?– by default Minheap?
Background image of page 4
    Implementing a Heap What data structure is good for its  implementation?
Background image of page 5

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

View Full DocumentRight Arrow Icon
    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
Background image of page 6
    Implementing a Heap Note the placement of the nodes in the array 0 1   2 3 4 5
Background image of page 7

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

View Full DocumentRight Arrow Icon
    Implementing a Heap
Background image of page 8
    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?
Background image of page 9

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

View Full DocumentRight Arrow Icon
    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
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 30

lecture11 - Sorting Dr.YingwuZhu Heaps...

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

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