Course contentsShow
← Computer Science
Lesson 458 of 2,87211. Binary TreesFree lesson

Degree of a Node and Tree Degree

Counting the number of children a node has and determining the maximum degree in a tree.

Degree of a Node and Tree Degree

What you'll learn: How to count the number of children each node has and determine the maximum degree in any tree.


Understanding Node Degree

The degree of a node is simply the number of children that node has. It's a straightforward count:

  • A leaf node (which has no children) has degree 0
  • A node with one child has degree 1
  • A node with two children has degree 2
  • And so on...

Think of it like counting how many direct reports someone has in a company org chart. The CEO might have 5 vice presidents reporting directly to them (degree 5), while an individual contributor at the bottom has no one reporting to them (degree 0).

Tree Degree

The degree of a tree is the maximum degree among all nodes in that tree. In other words, find the node with the most children—that count is your tree's degree.

For example:

  • If your tree's busiest node has 3 children, and no other node has more, the tree degree is 3
  • In a binary tree (where every node has at most 2 children), the tree degree can never exceed 2

Why This Matters

Understanding node and tree degree helps you:

  • Classify trees: Binary trees have degree ≤ 2, ternary trees have degree ≤ 3
  • Analyze structure: A tree where most nodes have high degree is "wide and shallow"
  • Design data structures: The degree constraint affects how you implement tree nodes in code

Key Takeaway: The degree of a node counts its children; the degree of a tree is the maximum degree found among all its nodes, defining the tree's structural constraint.