{"record":{"id":"974cdc6c8f838c83","repo":"TheAlgorithms/C-Sharp","slug":"value-cannot-be-increased","errorCode":null,"errorMessage":"Value cannot be increased","messagePattern":"Value cannot be increased","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"DataStructures/Heap/FibonacciHeap/FibonacciHeap.cs","lineNumber":237,"sourceCode":"    ///     k must be less than x.Key, increasing the key of an item is not supported.\n    /// </remarks>\n    /// <param name=\"x\">The item you want to reduce in value.</param>\n    /// <param name=\"k\">The new value for the item.</param>\n    public void DecreaseKey(FHeapNode<T> x, T k)\n    {\n        if (MinItem == null)\n        {\n            throw new ArgumentException($\"{nameof(x)} is not from the heap\");\n        }\n\n        if (x.Key == null)\n        {\n            throw new ArgumentException(\"x has no value\");\n        }\n\n        if (k.CompareTo(x.Key) > 0)\n        {\n            throw new InvalidOperationException(\"Value cannot be increased\");\n        }\n\n        x.Key = k;\n        var y = x.Parent;\n        if (y != null && x.Key.CompareTo(y.Key) < 0)\n        {\n            Cut(x, y);\n            CascadingCut(y);\n        }\n\n        if (x.Key.CompareTo(MinItem.Key) < 0)\n        {\n            MinItem = x;\n        }\n    }\n\n    /// <summary>\n    ///     Remove x from the child list of y.","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/DataStructures/Heap/FibonacciHeap/FibonacciHeap.cs#L219-L255","documentation":"FibonacciHeap.DecreaseKey throws InvalidOperationException \"Value cannot be increased\" when the new key k compares greater than the node's current key (k.CompareTo(x.Key) > 0). A decrease-key operation only accepts equal or smaller values; increasing would break the Fibonacci heap invariants.","triggerScenarios":"Calling DecreaseKey(x, k) where k > x.Key numerically / by comparison order.","commonSituations":"Inverting the priority direction (min-heap vs max-heap thinking), passing the old and new values swapped, or recomputing a distance that grew.","solutions":["Verify k is less than or equal to the node's current key before calling.","If an increase is needed, remove and re-Push the node instead.","Check comparator/parameter order so new value is the second argument."],"exampleFix":"// before\nheap.DecreaseKey(node, newVal); // newVal > node.Key\n// after\nif (newVal.CompareTo(node.Key) <= 0)\n{\n    heap.DecreaseKey(node, newVal);\n}\nelse\n{\n    heap.Remove(node); // or delete+reinsert path\n}","handlingStrategy":"validation","validationCode":"if (newVal.CompareTo(node.Key) <= 0) { heap.DecreaseKey(node, newVal); }","typeGuard":null,"tryCatchPattern":"try { heap.DecreaseKey(node, k); } catch (InvalidOperationException) { /* attempted increase; remove+reinsert instead */ }","preventionTips":["Assert the new priority is smaller-or-equal before calling","Remember this is a min-heap: smaller key = higher priority","For increases, use remove-and-reinsert"],"tags":["data-structures","fibonacci-heap","invalid-operation"],"backgroundTag":"invalid-state-transition","analyzedSha":"96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c","analyzedAt":"2026-09-13T17:04:01.438Z","contentChangedAt":"2026-09-13T17:04:01.438Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}