Implement min-heap with decrease-key in O(log n)
Analyze the implement min-heap with decrease-key in o(log n).
Examples
Input: "test_input_1"
Output: "output_1"
Input: "test_input_2"
Output: "output_2"
Hints
Recall that in a min-heap, the parent node is always smaller than or equal to its children. How can you leverage this property to efficiently locate a node's parent or children?
Consider how the decrease-key operation affects the heap property. What steps must you take to restore the heap property after decreasing a key, and how can you do this in logarithmic time?
Think about how to maintain a mapping between node values and their positions in the heap. How can this mapping help you quickly locate a node to perform decrease-key, and how can you update it efficiently during heap operations?
Implement min-heap with decrease-key in O(log n)
Analyze the implement min-heap with decrease-key in o(log n).