フィボナッチ ヒープのキーの減少操作で O(1) の償却複雑さを取得するにはどうすればよいですか? 要素を含むフィボナッチ ヒープ内のノードを見つけるだけでも、BFS を使用して O(n) 時間かかるため、O(1) 償却時間を取得することはできません。
参考までに、問題のノードを検索するための BFS の実装を次に示します。
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;
}
そして、ここに私の減少キーのコードがあります:
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;
}
}