All Exams Test series for 1 year @ ₹349 only
Question

In a ternary tree, the number of internal nodes of degree 1,2 and 3 is 4,3 and 3 respectively. The number of leaf nodes in the ternary tree is

The correct answer is

10

Finding the Number of Leaf Nodes in a Ternary Tree

This problem asks us to find the number of leaf nodes in a ternary tree, given information about its internal nodes based on their degrees.

Understanding Key Concepts

Before diving into the calculation, let's clarify some terms related to trees:

  • Ternary Tree: A type of tree data structure where each node has at most three children.
  • Internal Node: Any node in the tree that is not a leaf node. These nodes have one or more children.
  • Leaf Node: A node that has no children. These are the nodes at the "end" of the branches.
  • Degree of an Internal Node: In the context of a rooted tree, the degree of an internal node refers specifically to the number of its children.

Analyzing the Given Information

We are told the number of internal nodes for each specific degree:

  • Number of internal nodes with degree 1 = 4
  • Number of internal nodes with degree 2 = 3
  • Number of internal nodes with degree 3 = 3

Our goal is to determine the total number of leaf nodes in this ternary tree.

Method for Calculating Leaf Nodes

In any rooted tree, there is a useful relationship between the number of internal nodes and the number of leaf nodes. For a rooted tree where each internal node \( i \) has \( \text{degree}_i \) children, the number of leaf nodes \( L \) can be found using the formula:

\[ L = 1 + \sum_{\text{all internal nodes } i} (\text{degree}_i - 1) \]

This formula sums the quantity \( (\text{degree}_i - 1) \) for every internal node and adds 1 (representing the contribution from the root which doesn't have a parent edge contributing to node count from above).

Let's calculate the sum \( \sum (\text{degree}_i - 1) \) based on the given internal node counts:

  • For the 4 internal nodes of degree 1: The contribution is \( 4 \times (1 - 1) = 4 \times 0 = 0 \).
  • For the 3 internal nodes of degree 2: The contribution is \( 3 \times (2 - 1) = 3 \times 1 = 3 \).
  • For the 3 internal nodes of degree 3: The contribution is \( 3 \times (3 - 1) = 3 \times 2 = 6 \).

Now, we sum these contributions for all internal nodes:

\[ \sum (\text{degree}_i - 1) = 0 + 3 + 6 = 9 \]

Now, we plug this sum into the formula for the number of leaf nodes \( L \):

\[ L = 1 + \sum (\text{degree}_i - 1) \] \[ L = 1 + 9 \] \[ L = 10 \]

So, the number of leaf nodes in the ternary tree is 10.

Alternatively, we can use the fact that in any tree, the number of edges \( E \) is \( N - 1 \), where \( N \) is the total number of nodes. Also, in a rooted tree, the total number of edges is equal to the sum of the degrees (number of children) of all internal nodes.

Total number of internal nodes \( I = 4 + 3 + 3 = 10 \).

Total number of children = Sum of degrees of internal nodes

\[ \text{Total children} = (4 \times 1) + (3 \times 2) + (3 \times 3) = 4 + 6 + 9 = 19 \]

Since the total number of children equals the number of edges in a rooted tree (as each edge connects a parent to a child), we have:

\[ E = 19 \]

Using the relation \( E = N - 1 \):

\[ 19 = N - 1 \] \[ N = 19 + 1 = 20 \]

The total number of nodes \( N \) is the sum of internal nodes (\( I \)) and leaf nodes (\( L \)).

\[ N = I + L \] \[ 20 = 10 + L \] \[ L = 20 - 10 = 10 \]

Both methods yield the same result.

Conclusion

The number of leaf nodes in the ternary tree is 10.

Revision Table: Ternary Tree Node Distribution

Node Type Degree (Number of Children) Count Calculation Contribution (\( \text{degree} - 1 \))
Internal 1 4 \( 4 \times (1-1) = 0 \)
Internal 2 3 \( 3 \times (2-1) = 3 \)
Internal 3 3 \( 3 \times (3-1) = 6 \)
Total Internal Nodes 10 Sum \( = 9 \)
Leaf 0 10 (Calculated)
Total Nodes (Internal + Leaf) 20

Additional Information: Rooted Tree Properties

Rooted trees have several fundamental properties:

  • A unique node is designated as the root.
  • Every node except the root has exactly one parent.
  • The degree of a node typically refers to the number of its children in a rooted tree context.
  • Nodes with degree 0 are leaf nodes. Nodes with degree > 0 are internal nodes.
  • For any tree with \( N \) nodes, there are exactly \( N-1 \) edges.
  • The total number of children across all nodes in a rooted tree is equal to the number of edges, which is \( N-1 \). This is because each edge connects a parent to a child, and every node except the root is a child to exactly one parent.
Was this answer helpful?
Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App