9,172 views
5 votes
5 votes

A complete binary tree with $n$ non-leaf nodes contains

  1. $\log_{2}n$ nodes
  2. $n+1$ nodes
  3. $2n$ nodes
  4. $2n+1$ nodes

3 Answers

Best answer
22 votes
22 votes
A complete binary tree is one in which all levels except those in last level are fully filled and even in last level all nodes are filled from left to right.

Now, a tree is a graph and we can consider the binary tree as an undirected graph also. So, degree of root = 2, degree of all internal nodes excluding root = 3 (one parent and 2 child nodes) and degree of leaf nodes = 1 (only parent). (Assuming root is not a leaf and tree is full also).

Now, sum of degrees in a graph $=2e$, where $e$ is the no. of edges.

In a tree we have $e = x-1$ where $x$ is the total no. of nodes. Now, we have $n$ non-leaf nodes, so that means $x - n $ leaf nodes and $n-1$ internal nodes excluding root. So, equating the sum of degrees, we can write

$2 + 3.(n-1) + x - n  = 2.(x - 1) \\ \implies x = 2n + 1$.

Now, if tree is complete but not full, the last node might have no sibling and thus total number of nodes can be $2n$ also (one internal node having degree $2$ instead of $3$.
selected by
5 votes
5 votes
option D:

2n + 1 nodes in total
Answer:

Related questions

33 votes
33 votes
4 answers
1
39 votes
39 votes
8 answers
2
Kathleen asked Sep 15, 2014
18,708 views
The maximum number of edges in a $n$-node undirected graph without self loops is$n^2$$\frac{n(n-1)}{2}$$n-1$$\frac{(n+1)(n)}{2}$
64 votes
64 votes
15 answers
3
Arjun asked Jul 6, 2016
37,136 views
Consider the following segment of C-code:int j, n; j = 1; while (j <= n) j = j * 2;The number of comparisons made in the execution of the loop for any $n 0$ is:$\lceil \...
8 votes
8 votes
2 answers
4
Arjun asked Jul 6, 2016
3,902 views
A simple two-pass assembler does which of the following in the first pass:Checks to see if the instructions are legal in the current assembly modeIt allocates space for t...