Question: Design an algorithm find-in-heap(T[1..n], x) that looks for the value x in the heap T and returns either the index of x in the heap,
Design an algorithm find-in-heap(T[1..n], x) that looks for the value x in the heap T and returns either the index of x in the heap, if it is present, or 0 otherwise. What is the running time of your algorithm? Can you use the heap property to speed up the search, and if so, how?
I know you can simply loop through the entire T and find the index that way, but that would give a O(n) for the time. Due to the second part of the question; I assume there is a more elegant way of searching the heap.
Also this is a single function, and can not use any public libraries in my solution
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
