CS211-Algorithms & Data
Structures
Taibah University
Dr. Sameer M. Alrehaili
College of Science and Computer Engineering, Yanbu
1
Trees
2
Tree
● It is a special kind of graph
● A tree is a collection of nodes connected by directed or undirected edges.
● A tree is a nonlinear data structure.
● Is used to represent hierarchical data
● If n nodes, (n-1) edges, one edge for each parent-child relationship
3
Non-linear data structure
● Hierarchical organisation ● Linux file system
4
Terminology
● In computer science, trees are normally
displayed upside-down, with the root
forming the top level.
● A tree consists of nodes (also called
vertices or points) and edges (also
called lines or arcs).
● Root: a node without any parent
● Internal node: a node with at least one
child
● External node: (or a leaf) a node without
children
● Subtree: tree consisting of node and its
descendants
●
5
Applications
6
Current state is [125340678]
Represent the follower nodes in this state
UP[120345678], Down [125348670]
Left [125304678]