{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

DS-chapter5(Leftist Heap,Skew H,binomial queue)

# DS-chapter5(Leftist Heap,Skew H,binomial queue) - CHAPTER 5...

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

CHAPTER 5 PRIORITY QUEUES (HEAPS) —— delete the element with the highest \ lowest priority

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

View Full Document
5.6 Leftist Heaps 1. Structure Property: 0 0 0 1 0 1 0 1 0 1* 0 1 0 It’s a leftist heap ( very unbalanced) It’s not a leftist heap A structural property, an ordering property Definition 【 the null path length Npl(X) is the length of the shortest path from any node X to a node without two children. The Npl of a node with zero or one child is 0. Npl (NULL)= -1 the leftist heaps: for every node X in the heap, the null path length of the left child is at least as large as that of the right child.
Theorem : a leftist tree with r nodes on the right path must have at least 2 r -1 nodes. Induction: If r = 1 ,there must be at least one tree node. Suppose that the theorem is true for 1,2,…. .r. Consider : a leftist tree with r+1 node on the right path, the root has a right subtree with r nodes on the right path, a left subtree with at least r nodes on the right path. left subtree right subtree root r+1 node on the right path right subtree r node on the right path right subtree at least r node on the right path This tree has at least 2 r -1 nodes This tree has at least 2 r -1 nodes Leftist Heap A leftist tree of N nodes has a right path containing at most log( N+1 ) nodes

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

View Full Document
PriorityQueue Initialize( void ); ElementType FindMin( PriorityQueue H ); int IsEmpty(priorityQueue H); PriorityQueue Merge(PriorityQueue H1, PriorityQueue H2); PriorityQueue Insert1(ElementType X, PriorityQueue H); PriorityQueue DeleteMin1(PriorityQueue H) Leftist Heap 2. Leftist Heap Operations: Struct TreeNode { ElementType Element; PriorityQueue Left; PriorityQueue Right; int Npl; }
Merge routine Leftist Heap PriorityQueue Merge ( PriorityQueue H1, PriorityQueue H2) { if (H1 == NULL ) return H2; if (H2 == NULL) return H1; if (H1 ->Element < H2 ->Element) return Merge1(H1, H2) else return Merge1(H2,H1); } static PriorityQueue Merge1(PriorityQueue H1,PriorityQueue H2) { if (H1->Left == NULL) /* Single node */ H1->Left = H2; /*H1->Right is already NULL, H1->Npl is already 0 */

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 21

DS-chapter5(Leftist Heap,Skew H,binomial queue) - CHAPTER 5...

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

View Full Document
Ask a homework question - tutors are online