+1 vote
in Data Structures & Algorithms I by (110k points)
What may be the psuedo code for finding the size of a tree?

(a) find_size(root_node–>left_node) + 1 + find_size(root_node–>right_node)

(b) find_size(root_node–>left_node) + find_size(root_node–>right_node)

(c) find_size(root_node–>right_node) – 1

(d) find_size(root_node–>left_node + 1

The above asked question is from Binary Trees using Linked Lists in chapter Binary Trees of Data Structures & Algorithms I

This question was posed to me in a job interview.

1 Answer

+1 vote
by (672k points)
selected by
Best answer
Correct choice is (a) find_size(root_node–>left_node) + 1 + find_size(root_node–>right_node)

Easy explanation - Draw a tree and analyze the expression. we are always taking size of left subtree and right subtree and adding root value(1) to it and finally printing size.

Related questions

Welcome to TalkJarvis QnA, a question-answer community website for the people by the people. On TalkJarvis QnA you can ask your doubts, curiosity, questions and whatever going in your mind either related to studies or others. Experts and people from different fields will answer.