UGC-NET Jan 2017 · Asymptotic Analysis & Recurrences
MCQ · 2 marks · Problem PROG-DIVC-0053
Red-black trees are one of many search tree schemes that are “balanced” in order to guarantee that basic dynamic-set operations take time in the worst case.
Show the worked solutionA red-black tree with \(n\) internal nodes has height at most \(2\lg(n+1)\), because every root-to-leaf path has the same number of black nodes and no two reds are adjacent.
Search, minimum, maximum, successor, predecessor, insert and delete all walk one root-to-leaf path (plus \(O(1)\) rotations for insert/delete):\[O(h)=O(\lg n)\ \text{in the worst case}.\]Answer: B
GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com