OA. free
Free
Other/Unspecified Core Computer Science Data Structures & Algorithms Medium

The depth (height) of a complete binary tree with n nodes is given by which formula?

Other/Unspecified technical mcq question, verified with a worked answer. Free to practise - no sign-up.

The depth (height) of a complete binary tree with $n$ nodes is given by which formula?

Choose one option.
Show answer & explanation
Answer: A. floor(log2(n))

In a complete binary tree with n nodes, the maximum level index (height/depth) is given by floor(log2(n)).

Step-by-step Derivation:
Step 1: A complete binary tree of depth d has between 2^d and 2^(d+1) - 1 nodes.
Step 2: Taking base-2 logarithm: d <= log2(n) < d + 1.
Step 3: Therefore, the depth d = floor(log2(n)).