r/AskComputerScience • • Jan 20 '26
Correct Binary Heap
for an array [1,2,3,4,5] which is the correct heap?
a. 1->(2, 3), 2->(4,Empty), 3->(5,Empty)
b. 1->(2,3), 2->(4,5), 3
0
Upvotes
r/AskComputerScience • • Jan 20 '26
for an array [1,2,3,4,5] which is the correct heap?
a. 1->(2, 3), 2->(4,Empty), 3->(5,Empty)
b. 1->(2,3), 2->(4,5), 3
View all comments
Show parent comment
2
u/dajoli Jan 20 '26
OK, so to answer your question. "Balance" isn't sufficient for a heap. The key point is that the bottom level is left-filled. 2 has an empty right child that can't be there if 3 has any non-empty children.