why iis a heap able to be efficiently kept in an array based

why iis a heap able to be efficiently kept in an array based collection? why is a binary search tree not able to be efficiently kept in such a collection

Solution

Difference is that, heap is a complete binary tree, whereas BST is not.

Let me define complete binary tree: If in tree, at all levels except possibly the last one, are completely filled, then we say that it is binary tree.

Now, to keep it in array based collection, we store breadth first traversal in the array, which can be stored efficiently if traversal is \"continous\" as in case of complete binary tree. In BST, several nodes at different levels can be missing, thus making it inefficient. I hope this clears it, if not, try looking at general BST and Heap diagrams for better understanding

why iis a heap able to be efficiently kept in an array based collection? why is a binary search tree not able to be efficiently kept in such a collectionSolutio

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site