Professional Documents
Culture Documents
Structures
Introduction to Trees
Introduction to trees
Trees as a Tool
Understanding the terminology
Linear Lists and Trees
Hierarchical Data and Trees
Applications of Trees
Some more terminologies
Linear Lists And Trees
3
Linear lists are useful for serially ordered data.
(e0, e1, e2, …, en-1)
Days of week
Months in a year
Students in this class
Trees are useful for hierarchically ordered data
Structure of directories
Employees of a corporation
◼ President, vice presidents, managers, and so on
Linear vs Non-Linear Data
4
Structures
Nature of data
Cost of operations (insertion, searching, deletion)
Memory usage
The convention used in computer science is that roots are drawn on the
top. It may seem strange at the beginning but you'll get used to it
Root
root of
subtree
A subtree
More conventions
15
Due to the fact that we organize trees with root at the top
(as shown in previous slide) we will often hear
Node A is below node B
Node C is above node D
etc.
In fact, the most common way to refer to nodes based on
another node is use the idea of a family tree
Parent node
Children
Siblings
etc
16
Another Important Characteristic
Another characteristic of a tree which is that every node
(except the root) has only one node immediately above it
(one parent) but can have several immediately below
(children)
parent
node
children
Leaves
17
Leaves
Trees with specific number of children
18
B C D
E F G
Owner
Manager Chef
Manager Chef
Owner
Manager Chef
LEAF NODES
Sibling nodes have same parent
25
Owner
SIBLINGS
Manager Chef
Owner
Manager Chef
SIBLINGS
Tree Terminology
27
Owner
Manager Chef
SIBLINGS
A Tree Has Depths
28
Depth #0
Owner
Manager Chef
Owner
Owner
Manager Chef
Owner
Manager Chef
Owner
Manager Chef
ANOTHER SUBTREE
OF ROOT NODE
33
The End