1

I need to describe an algorithm that finds the second smallest element in a Fibonacci-Heap using the Operations: Insert, ExtractMin, DecreaseKey and GetMin. The last one is an algorithm previously implemented to find and return the smallest element of the heap.

I thought I'd start by extracting the minimum, which results in its children becoming roots. I could then use GetMin to find the second smallest element. But it seems to me that I'm overlooking other cases because I don't know when to use Insert and DecreaseKey, and the way the question is phrased seems to suggest I should need them.

gnat
20.5k29 gold badges117 silver badges308 bronze badges
asked Jan 11, 2013 at 10:37
4
  • 3
    a=extractMin; res=getMin; insert(a);return res; Commented Jan 11, 2013 at 10:49
  • Why do I need to insert a again? And also, does it not matter that I still haven't used DecreaseKey then? Commented Jan 11, 2013 at 11:24
  • only if you want to keep the heap unchanged after the call to getSecondMin, and no it doesn't matter that you didn't use it Commented Jan 11, 2013 at 11:26
  • 1
    @ratchetfreak : Why not post your comment as an answer? :) Commented Jun 18, 2013 at 9:29

1 Answer 1

0

a=extractMin; res=getMin; insert(a);return res;

[Folks: when answers are posted as comments, would you please add them as an answer and close the question. Thanks]

answered Jun 21, 2015 at 5:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.