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.
  1. A
    $O(1)$
  2. B
    $O( \lg n)$
  3. C
    $O(n)$
  4. D
    $O(n \lg n)$

Solve it on GATE DA practice →More Searching & Sorting Algorithms problems

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