Ora

What is the formula for the internal vertices of a tree?

Published in Tree Vertices Formula 4 mins read

The number of internal vertices in a full m-ary tree can be precisely determined by the formula $i = (n-1)/m$.

Understanding Internal Vertices in Trees

In the realm of tree data structures, a vertex (or node) is a fundamental component. These vertices can be categorized into two main types:

  • Internal Vertices (or Internal Nodes): These are any non-leaf vertices. An internal vertex is a node that has at least one child. In other words, it's not at the very end of a branch.
  • Leaves (or External Vertices/Nodes): These are vertices that have no children. They represent the endpoints of the tree branches.

The question of a specific formula for internal vertices often refers to a particular type of tree structure, as the properties vary.

The Formula for Full m-ary Trees

The most common context for a direct formula linking internal vertices to total vertices is found in a full m-ary tree.

What is a Full m-ary Tree?

A full m-ary tree is a special type of tree where every internal vertex has exactly m children. Here, m is an integer greater than or equal to 2, representing the maximum branching factor of the tree. For instance:

  • A full binary tree is a full m-ary tree where m=2 (every internal node has exactly 2 children).
  • A full ternary tree is a full m-ary tree where m=3 (every internal node has exactly 3 children).

This consistent branching pattern allows for a clear mathematical relationship between its components.

The Key Formulas

For a full m-ary tree:

  • Let i represent the number of internal vertices.
  • Let j represent the number of leaf vertices.
  • Let n represent the total number of vertices (i.e., $n = i + j$).
  • Let m represent the order of the tree (number of children per internal node).

The formula for the number of internal vertices (i) in a full m-ary tree, given the total number of vertices (n) and the order (m), is:

$$i = \frac{n-1}{m}$$

This formula can also be expressed in terms of the total number of vertices:

$$n = m \times i + 1$$

This relationship highlights that the total number of vertices in a full m-ary tree is directly determined by the number of internal vertices and the tree's order.

Relationship to Leaves

The number of leaves (j) in a full m-ary tree is also directly related to the number of internal vertices:

$$j = (m-1)i + 1$$

Combining these relationships, we can confirm the total vertices:
$n = i + j$
$n = i + ((m-1)i + 1)$
$n = i + mi - i + 1$
$n = mi + 1$

This consistency confirms the mathematical structure inherent in full m-ary trees.

Examples and Practical Applications

Let's illustrate these formulas with specific examples:

Example 1: Full Binary Tree (m=2)

For a full binary tree, $m=2$.

  • Formula for internal vertices: $i = \frac{n-1}{2}$
  • Formula for total vertices: $n = 2i + 1$
  • Formula for leaves: $j = (2-1)i + 1 = i + 1$

Scenario: If a full binary tree has 9 total vertices ($n=9$):
$i = (9-1)/2 = 8/2 = 4$ internal vertices.
$j = i + 1 = 4 + 1 = 5$ leaves.
Check: $n = i + j = 4 + 5 = 9$.

Example 2: Full Ternary Tree (m=3)

For a full ternary tree, $m=3$.

  • Formula for internal vertices: $i = \frac{n-1}{3}$
  • Formula for total vertices: $n = 3i + 1$
  • Formula for leaves: $j = (3-1)i + 1 = 2i + 1$

Scenario: If a full ternary tree has 10 total vertices ($n=10$):
$i = (10-1)/3 = 9/3 = 3$ internal vertices.
$j = 2i + 1 = 2(3) + 1 = 7$ leaves.
Check: $n = i + j = 3 + 7 = 10$.

Summary Table

The following table summarizes the key formulas for full m-ary trees:

Tree Type Order (m) Formula for Internal Vertices (i) Total Vertices (n) Formula for Leaves (j)
Full m-ary Tree $m$ $(n-1)/m$ $m \times i + 1$ $(m-1)i + 1$
Full Binary Tree $2$ $(n-1)/2$ $2i + 1$ $i + 1$
Full Ternary Tree $3$ $(n-1)/3$ $3i + 1$ $2i + 1$

These formulas are invaluable in fields like computer science for analyzing the efficiency of algorithms that use tree structures, determining memory requirements, and understanding the balance of different node types within these specific tree architectures.