Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 14 Ming Li Department of."— Presentation transcript:

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

2 Introduction to Data Structure, Fall 2006 Slide- 2 California State University, Fresno 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 Introduction to Data Structure, Fall 2006 Slide- 3 California State University, Fresno Maximum and Minimum Heaps Example 40 10 30 15 55 22 20 5 11 10 25 52 50 (A) Maximum Heap (9 nodes)(B) Maximum Heap (4 nodes)

4 Introduction to Data Structure, Fall 2006 Slide- 4 California State University, Fresno Maximum and Minimum Heaps Example 10 40 30 15 5 25 55 52 2011 50 10 22 (C) Minimum Heap (9 nodes)(D) Minimum Heap (4 nodes)

5 Introduction to Data Structure, Fall 2006 Slide- 5 California State University, Fresno Example of Heap Before and After Insertion of 50

6 Introduction to Data Structure, Fall 2006 Slide- 6 California State University, Fresno Reorder the tree in pushHeap()

7 Introduction to Data Structure, Fall 2006 Slide- 7 California State University, Fresno Exchanging elements in popHeap()

8 Introduction to Data Structure, Fall 2006 Slide- 8 California State University, Fresno Adjusting the heap for popHeap()

9 Introduction to Data Structure, Fall 2006 Slide- 9 California State University, Fresno Heap Operations - POP

10 Introduction to Data Structure, Fall 2006 Slide- 10 California State University, Fresno Heap Operations - PUSH

11 Introduction to Data Structure, Fall 2006 Slide- 11 California State University, Fresno 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


Download ppt "Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 14 Ming Li Department of."

Similar presentations


Ads by Google