• edited by
30,796 views
88 88 votes

In a  binary tree with $n$ nodes, every node has an odd number of descendants. Every node is considered to be its own descendant. What is the number of nodes in the tree that have exactly one child?

  1. $0$
  2. $1$
  3. $\frac{(n-1)}{2}$
  4. $n-1$

14 Answers

Best answer
93 93 votes
$0$ because every node has an odd number of descendants so least odd number $1$ and every node is considered to be its own descendant so all nodes have even number of descendants $(0,2,4,6...)$ so every node has either $0$ children or $2$ children...
• edited by
28 28 votes

It is given that , "every node has an odd number of descendants. Every node is considered to be its own descendant.".

For all Nodes,

Total Odd Descendants = 1 (Itself ) + Descendents other than itself

Descendants other than Itself  = Odd - 1 = Even

So answer is A.

19 19 votes
in binary tree there are 3 cases

1)  0 child      2)  1 child    3) 2 child

 

if it hv 1 child ( odd )  then no of descendents are  2 ( even ) no this case is invalid

if it hv 0 or 2 child ( even ) then no of descendents are 1 or 2 ( odd ) respectively and this case is valid

so in this only 0 or 2 child are valid and 1 child is invalid

so  number of nodes in the tree that have exactly one child is 0
1 flag:
✌ Edit necessary (spongebob “As mentioned in a comment. "if it hv 0 or 2 child ( even ) then no of descendents are 1 or ****3*****( odd ) respectively and this case is valid"”)
8 8 votes

According to this definition " either 2 children or 0 children for every node"

clearly 0 node with only one child.

A is ans.

8 8 votes
Since Odd + Even = Odd

bydefault 1 descendent (odd) which is the node itself.

Now to get odd number of descendents node must have even number of descendents(nodes with 0,2,4,6.... descendents).

If a node has only one child then number of descendents will be even which is contradiction.

So none of such node is possible

Answer is A
4 4 votes

Now, for X descendent = y + 1 =even (as y is odd). Hence for making X as odd, we have to add one more child to it. Thus no node is possible with single child and having odd descendant.

Answer:
Position:
Show:

Related questions

123 123 votes
13 answers 13 answers
46.7k
46.7k views
go_editor asked Apr 21, 2016
46,711 views
A hash table of length $10$ uses open addressing with hash function $h(k) = k \: \mod \: 10$, and linear probing. After inserting $6$ values into an empty hash table, the...
32 32 votes
3 answers 3 answers
10.6k
10.6k views
go_editor asked Sep 30, 2014
10,602 views
A hash table of length $10$ uses open addressing with hash function $h(k) = k \mod 10$, and linear probing. After inserting $6$ values into an empty hash table, the table...
63 63 votes
4 answers 4 answers
18.3k
18.3k views
go_editor asked Sep 30, 2014
18,314 views
The following C function takes a singly-linked list as input argument. It modifies the list by moving the last element to the front of the list and returns the modified l...
97 97 votes
10 answers 10 answers
41.4k
41.4k views
go_editor asked Apr 21, 2016
41,390 views
A computer system has an $L1$ cache, an $L2$ cache, and a main memory unit connected as shown below. The block size in $L1$ cache is $4$ words. The block size in $L2$ cac...