Binary heap
[[toc]]
- Heap
- Some Characteristics
- Heap Is in the form of a binary tree
- N-th level in heap has
- N-th level in heap has one more element than all previous level elements summed up Binary Number Characteristic <-
- N-th levels last element in heap is the -th element
- j-th element in heap is in the floor(log(j)+1) level. -th element in heap is at n-th level
- left child of j-th member is at 2 * j-th position ins heap, right is at 2*j+1 -th position
- Some Characteristics
Heap
- Interesting Problem
- There exits multiple types of heaps. We are talking about Binary Heap
- Binary Heap Theory
Some Characteristics
Heap Is in the form of a binary tree
N-th level in heap has
N-th level in heap has one more element than all previous level elements summed up Binary Number Characteristic <-
Proof by induction
-
This is correct when n=3
-
Lets Perform the induction step with n+1
Left side:
Right side
<- Left Side = Right Side
N-th levels last element in heap is the -th element
j-th element in heap is in the floor(log(j)+1) level. -th element in heap is at n-th level
left child of j-th member is at 2 * j-th position ins heap, right is at 2*j+1 -th position
PROOF Last element in N-th level is th element. In level N+1, it is th element. That means, when we go to from N-th level last element to
- right child <- Last element in N+1 level
- left child <- Second to last element in N+1 level
First element in N-th level is th element. In level N+1, it is th element.
- right <-Second to First element in n+1 level
- left <- First element in n+1 level
If we go to second to last element in N-th level, it childs
- right child <- 3. from last element in N+1 level
- left child <- 4. from last to last element in N+1 level