View
220
Download
5
Category
Tags:
Preview:
Citation preview
Joseph Lindo
Trees
Sir Joseph LindoUniversity of the Cordilleras
Joseph Lindo
BST
Cases
Traversals
Binary Tree
Trees
Course TitleTree
In computer science, a tree is an abstract model of a hierarchical structure
Trees
Joseph Lindo
BST
Cases
Traversals
Binary Tree
Trees
Course TitleBinary Tree
A binary tree is a finite set of elements that is either empty or is partitioned into three disjoint subsets.
The other two subsets are themselves binary trees called the left and right subtrees.
Binary Trees
Joseph Lindo
BST
Cases
Traversals
Binary Tree
Trees
Course TitleBinary Tree
The other two subsets are themselves binary trees called the left and right subtrees.
• Ordered Tree• Full binary tree• Skewed binary tree
Binary Trees
Joseph Lindo
BST
Cases
Traversals
Binary Tree
Trees
Course TitleBinary SearchTree• All identifiers in the left
subtree are less than the identifier in the root node
• All identifiers in the right subtree are greater than the identifier in the root node
BST
Joseph Lindo
BST
Cases
Traversals
Binary Tree
Trees
Course TitleTraversing• It is the process of visiting
each node in a tree exactly one.
Common traversals:Traversals
Joseph Lindo
BST
Cases
Traversals
Binary Tree
Trees
Course TitleTraversals• Preorder
Node - Left - Right • InorderLeft - Node -Right
• PostorderLeft - Right - Node• Level - order
Traversals
Want an easy way to do INORDER
Traversal?
SQUISHING
Joseph Lindo
Trees
-- end --Sir Joseph Lindo
University of the Cordilleras
Joseph Lindo
Trees
-- end na --Sir Joseph Lindo
University of the Cordilleras
Joseph Lindo
Applications
Tree
Organization charts
File systems Programming
environments
Joseph Lindo
Terminologies
Tree
Node Root Node Parent Node Siblings Internal Node External
Node/Leaf/ Terminal
Joseph Lindo
Terminologies
Tree
Ancestors Descendants Subtree Level Depth Height Degree Weigth
Joseph Lindo
Properties
Binary Tree
• 2i-1: maximum number of nodes on level I of a binary tree
• 2k-1: maximum number of nodes in a binary tree of height k
Joseph Lindo
Examples
Traversals
Joseph Lindo
Squishing
INORDER Traversal
Joseph Lindo
Level - Order
Traversal
Joseph Lindo
Trees
-- end --Sir Joseph Lindo
University of the Cordilleras
Joseph Lindo
Trees
-- end na --Sir Joseph Lindo
University of the Cordilleras
Joseph Lindo
Examples
Recommended