Photo AI
Last Updated Sep 27, 2025
Revision notes with simplified explanations to understand Trees quickly and effectively.
385+ students studying
A tree is a hierarchical data structure consisting of nodes. Trees are used to represent relationships, such as family trees, organisational charts, and file systems. In Computer Science, trees are widely used for efficient data searching, sorting, and hierarchical data representation.
A tree can be implemented dynamically using linked nodes.
Example: Pseudocode for a Binary Tree Node:
CLASS Node
DATA value
POINTER left
POINTER right
CLASS BinaryTree
POINTER root
METHOD Add(value)
IF root IS NULL
root ← NEW Node(value)
ELSE
CALL AddRecursive(root, value)
METHOD AddRecursive(current, value)
IF value < current.value
IF current.left IS NULL
current.left ← NEW Node(value)
ELSE
CALL AddRecursive(current.left, value)
ELSE
IF current.right IS NULL
current.right ← NEW Node(value)
ELSE
CALL AddRecursive(current.right, value)
A binary tree can also be implemented using an array where:
In post-order traversal, the nodes are visited in this order:
Left Subtree → Right Subtree → Root
Example Post-Order Traversal:
Given Tree:
A
/ \\
B C
/ \\
D E
Post-Order: D → E → B → C → A
Pseudocode for Post-Order Traversal:
METHOD PostOrder(node)
IF node IS NOT NULL
CALL PostOrder(node.left)
CALL PostOrder(node.right)
OUTPUT node.value
Also known as Level-Order Traversal, nodes are visited level by level, from left to right.
Example Breadth-First Traversal:
Given Tree:
A
/ \\
B C
/ \\
D E
Breadth-First: A → B → C → D → E
Pseudocode for Breadth-First Traversal:
METHOD BreadthFirst(root)
INITIALISE queue
ENQUEUE root
WHILE queue IS NOT EMPTY
current ← DEQUEUE queue
OUTPUT current.value
IF current.left IS NOT NULL
ENQUEUE current.left
IF current.right IS NOT NULL
ENQUEUE current.right
1. Start at the root. 2. Traverse left if the value is smaller or right if it is larger. 3. Insert the node at the appropriate leaf position.
1. If the node has no children: Remove it directly. 2. If the node has one child: Replace it with its child. 3. If the node has two children: Replace it with the in-order successor (smallest value in the right subtree).
Enhance your understanding with flashcards, quizzes, and exams—designed to help you grasp key concepts, reinforce learning, and master any topic with confidence!
120 flashcards
Flashcards on Trees
Revise key concepts with interactive flashcards.
Try Computer Science Flashcards12 quizzes
Quizzes on Trees
Test your knowledge with fun and engaging quizzes.
Try Computer Science Quizzes29 questions
Exam questions on Trees
Boost your confidence with real exam questions.
Try Computer Science Questions27 exams created
Exam Builder on Trees
Create custom exams across topics for better practice!
Try Computer Science exam builder12 papers
Past Papers on Trees
Practice past papers to reinforce exam experience.
Try Computer Science Past PapersDiscover More Revision Notes Related to Trees to Deepen Your Understanding and Improve Your Mastery
96%
114 rated
Algorithms for the Main Data Structures
Searching and Sorting Algorithms
481+ studying
196KViewsJoin 500,000+ A-Level students using SimpleStudy...
Join Thousands of A-Level Students Using SimpleStudy to Learn Smarter, Stay Organized, and Boost Their Grades with Confidence!
Report Improved Results
Recommend to friends
Students Supported
Questions answered