In: Computer Science
Recall that an array could be a convenient way of storing the elements of a Heap. Give a Pseudocode that determines whether an array H[1..N] is indeed a Heap, i.e., it’s elements satisfy the Heap property.
Array:
B = Base address
W = Storage Size of one element stored in the
array (in byte)
I = Subscript of element whose address is to be
found
LB = Lower limit / Lower Bound of subscript, if not specified assume 0 (zero)
Int A[6]={33,32,31,43,35,85}
1001 1004 1008 1012 1016 1020
33 | 32 | 31 | 43 | 35 | 85 |
A[0] A[1] A[2] A[3] A[4] A[5]
Where:1001 ,1004......................1020 = address or memory allocatrion
33,32......................85= Elemets of array
A[0] ,A[1]...................A[5] = Index value
Heap:
An array could be a convenient way of storing the elements of a Heap in following way:
1. Sequance representation of heap:
Sequance representation of heap:
1001 1004 1008 1012 1016 1020
33 | 32 | 31 | 43 | 35 | 85 |
A[0] A[1] A[2] A[3] A[4] A[5]
Where:1001 ,1004......................1020 = address or memory allocatrion.
33,32......................85= Elemets of array.
A[0] ,A[1]...................A[5] = Index value.
2. Array representation of Heap's:
Properties of a Heap:
Pseudocode that determines whether an array H[1..N] is indeed a Heap:
Here: H[1...n]= array which elemnts tends to 1 to n.
N=represent the number of elments in array H[1....n]