wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

A d-ary heap is like a binary heap, but instead of two children, nodes have 'd' children. A d-ary heap can be represented in a 1-dimensional array as follows. The root is kept in A[1], its d children are kept in order in A[2] through A[d + 1] their children are kept in order in A[d + 2] through A[d2+d+1] and so on. What index does maps the jth child for (1 J d) of ith index node?

A
d(i1)+j+1
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
B
(d×i)+j+1
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
d(i1)+1
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
d(i1)+j
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is A d(i1)+j+1
Consider 3 array heap:


So, root at at A[1] i.e., d(i -1) + j + 1
= 3(1 - 1) + j +1
=0 + 0 + 1 =1
1st child of root=d(i1)+j+1
= 3(1 - 1) + 1 + 1 = 2
3rd child of root=d(i1)+j+1
= 3(1 - 1) + 3 + 1
= 0 + 4 = 4
Index for node 7 = d(i -1) + j + 1
3(2 - 1) + 3 + 1
= 3 + 3 + 1 = 7
So, index maps to d(i - 1) + j + 1.

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Remainder Problems
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon