1 / 11

Introduction to Data Structure

Introduction to Data Structure. Chapter 14 Ming Li Department of Computer Science California State University, Fresno Fall 2006. Binary Heap.

cassaundra
Download Presentation

Introduction to Data Structure

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Data Structure Chapter 14 Ming Li Department of Computer Science California State University, Fresno Fall 2006

  2. Binary Heap Binary heaps are a particularly simple kind of heap data structure created using a binary tree. It can be seen as a binary tree with two additional constraints: The shape property: the tree is either a perfectly balanced binary tree (all leaves are at the same level), or, if the last level of the tree is not complete, the nodes are filled from left to right. The heap property: each node is greater than or equal to each of its children according to some comparison predicate which is fixed for the entire data structure.

  3. Maximum and Minimum Heaps Example 55 40 52 30 50 15 11 10 10 25 5 20 22 (A) Maximum Heap (9 nodes) (B) Maximum Heap (4 nodes)

  4. Maximum and Minimum Heaps Example 10 5 30 15 50 10 40 52 11 20 55 25 22 ( C) Minimum Heap (9 nodes) (D) Minimum Heap (4 nodes)

  5. Example of Heap Before and After Insertion of 50

  6. Reorder the tree in pushHeap()

  7. Exchanging elements in popHeap()

  8. Adjusting the heap for popHeap()

  9. Heap Operations - POP

  10. Heap Operations - PUSH

  11. Heap Sort • Sort a list of objects by using a heap data structure. • All elements to be sorted are inserted into a heap • The heap organizes the elements added to it in such a way that either the largest value or the smallest value can be quickly extracted. • This gives us the elements in order. • More info: http://en.wikipedia.org/wiki/Heapsort

More Related