in DS
9,107 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
in DS
by
9.1k views

1 comment

ManojK I think this question can't be answered unless you define what exactly do you mean by complete binary tree .you must have a proper definition for complete binary tree and in gate i guess they don't ask such question without there own definition what do they mean by the complete binary tree  otherwise answer will be many or none
0
0

3 Answers

22 votes
22 votes
Best answer
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
by
5 votes
5 votes
option D:

2n + 1 nodes in total

4 Comments

yes of course answer to this question can be 2n as well as 2n+1,

this is complete binary tree ,

but if F had second child, that is complete binary tree too

1
1
its a elimination method in which you took a tree and eliminate the options I am asking for a mathematical  proof or a general method that can be applied in all the case's not just like answer can be (2n or 2n+1) .be this or that.
0
0
@shekhar see my answer..
1
1
0 votes
0 votes
Answer:

Related questions