{"record":{"id":"cd29aef07604ad69","repo":"TheAlgorithms/C-Sharp","slug":"the-value-s-key-is-greater-than-or-equal-to-node-s-left","errorCode":null,"errorMessage":"The value's key is greater than or equal to node's left child's key.","messagePattern":"The value's key is greater than or equal to node's left child's key\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"DataStructures/ScapegoatTree/Node.cs","lineNumber":35,"sourceCode":"        set\n        {\n            if (value != null && !value.IsGreaterThanOrSameAs(Key))\n            {\n                throw new ArgumentException(\"The value's key is smaller than or equal to node's right child's key.\", nameof(value));\n            }\n\n            right = value;\n        }\n    }\n\n    public Node<TKey>? Left\n    {\n        get => left;\n        set\n        {\n            if (value != null && value.IsGreaterThanOrSameAs(Key))\n            {\n                throw new ArgumentException(\"The value's key is greater than or equal to node's left child's key.\", nameof(value));\n            }\n\n            left = value;\n        }\n    }\n\n    public Node(TKey key, Node<TKey>? right, Node<TKey>? left)\n        : this(key)\n    {\n        Right = right;\n        Left = left;\n    }\n\n    /// <summary>\n    /// Returns number of elements in the tree.\n    /// </summary>\n    /// <returns>Number of elements in the tree.</returns>\n    public int GetSize() => (Left?.GetSize() ?? 0) + 1 + (Right?.GetSize() ?? 0);","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/DataStructures/ScapegoatTree/Node.cs#L17-L53","documentation":"Node<TKey>.Left setter enforces BST ordering: a left child's key must be strictly less than its parent's key. Assigning a left child whose key is greater than or equal to the node's key throws ArgumentException naming `value`.","triggerScenarios":"Assigning node.Left = child where child.IsGreaterThanOrSameAs(node.Key) is true and child is not null.","commonSituations":"Hand-building trees in unit tests, custom rotation code that swaps children incorrectly, or reusing a node from a different part of the tree where duplicates or wrong-order keys exist.","solutions":["Ensure the child assigned to Left has a key strictly less than the parent's key.","Use ScapegoatTree.Insert to build the tree rather than manual node wiring.","During rotations, verify each relink maintains left < parent <= right."],"exampleFix":"// before\nnode.Left = bigChild; // bigChild.Key >= node.Key\n// after\nnode.Right = bigChild; // >= goes on the right","handlingStrategy":"validation","validationCode":"if (child != null && child.Key.CompareTo(node.Key) >= 0) throw new InvalidOperationException(\"Left child key must be < parent key\");","typeGuard":"static bool IsValidLeftChild<TKey>(Node<TKey> parent, Node<TKey> child) where TKey : IComparable => child == null || !child.IsGreaterThanOrSameAs(parent.Key);","tryCatchPattern":"try { node.Left = child; } catch (ArgumentException ex) { /* log BST violation; rebuild tree */ }","preventionTips":["Place keys >= parent on the right side only.","Prefer library Insert over manual linking.","Validate invariants after rotations in tests."],"tags":["binary-search-tree","invariant-violation","argument-validation"],"backgroundTag":"invalid-argument-value","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"}