How can you get O(1) amortized complexity in the decrease-key operation on a Fibonacci heap? Just finding the node in the Fibonacci heap that contains the element takes O(n) time using a BFS, which should make it impossible to get O(1) amortized time.
For reference, here's my implementation of BFS to search for the node in question:
public fHeapNode search(int x){
Stack<fHeapNode> stack = new Stack<fHeapNode>();
stack.push(minNode);
//Breath first searching
while (!stack.empty()) {
fHeapNode curr = stack.pop();
if(curr.data==x) {return curr;}
else{
if (curr.child != null) {
stack.push(curr.child);
}
fHeapNode start = curr;
curr = curr.right;
while (curr != start) {
if (curr.child != null) {
stack.push(curr.child);
}
if(curr.data==x) {return curr;}
curr = curr.right;
}
}
}
return null;
}
And here's my code for decrease-key:
public void decreaseKey(fHeapNode x, double k)
{
if (k > x.key) {
//throw new IllegalArgumentException("entered value is wrong");
}
x.key = k;
fHeapNode tempParent = x.parent;
if ((tempParent != null) && (x.key < tempParent.key)) {
cut(x,tempParent);
cascadingCut(tempParent);
}
if (x.key < minNode.key) {
minNode = x;
}
}