Professional Documents
Culture Documents
Lecture 7 (Trees)
Lecture 7 (Trees)
Lecture 7 (Trees)
:محاضرات في مادة
Lecture # 7
Trees
Dr. Asim Abdallah Elshiekh, UofK, Fac. of Math. Sc., Computer Dept. Algorithms and Data Structures: Lecture (7)
Trees 154
Outline
• Introduction to Trees
Tree ADT.
Tree terminologies.
Dr. Asim Abdallah Elshiekh, UofK, Fac. of Math. Sc., Computer Dept. Algorithms and Data Structures: Lecture (7)
Trees 155
Trees
• Trees are data structures, that are composed of nodes organized by
references.
• The references are used to keep the nodes organized into a hierarchy.
Dr. Asim Abdallah Elshiekh, UofK, Fac. of Math. Sc., Computer Dept. Algorithms and Data Structures: Lecture (7)
Trees 156
Trees (cont…)
• A tree is a collection of nodes.
The collection can be empty.
(recursive definition) If not empty, a tree consists of:
a distinguished node r (the root).
Dr. Asim Abdallah Elshiekh, UofK, Fac. of Math. Sc., Computer Dept. Algorithms and Data Structures: Lecture (7)
Tree Terminologies 157
Some Terminologies
• Root:
Node without parent.
• Leaves:
Are nodes with no children.
• Siblings:
Nodes with same parent.
Dr. Asim Abdallah Elshiekh, UofK, Fac. of Math. Sc., Computer Dept. Algorithms and Data Structures: Lecture (7)
Tree Terminologies 158
Dr. Asim Abdallah Elshiekh, UofK, Fac. of Math. Sc., Computer Dept. Algorithms and Data Structures: Lecture (7)
Tree Terminologies 159
More Terminologies
• Path:
A sequence of edges.
• Length of a path:
Number of edges on the path.
• Depth of a node:
Length of the unique path from the root to that node.
OR, number of ancestors of a node.
• Height of a node:
Length of the longest path from that node to a leaf.
All leaves are at height 0.
• The height of a tree = the height of the root
= the depth of the deepest leaf
Dr. Asim Abdallah Elshiekh, UofK, Fac. of Math. Sc., Computer Dept. Algorithms and Data Structures: Lecture (7)
Tree Terminologies 160
Dr. Asim Abdallah Elshiekh, UofK, Fac. of Math. Sc., Computer Dept. Algorithms and Data Structures: Lecture (7)
Tree Terminologies 161
The level of any other node in the tree is one more than the
level of its father.
Dr. Asim Abdallah Elshiekh, UofK, Fac. of Math. Sc., Computer Dept. Algorithms and Data Structures: Lecture (7)
Tree Terminologies 162
(siblings)
leaves
Dr. Asim Abdallah Elshiekh, UofK, Fac. of Math. Sc., Computer Dept. Algorithms and Data Structures: Lecture (7)
Trees - Example 164