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.
Sorry about being annoying. I rethought about this problem and felt there might be a caveat in this way. I think in Java, when we offer objects to a queue, it actually takes its reference. So if we re-offer a node to a queue, it actually stores two same thing: the old node's key secretly decreased, but the queue did not know that and did not deal with it. Then the order in the heap might be messed up, and "heapify" is not guarantee to push the newly added item to their correct position. Do you have any comments on this? Many thanks!
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Dijkstra: Shortest Reach 2
You are viewing a single comment's thread. Return to all comments →
Sorry about being annoying. I rethought about this problem and felt there might be a caveat in this way. I think in Java, when we offer objects to a queue, it actually takes its reference. So if we re-offer a node to a queue, it actually stores two same thing: the old node's key secretly decreased, but the queue did not know that and did not deal with it. Then the order in the heap might be messed up, and "heapify" is not guarantee to push the newly added item to their correct position. Do you have any comments on this? Many thanks!