Skip to content
Azhimathi Mayam logoDSA Study HubPCCST303 · KTU · S3
Module 3 · syllabusLesson live

Trees: terminology and representation

Tree vocabulary (root, leaf, degree, level, height…) and three ways to store a general tree.

Syllabus says: “Trees: Representation Of Trees”

On this page · 7 sections
ormakkurippu ✎
Never-forget card

A tree is an upside-down coconut tree: ROOT at the top, LEAVES at the bottom. Degree = number of children; height = longest root-to-leaf path.

Picture it

Your family tree: grandparents at the root, parents below, cousins are siblings' children, and the youngest kids with no children are leaves.

Write this in the exam

A tree is a finite set of one or more nodes with a specially designated root, where the remaining nodes are partitioned into n ≥ 0 disjoint sets T₁…Tₙ, each of which is itself a tree (subtree).

മുകളിൽ വേര് (root), താഴെ ഇലകൾ (leaves) — തലകീഴായ മരം!

What you will be able to do

  • Use tree terminology correctly.
  • Represent a general tree as a list, with k-ary nodes, and as left-child right-sibling.

Terminology

EBFAGC
Example: A is the root; B and C are children of A (siblings); E, F, G are leaves.
TermMeaningIn the picture
Rootthe topmost node, with no parentA
Parent / childa node and the nodes directly below itB is the parent of E and F
Siblingschildren of the same parentE and F
Leaf (terminal)a node with no childrenE, F, G
Degree of a nodenumber of its childrendeg(B) = 2, deg(C) = 1
Degree of the treemaximum node degree2
Levelroot is level 1 (some books use 0); children are one level lowerE is at level 3
Height / depth of treemaximum level of any node3
Ancestors / descendantsall nodes on the path to the root / below a nodeancestors of E: B, A
Foresta set of disjoint treesremove A → two trees

Three representations of a general tree

Take a general tree: A has children B, C and D; B has E and F; D has G, H and I.

1. List representation

(A (B (E, F), C, D (G, H, I)))

2. Node with k child fields

Give every node as many link fields as the degree k of the tree. Simple, but wasteful: a tree with n nodes has nk links, of which only n − 1 are used, so n(k − 1) + 1 links are NULL.

3. Left-child right-sibling

Each node keeps just two links: its leftmost child and its next sibling to the right. Every general tree becomes a binary tree this way.

EFBCGHIDA
Left link = first child, right link = next sibling. B→C→D are siblings in a right chain; E→F and G→H→I likewise.

Quick check — can you get them all?

Question 1

Q1.A node with no children is called…

Question 2

Q2.The degree of a TREE is…

Question 3

Q3.Left-child right-sibling turns any tree into…

Practice

Every visualizer has a Practice mode: predict the next state before the animation reveals it. You can also work through the topic's question set on the practice page.

Exam-ready summary

  • Root, parent, child, sibling, leaf, degree (node / tree), level, height, ancestor, forest.
  • List form: (A (B (E, F), C, D (…))).
  • k-ary nodes waste n(k − 1) + 1 links.
  • Left-child right-sibling → binary tree.

References

  • Horowitz, Sahni & Anderson-Freed, Fundamentals of Data Structures in C, 2/e — §5.1 (Introduction to trees)

Explanations on this page are original. Textbook references point to where the standard treatment can be read; no text is reproduced from them.

Prefer revising from notes? Module-wise notes and question papers on Azhimathi Mayam (opens in a new tab)