Closest location - Heapify or Build-heap

Posted by Trevor Adams on Programmers See other posts from Programmers or by Trevor Adams
Published on 2011-11-16T04:08:18Z Indexed on 2011/11/16 10:23 UTC
Read the original article Hit count: 414

Filed under:
|

So lets say we have a set of gps data points and your current location. If asked to give the closest point to your current location we can utilize a heap with the distance being the key. Now if we update the current location, I suspect that only a few of the keys will change enough to violate the heap property. Would it be more efficient to rebuild the heap after recalculating the keys or to run heapify (assuming that only a few of the keys have changed enough). It is assumed that we don't jump around with the new location (new current location is close to the last current location).

© Programmers or respective owner

Related posts about algorithms

Related posts about data-structures