0

I want to implement Fibonacci Heap on Dijkstra Algorithm. I use this code for Fibonacci heap. http://keithschwarz.com/interesting/code/?dir=fibonacci-heap The problem is how to call the method: decreaseKey? It always give me the hint that (entry,double). But how to write an entry? The following is a simple example, how to fill the question mark?

FibonacciHeap<Integer> aa = new FibonacciHeap<>();
aa.enqueue(10, 1.01);
aa.enqueue(10, .2);
aa.enqueue(12, 3.2);
aa.enqueue(13, 3.4);
aa.decreaseKey(??????, newPriority);
Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122
09817167d
  • 3
  • 4

1 Answers1

0

decreaseKey() expects the first argument to be of type FibonacciHeap.Entry. 3 methods in the class return the Entrys of the heap:

  • public Entry<T> enqueue(T value, double priority);
  • public Entry<T> min();
  • public Entry<T> dequeueMin();

Each of the 3 methods return a different element, and modify the heap in their own way. Depending on your use case, you can store these Entrys in a variable and pass it to decreaseKey().

One such case would be storing the Entry while enqueuing it. Whenever you enqueue() something to the heap, it returns its corresponding Entry. From its documentation:

/**
 * Inserts the specified element into the Fibonacci heap with the specified
 * priority.  
 * ...
 * @return An Entry representing that element in the tree.
 */
public Entry<T> enqueue(T value, double priority);

You can store it, and pass it to decreaseKey().

FibonacciHeap<Integer> aa = new FibonacciHeap<>();
FibonacciHeap.Entry entry = aa.enqueue(10, 1.01);
// ...
aa.decreaseKey(entry, newPriority);
John Bupit
  • 10,406
  • 8
  • 39
  • 75