One can implement a priority queue by an unsorted array or a

One can implement a priority queue by an unsorted array or a binary heap. What is the complexity of insertion and deletion (in big-O notation), if (a) you use a binary heap, or (2) you use an unsorted array?

Solution

Complexity of insertion in Bunary Heap : O(logn), because height of tree remains O(logn)

Complexity of insertion in unsorted array: O(n), beacause you have to first find the position in array that itself take O(n) and again insertion takes O(n)

One can implement a priority queue by an unsorted array or a binary heap. What is the complexity of insertion and deletion (in big-O notation), if (a) you use a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site