Presentation is loading. Please wait.

Presentation is loading. Please wait.

Binary Heap 16 1112 8119 1 23 456 16 1 11 2 12 3 8 4 11 5 9 6 viewed as an array viewed as a binary tree Left(i) = 2*i Right(i) = 2*i + 1 Parent(i) = i.

Similar presentations


Presentation on theme: "Binary Heap 16 1112 8119 1 23 456 16 1 11 2 12 3 8 4 11 5 9 6 viewed as an array viewed as a binary tree Left(i) = 2*i Right(i) = 2*i + 1 Parent(i) = i."— Presentation transcript:

1 Binary Heap 16 1112 8119 1 23 456 16 1 11 2 12 3 8 4 11 5 9 6 viewed as an array viewed as a binary tree Left(i) = 2*i Right(i) = 2*i + 1 Parent(i) = i / 2 A[i] >= A[Left(i)] A[i] >= A[Right(i)]

2 Binary Heap : Insert Operation 16 1112 8109 1 23 456 16 1 11 2 12 3 8 4 10 5 9 6 viewed as an array viewed as a binary tree 14 7 7 16 1114 8109 1 23 456 16 1 11 2 14 3 8 4 10 5 9 6 viewed as an array viewed as a binary tree 12 7 7

3 Binary Heap : Delete Operation 16 1114 8109 1 23 456 16 1 11 2 14 3 8 4 10 5 9 6 viewed as an array viewed as a binary tree 12 7 7 16 1114 8109 23 456 12 1 11 2 14 3 8 4 10 5 9 6 viewed as an array viewed as a binary tree 12 1 1112 8109 23 456 14 1 11 2 12 3 8 4 10 5 9 6 viewed as an array viewed as a binary tree 14 1

4 Binary Heap Operations Both insert and delete are O(log N) operations (i.e. number of levels in the tree) 2*i can be implemented as left shift i / 2 can be implemented as right shift


Download ppt "Binary Heap 16 1112 8119 1 23 456 16 1 11 2 12 3 8 4 11 5 9 6 viewed as an array viewed as a binary tree Left(i) = 2*i Right(i) = 2*i + 1 Parent(i) = i."

Similar presentations


Ads by Google