Skip to main content
Tweeted twitter.com/#!/StackCompSci/status/605744266086887424
edited tags
Link
Raphael
  • 72.9k
  • 30
  • 181
  • 393
Source Link
Eran Medan
  • 431
  • 1
  • 4
  • 12

Why in a min priority queue (heap based) it is called "decrease-key" and not just "set-key"?

When you call decrease-key in a min priority queue, you are basically setting the key, you can accidentally put a higher key, right? so why isn't it called "set-key" or "update-key"? why (according to Wikipedia and other sources) a min priority queue has "decrease-key" and a max priority queue has "increase-key"? why not have both "set-key" and if you decrease it or increase it, do what you should do to keep the heap property invariant?

I mean what if I call decrease-key on a min heap and give a bigger value? Will it throw an exception? Why not just call it "set-key" and handle any kind of value?