We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I had the same response. Once you need to search the heap for a specific value, you're really stuck with linear time. So this may not be the best data structure to use if the operation is expected to be called very often.
That said, I think there are real-world use cases for this. Very simply, suppose you have a priority queue filled with a bunch of random work items. Every once in a while, somebody submits work, then smacks their head and says "oh, I forgot to do XXXXX." That person would like to remove the item from the queue, then resubmit. Depending on how big the queue is and how often this happens, you might be OK with the linear search.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
QHEAP1
You are viewing a single comment's thread. Return to all comments →
I had the same response. Once you need to search the heap for a specific value, you're really stuck with linear time. So this may not be the best data structure to use if the operation is expected to be called very often.
That said, I think there are real-world use cases for this. Very simply, suppose you have a priority queue filled with a bunch of random work items. Every once in a while, somebody submits work, then smacks their head and says "oh, I forgot to do XXXXX." That person would like to remove the item from the queue, then resubmit. Depending on how big the queue is and how often this happens, you might be OK with the linear search.