SlideShare a Scribd company logo
Trees
Definition: Let 𝐴𝐴 be a set, and let 𝑇𝑇 be a relation on 𝐴𝐴.
We say that 𝑇𝑇 is a tree if there is a vertex 𝑣𝑣0 in 𝐴𝐴 with
the property that
1) there exists a unique path in 𝑇𝑇 from 𝑣𝑣0 to every
other vertex in 𝐴𝐴,
2) no path from 𝑣𝑣0 to 𝑣𝑣0.
Definition: 𝑣𝑣0 is called the root of the tree, and T is
referred to as a rooted tree denoted by 𝑇𝑇, 𝑣𝑣0 .
Trees
© S. Turaev, CSC 1700 Discrete Mathematics 2
Theorem: Let 𝑇𝑇, 𝑣𝑣0 be a rooted tree. Then
1. There are no cycle in 𝑇𝑇.
2. Vertex 𝑣𝑣0 is the only root of 𝑇𝑇.
3. Each vertex in 𝑇𝑇, other than 𝑣𝑣0,
has in-degree one, and 𝑣𝑣0 has in-degree zero.
Trees
© S. Turaev, CSC 1700 Discrete Mathematics 3
Levels, Parent-Offspring, Siblings
© S. Turaev, CSC 1700 Discrete Mathematics
2
1
5
3 4
6
7
Level 1 vertices: the vertices of
the edges beginning at 𝑣𝑣0 (level 0)
Level 𝑘𝑘 vertices: the vertices of the
edges beginning at those level 𝑘𝑘 − 1
vertices
Parent-offspring: for all pairs (𝑎𝑎, 𝑏𝑏) in 𝑇𝑇,
𝑎𝑎 is called the parent of 𝑏𝑏 and 𝑏𝑏 is called
the offspring of 𝑎𝑎
Siblings: the vertices that have the same
parent
Height of a tree: the largest level number
of a tree
Leaves: the vertices that have no
offspring
4
Levels, Parent-Offspring, Siblings
© S. Turaev, CSC 1700 Discrete Mathematics
2
1
5
3 4
6
7
Level 0
Level 1
Level 2
Level 3
Height 3Leaf
Root
Child /
Offspring
Parent
Siblings
5
Theorem: Let 𝑇𝑇, 𝑣𝑣0 be a rooted tree. Then
 𝑇𝑇 is irreflexive
 𝑇𝑇 is asymmetric
 If 𝑎𝑎, 𝑏𝑏 in 𝑇𝑇 and 𝑏𝑏, 𝑐𝑐 in 𝑇𝑇, then 𝑎𝑎, 𝑐𝑐 is not
in 𝑇𝑇, for all 𝑎𝑎, 𝑏𝑏 and 𝑐𝑐 in 𝐴𝐴.
Trees
© S. Turaev, CSC 1700 Discrete Mathematics 6
Example: Let 𝐴𝐴 = 𝑣𝑣1, 𝑣𝑣2, 𝑣𝑣3, … , 𝑣𝑣10 and let
𝑇𝑇 =
𝑣𝑣2, 𝑣𝑣3 , 𝑣𝑣2, 𝑣𝑣1 , 𝑣𝑣4, 𝑣𝑣5 , 𝑣𝑣4, 𝑣𝑣6 ,
𝑣𝑣5, 𝑣𝑣8 , 𝑣𝑣6, 𝑣𝑣7 , 𝑣𝑣4, 𝑣𝑣2 , 𝑣𝑣7, 𝑣𝑣9 , 𝑣𝑣7, 𝑣𝑣10
Show that 𝑇𝑇 is a rooted tree and identify the root.
Trees
© S. Turaev, CSC 1700 Discrete Mathematics 7
Definition:
 If 𝑛𝑛 is a positive integer, we say that a tree is an 𝑛𝑛-
tree if every vertex has at most 𝑛𝑛 offspring.
 A 2-tree is called a binary tree.
Definition:
 If all vertices of 𝑇𝑇, other than the leaves, have
exactly 𝑛𝑛 offspring, we say that 𝑇𝑇 is a complete
𝑛𝑛-tree.
 A complete 2-tree is called a completed binary tree.
𝒏𝒏-trees
© S. Turaev, CSC 1700 Discrete Mathematics 8
 Let 𝑇𝑇, 𝑣𝑣0 be a rooted tree on the set 𝐴𝐴, and let 𝑣𝑣
be a vertex of 𝑇𝑇.
 Let 𝐵𝐵 be the set consisting of 𝑣𝑣 and all its
descendants, i.e., all vertices of 𝑇𝑇 that can be reached
by a path beginning at 𝑣𝑣.
 Let 𝑇𝑇 𝑣𝑣 be the restriction of the relation 𝑇𝑇 to 𝐵𝐵,
that is 𝑇𝑇 ∩ (𝐵𝐵 × 𝐵𝐵).
 Delete all vertices that are not descendants of 𝑣𝑣 and all
edges that do not begin and end at any such vertex.
Subtrees
© S. Turaev, CSC 1700 Discrete Mathematics 9
Theorem: If 𝑇𝑇, 𝑣𝑣0 is a rooted tree and 𝑣𝑣 in 𝑇𝑇, then
𝑇𝑇 𝑣𝑣 is also a rooted tree with root 𝑣𝑣.
We will say that 𝑇𝑇 𝑣𝑣 is the subtree of 𝑇𝑇 beginning at 𝑣𝑣.
Subtrees
© S. Turaev, CSC 1700 Discrete Mathematics
2 31
0
4 5
6
10
Theorem: If 𝑇𝑇, 𝑣𝑣0 is a rooted tree and 𝑣𝑣 in 𝑇𝑇, then
𝑇𝑇 𝑣𝑣 is also a rooted tree with root 𝑣𝑣.
We will say that 𝑇𝑇 𝑣𝑣 is the subtree of 𝑇𝑇 beginning at 𝑣𝑣.
Subtrees
© S. Turaev, CSC 1700 Discrete Mathematics
2
0
4 5
6
11
Exercise 1: Determine if 𝑅𝑅 is a tree and, if it is, find the
root.
 𝐴𝐴 = 𝑎𝑎, 𝑏𝑏, 𝑐𝑐, 𝑑𝑑, 𝑒𝑒
𝑅𝑅 = 𝑎𝑎, 𝑑𝑑 , 𝑏𝑏, 𝑐𝑐 , 𝑐𝑐, 𝑎𝑎 , 𝑑𝑑, 𝑒𝑒
 𝐴𝐴 = 1, 2, 3, 4, 5, 6
𝑅𝑅 = 2,1 , 3,4 , 5,2 , 6,5 , 6,3
Exercises
© S. Turaev, CSC 1700 Discrete Mathematics 12
Exercise 2: Consider the rooted tree 𝑇𝑇, 0 .
Exercises
© S. Turaev, CSC 1700 Discrete Mathematics
0
1 2
4 5 6 8 9
10
11 12
7
3
13 14
15
13
Exercise 2: Consider the rooted tree 𝑇𝑇, 0 .
1. List all level-3 vertices
2. List all leaves
3. What are the siblings of 8?
4. What are the descendants of 3?
5. Compute 𝑇𝑇 2
6. Compute 𝑇𝑇 3
7. What is the height of 𝑇𝑇, 0 ?
Exercises
© S. Turaev, CSC 1700 Discrete Mathematics 14
Example: Use a tree to denote the following algebraic
expression
3 − 2 × 𝑏𝑏 + 𝑏𝑏 − 2 − 3 + 𝑏𝑏
Labeled Trees
© S. Turaev, CSC 1700 Discrete Mathematics
+
- -
3
2 b
x -
b 2 3 b
+
15
Example: Use a tree to denote the following algebraic
expression
3 × 1 − 𝑎𝑎 ÷ 4 + 7 − 𝑏𝑏 + 2 × 7 + 𝑎𝑎 ÷ 𝑏𝑏
Labeled Trees
© S. Turaev, CSC 1700 Discrete Mathematics 16
Positional 𝑛𝑛-tree:
• 𝑛𝑛-tree: every vertex has at most 𝑛𝑛 offspring
• positional 𝑛𝑛-tree: label the offspring of a given
vertex from left to right with numbers 1,2, … , 𝑛𝑛
• some of the offspring in the sequence may be
missing
Labeled Trees
© S. Turaev, CSC 1700 Discrete Mathematics 17
Example: positional 3-tree:
Labeled Trees
© S. Turaev, CSC 1700 Discrete Mathematics
2
2
3
3
3
1 1
3
2 31
2 31
18
Example: positional 2-tree:
Labeled Trees
© S. Turaev, CSC 1700 Discrete Mathematics
L R
L
R
R L
L L R
R
19
Visiting
Performing appropriate tasks at a vertex will be
called visiting the vertex.
Tree search
The process of visiting each vertex of a tree in some
specific order will be called searching the tree or
performing a tree search.
Tree Searching
© S. Turaev, CSC 1700 Discrete Mathematics 20
Algorithm PREORDER
Step 1: Visit 𝑣𝑣
Step 2: If 𝑣𝑣𝐿𝐿 exists, then apply this algorithm to
𝑇𝑇 𝑣𝑣𝐿𝐿 , 𝑣𝑣𝐿𝐿
Step 3: If 𝑣𝑣𝑅𝑅 exists, then apply this algorithm to
𝑇𝑇 𝑣𝑣𝑅𝑅 , 𝑣𝑣𝑅𝑅
Tree Searching
© S. Turaev, CSC 1700 Discrete Mathematics 21
Example 1
Tree Searching
© S. Turaev, CSC 1700 Discrete Mathematics
A
B
C
D F
E
G J
I
L
K
H
1
2
3
4
5 6
7
8
9
10
11
A B C D E F G H I J K L
22
Example 2: 𝑎𝑎 − 𝑏𝑏 × 𝑐𝑐 + 𝑑𝑑/𝑒𝑒
Tree Searching
© S. Turaev, CSC 1700 Discrete Mathematics
×
-
a b
e
/
+
c
d
× - a b + c / d e
1
2 3
4
5
7 8
6
23
Prefix or Polish form:
× − 𝑎𝑎 𝑏𝑏 + 𝑐𝑐 / 𝑑𝑑 𝑒𝑒 (𝑎𝑎 = 6, 𝑏𝑏 = 4, 𝑐𝑐 = 5, 𝑑𝑑 = 2, 𝑒𝑒 = 2)
1. × −6 4 + 5 / 2 2
2. × 2 + 5 / 2 2 replacing −6 4 by 2 since 6 − 4 = 2
3. × 2 + 5 1 replacing / 2 2 by 1 since 2/2 = 1
4. × 2 6 replacing + 5 1 by 6 since 5 + 1 = 6
5. 12 replacing × 2 6 by 12 since
2 × 6 = 12
Tree Searching
© S. Turaev, CSC 1700 Discrete Mathematics 24
Algorithm INORDER
Step 1: Search the left subtree 𝑇𝑇 𝑣𝑣𝐿𝐿 , 𝑣𝑣𝐿𝐿 , if it exists
Step 2: Visit the root 𝑣𝑣
Step 3: Search the right subtree 𝑇𝑇 𝑣𝑣𝑅𝑅 , 𝑣𝑣𝑅𝑅 , if it exists
Tree Searching
© S. Turaev, CSC 1700 Discrete Mathematics 25
Algorithm POSTORDER
Step 1: Search the left subtree 𝑇𝑇 𝑣𝑣𝐿𝐿 , 𝑣𝑣𝐿𝐿 , if it exists
Step 2: Search the right subtree 𝑇𝑇 𝑣𝑣𝑅𝑅 , 𝑣𝑣𝑅𝑅 , if it exists
Step 3: Visit the root 𝑣𝑣
Tree Searching
© S. Turaev, CSC 1700 Discrete Mathematics 26
Example: Traveling the tree using INORDER and
POSTORDER
𝑎𝑎 − 𝑏𝑏 × 𝑐𝑐 + 𝑑𝑑/𝑒𝑒
Tree Searching
© S. Turaev, CSC 1700 Discrete Mathematics
×
-
a b
e
/
+
c
d
INORDER: 𝑎𝑎 − 𝑏𝑏 × 𝑐𝑐 + 𝑑𝑑/𝑒𝑒
POSTORDER: 𝑎𝑎 𝑏𝑏 − 𝑐𝑐 𝑑𝑑 𝑒𝑒 / +×
27
Infix notation: Algebraic symbols lie between their
arguments
𝑎𝑎 − 𝑏𝑏 × 𝑐𝑐 + 𝑑𝑑 / 𝑒𝑒
(𝑎𝑎 − 𝑏𝑏) × (𝑐𝑐 + (𝑑𝑑/𝑒𝑒))
or
𝑎𝑎 − (𝑏𝑏 × ( 𝑐𝑐 + 𝑑𝑑 /𝑒𝑒))
Tree Searching
© S. Turaev, CSC 1700 Discrete Mathematics 28
Postfix or reverse Polish:
𝑎𝑎 𝑏𝑏 − 𝑐𝑐 𝑑𝑑 𝑒𝑒 / + × (𝑎𝑎 = 2, 𝑏𝑏 = 1, 𝑐𝑐 = 3, 𝑑𝑑 = 4, 𝑒𝑒 = 2)
1. 2 1 − 3 4 2 / + ×
2. 1 3 4 2 / + × replacing 2 1 − with 1 since 2 − 1 = 1
3. 1 3 2 + × replacing 4 2 / with 2 since 4/2 = 2
4. 1 5 × replacing 3 2 + with 5 since 3 + 2 = 5
5. 5 replacing 1 5 × with 5 since 1 × 5 =5
Tree Searching
© S. Turaev, CSC 1700 Discrete Mathematics 29
Show the result of performing a preorder search of the
tree
Exercises
© S. Turaev, CSC 1700 Discrete Mathematics
x
y
s
z
t
u
v
30
Show the result of performing an inorder search of the
tree
Exercises
© S. Turaev, CSC 1700 Discrete Mathematics
x
y
s
z
t
u
v
31
Show the result of performing a postorder search of the
tree
Exercises
© S. Turaev, CSC 1700 Discrete Mathematics
x
y
s
z
t
u
v
32
Show the result of performing preorder, inorder and
postorder searches of the tree
𝑇𝑇 =
𝑎𝑎, 𝑏𝑏 , 𝑎𝑎, 𝑑𝑑 , 𝑏𝑏, 𝑐𝑐 , 𝑏𝑏, 𝑖𝑖 , 𝑑𝑑, 𝑘𝑘 , 𝑑𝑑, 𝑒𝑒 ,
𝑐𝑐, 𝑔𝑔 , 𝑐𝑐, ℎ , 𝑒𝑒, 𝑗𝑗 , 𝑒𝑒, 𝑓𝑓
Exercises
© S. Turaev, CSC 1700 Discrete Mathematics 33
Show the result of performing preorder, inorder and
postorder searches of the tree
𝑇𝑇 = 1,2 , 1,3 , 2,4 , 3,5 , 4,6 , 5,7
Exercises
© S. Turaev, CSC 1700 Discrete Mathematics 34
Evaluate the expressions, which are given in Polish, or
prefix, notation
• × − + 3 4 − 7 2 ÷ 12 × 3 − 6 4
• ÷ − × 3 2 × 4 3 + 15 × 2 − 6 × 3
Exercises
© S. Turaev, CSC 1700 Discrete Mathematics 35
Evaluate the expressions, which are given in reverse
Polish, or postfix, notation
• 4 3 2 ÷ − 5 × 4 2 × 5 × 3 ÷ ÷
• 3 7 × 4 − 9 × 6 5 × 2 + ÷
Exercises
© S. Turaev, CSC 1700 Discrete Mathematics 36
Draw a binary tree whose preorder search produces
• JBACDIHEGF
• CATSANDDOGS
Draw a binary tree whose postorder search produces
• SEARCHING
• TREEHOUSE
Exercises
© S. Turaev, CSC 1700 Discrete Mathematics 37

More Related Content

What's hot

Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)
United International University
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
Mohamed Loey
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Bubble sort
Bubble sortBubble sort
Bubble sort
Manek Ar
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructure
rajshreemuthiah
 
Binary tree
Binary treeBinary tree
Binary tree
Rajendran
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
 
Lecture 01 dld 2018
Lecture 01 dld  2018Lecture 01 dld  2018
Lecture 01 dld 2018
Tanveer Hussain
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
Ashim Lamichhane
 
Sorting
SortingSorting
Binary tree
Binary  treeBinary  tree
Binary tree
Vanitha Chandru
 
Recursion - Algorithms and Data Structures
Recursion - Algorithms and Data StructuresRecursion - Algorithms and Data Structures
Recursion - Algorithms and Data Structures
Priyanka Rana
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary search
Zia Ush Shamszaman
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
Sumit Gupta
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
Hossain Md Shakhawat
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
Rajendra Dangwal
 
Prim's algorithm
Prim's algorithmPrim's algorithm
Prim's algorithm
Pankaj Thakur
 
Insertion sort algorithm power point presentation
Insertion  sort algorithm power point presentation Insertion  sort algorithm power point presentation
Insertion sort algorithm power point presentation
University of Science and Technology Chitttagong
 
3. mining frequent patterns
3. mining frequent patterns3. mining frequent patterns
3. mining frequent patterns
Azad public school
 
Symbolic Mathematics
Symbolic Mathematics Symbolic Mathematics
Symbolic Mathematics
saadurrehman35
 

What's hot (20)

Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructure
 
Binary tree
Binary treeBinary tree
Binary tree
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Lecture 01 dld 2018
Lecture 01 dld  2018Lecture 01 dld  2018
Lecture 01 dld 2018
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
Sorting
SortingSorting
Sorting
 
Binary tree
Binary  treeBinary  tree
Binary tree
 
Recursion - Algorithms and Data Structures
Recursion - Algorithms and Data StructuresRecursion - Algorithms and Data Structures
Recursion - Algorithms and Data Structures
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary search
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
 
Prim's algorithm
Prim's algorithmPrim's algorithm
Prim's algorithm
 
Insertion sort algorithm power point presentation
Insertion  sort algorithm power point presentation Insertion  sort algorithm power point presentation
Insertion sort algorithm power point presentation
 
3. mining frequent patterns
3. mining frequent patterns3. mining frequent patterns
3. mining frequent patterns
 
Symbolic Mathematics
Symbolic Mathematics Symbolic Mathematics
Symbolic Mathematics
 

Similar to Trees (slides)

Relations digraphs
Relations  digraphsRelations  digraphs
Relations digraphs
IIUM
 
Counting i (slides)
Counting i (slides)Counting i (slides)
Counting i (slides)
IIUM
 
Pattern_avoidance_in_ternary_trees
Pattern_avoidance_in_ternary_treesPattern_avoidance_in_ternary_trees
Pattern_avoidance_in_ternary_trees
Nathan Gabriel
 
Recurrence relations
Recurrence relationsRecurrence relations
Recurrence relations
IIUM
 
B.TECH Math project
B.TECH Math projectB.TECH Math project
B.TECH Math project
arunsarkar9
 
Triangles’ Theorems.pptx
Triangles’ Theorems.pptxTriangles’ Theorems.pptx
Triangles’ Theorems.pptx
DanielEsparza43
 
Logic (slides)
Logic (slides)Logic (slides)
Logic (slides)
IIUM
 
Integers and matrices (slides)
Integers and matrices (slides)Integers and matrices (slides)
Integers and matrices (slides)
IIUM
 
trees-and-forest.pdf
trees-and-forest.pdftrees-and-forest.pdf
trees-and-forest.pdf
albertfernandez44
 
Bounds on inverse domination in squares of graphs
Bounds on inverse domination in squares of graphsBounds on inverse domination in squares of graphs
Bounds on inverse domination in squares of graphs
eSAT Journals
 
Seven trees in one
Seven trees in oneSeven trees in one
Seven trees in one
Mark Hopkins
 
Module 1 (Part 1)-Sets and Number Systems.pdf
Module 1 (Part 1)-Sets and Number Systems.pdfModule 1 (Part 1)-Sets and Number Systems.pdf
Module 1 (Part 1)-Sets and Number Systems.pdf
GaleJean
 
COMPUTING WIENER INDEX OF FIBONACCI WEIGHTED TREES
COMPUTING WIENER INDEX OF FIBONACCI WEIGHTED TREESCOMPUTING WIENER INDEX OF FIBONACCI WEIGHTED TREES
COMPUTING WIENER INDEX OF FIBONACCI WEIGHTED TREES
cscpconf
 
Split block domination in graphs
Split block domination in graphsSplit block domination in graphs
Split block domination in graphs
eSAT Journals
 
7 Trees.pptx
7 Trees.pptx7 Trees.pptx
7 Trees.pptx
MuhammadHazwanJamal
 
Lecture Notes: EEEC4340318 Instrumentation and Control Systems - Stability a...
Lecture Notes:  EEEC4340318 Instrumentation and Control Systems - Stability a...Lecture Notes:  EEEC4340318 Instrumentation and Control Systems - Stability a...
Lecture Notes: EEEC4340318 Instrumentation and Control Systems - Stability a...
AIMST University
 
lec6.ppt
lec6.pptlec6.ppt
SETS PPT-XI.pptx
SETS PPT-XI.pptxSETS PPT-XI.pptx
SETS PPT-XI.pptx
TamannaNayak5
 
Set theory
Set theorySet theory
Set theory
AN_Rajin
 
lec35.ppt
lec35.pptlec35.ppt

Similar to Trees (slides) (20)

Relations digraphs
Relations  digraphsRelations  digraphs
Relations digraphs
 
Counting i (slides)
Counting i (slides)Counting i (slides)
Counting i (slides)
 
Pattern_avoidance_in_ternary_trees
Pattern_avoidance_in_ternary_treesPattern_avoidance_in_ternary_trees
Pattern_avoidance_in_ternary_trees
 
Recurrence relations
Recurrence relationsRecurrence relations
Recurrence relations
 
B.TECH Math project
B.TECH Math projectB.TECH Math project
B.TECH Math project
 
Triangles’ Theorems.pptx
Triangles’ Theorems.pptxTriangles’ Theorems.pptx
Triangles’ Theorems.pptx
 
Logic (slides)
Logic (slides)Logic (slides)
Logic (slides)
 
Integers and matrices (slides)
Integers and matrices (slides)Integers and matrices (slides)
Integers and matrices (slides)
 
trees-and-forest.pdf
trees-and-forest.pdftrees-and-forest.pdf
trees-and-forest.pdf
 
Bounds on inverse domination in squares of graphs
Bounds on inverse domination in squares of graphsBounds on inverse domination in squares of graphs
Bounds on inverse domination in squares of graphs
 
Seven trees in one
Seven trees in oneSeven trees in one
Seven trees in one
 
Module 1 (Part 1)-Sets and Number Systems.pdf
Module 1 (Part 1)-Sets and Number Systems.pdfModule 1 (Part 1)-Sets and Number Systems.pdf
Module 1 (Part 1)-Sets and Number Systems.pdf
 
COMPUTING WIENER INDEX OF FIBONACCI WEIGHTED TREES
COMPUTING WIENER INDEX OF FIBONACCI WEIGHTED TREESCOMPUTING WIENER INDEX OF FIBONACCI WEIGHTED TREES
COMPUTING WIENER INDEX OF FIBONACCI WEIGHTED TREES
 
Split block domination in graphs
Split block domination in graphsSplit block domination in graphs
Split block domination in graphs
 
7 Trees.pptx
7 Trees.pptx7 Trees.pptx
7 Trees.pptx
 
Lecture Notes: EEEC4340318 Instrumentation and Control Systems - Stability a...
Lecture Notes:  EEEC4340318 Instrumentation and Control Systems - Stability a...Lecture Notes:  EEEC4340318 Instrumentation and Control Systems - Stability a...
Lecture Notes: EEEC4340318 Instrumentation and Control Systems - Stability a...
 
lec6.ppt
lec6.pptlec6.ppt
lec6.ppt
 
SETS PPT-XI.pptx
SETS PPT-XI.pptxSETS PPT-XI.pptx
SETS PPT-XI.pptx
 
Set theory
Set theorySet theory
Set theory
 
lec35.ppt
lec35.pptlec35.ppt
lec35.ppt
 

More from IIUM

How to use_000webhost
How to use_000webhostHow to use_000webhost
How to use_000webhost
IIUM
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
IIUM
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
IIUM
 
Kreydle internship-multimedia
Kreydle internship-multimediaKreydle internship-multimedia
Kreydle internship-multimedia
IIUM
 
03phpbldgblock
03phpbldgblock03phpbldgblock
03phpbldgblock
IIUM
 
Chap2 practice key
Chap2 practice keyChap2 practice key
Chap2 practice key
IIUM
 
Group p1
Group p1Group p1
Group p1
IIUM
 
Tutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seoTutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seo
IIUM
 
Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009
IIUM
 
03 the htm_lforms
03 the htm_lforms03 the htm_lforms
03 the htm_lforms
IIUM
 
Exercise on algo analysis answer
Exercise on algo analysis   answerExercise on algo analysis   answer
Exercise on algo analysis answer
IIUM
 
Redo midterm
Redo midtermRedo midterm
Redo midterm
IIUM
 
Heaps
HeapsHeaps
Heaps
IIUM
 
Report format
Report formatReport format
Report format
IIUM
 
Edpuzzle guidelines
Edpuzzle guidelinesEdpuzzle guidelines
Edpuzzle guidelines
IIUM
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
IIUM
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
IIUM
 
Group assignment 1 s21516
Group assignment 1 s21516Group assignment 1 s21516
Group assignment 1 s21516
IIUM
 
Avl tree-rotations
Avl tree-rotationsAvl tree-rotations
Avl tree-rotations
IIUM
 
Week12 graph
Week12   graph Week12   graph
Week12 graph
IIUM
 

More from IIUM (20)

How to use_000webhost
How to use_000webhostHow to use_000webhost
How to use_000webhost
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Kreydle internship-multimedia
Kreydle internship-multimediaKreydle internship-multimedia
Kreydle internship-multimedia
 
03phpbldgblock
03phpbldgblock03phpbldgblock
03phpbldgblock
 
Chap2 practice key
Chap2 practice keyChap2 practice key
Chap2 practice key
 
Group p1
Group p1Group p1
Group p1
 
Tutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seoTutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seo
 
Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009
 
03 the htm_lforms
03 the htm_lforms03 the htm_lforms
03 the htm_lforms
 
Exercise on algo analysis answer
Exercise on algo analysis   answerExercise on algo analysis   answer
Exercise on algo analysis answer
 
Redo midterm
Redo midtermRedo midterm
Redo midterm
 
Heaps
HeapsHeaps
Heaps
 
Report format
Report formatReport format
Report format
 
Edpuzzle guidelines
Edpuzzle guidelinesEdpuzzle guidelines
Edpuzzle guidelines
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
 
Group assignment 1 s21516
Group assignment 1 s21516Group assignment 1 s21516
Group assignment 1 s21516
 
Avl tree-rotations
Avl tree-rotationsAvl tree-rotations
Avl tree-rotations
 
Week12 graph
Week12   graph Week12   graph
Week12 graph
 

Recently uploaded

Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 

Recently uploaded (20)

Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 

Trees (slides)

  • 2. Definition: Let 𝐴𝐴 be a set, and let 𝑇𝑇 be a relation on 𝐴𝐴. We say that 𝑇𝑇 is a tree if there is a vertex 𝑣𝑣0 in 𝐴𝐴 with the property that 1) there exists a unique path in 𝑇𝑇 from 𝑣𝑣0 to every other vertex in 𝐴𝐴, 2) no path from 𝑣𝑣0 to 𝑣𝑣0. Definition: 𝑣𝑣0 is called the root of the tree, and T is referred to as a rooted tree denoted by 𝑇𝑇, 𝑣𝑣0 . Trees © S. Turaev, CSC 1700 Discrete Mathematics 2
  • 3. Theorem: Let 𝑇𝑇, 𝑣𝑣0 be a rooted tree. Then 1. There are no cycle in 𝑇𝑇. 2. Vertex 𝑣𝑣0 is the only root of 𝑇𝑇. 3. Each vertex in 𝑇𝑇, other than 𝑣𝑣0, has in-degree one, and 𝑣𝑣0 has in-degree zero. Trees © S. Turaev, CSC 1700 Discrete Mathematics 3
  • 4. Levels, Parent-Offspring, Siblings © S. Turaev, CSC 1700 Discrete Mathematics 2 1 5 3 4 6 7 Level 1 vertices: the vertices of the edges beginning at 𝑣𝑣0 (level 0) Level 𝑘𝑘 vertices: the vertices of the edges beginning at those level 𝑘𝑘 − 1 vertices Parent-offspring: for all pairs (𝑎𝑎, 𝑏𝑏) in 𝑇𝑇, 𝑎𝑎 is called the parent of 𝑏𝑏 and 𝑏𝑏 is called the offspring of 𝑎𝑎 Siblings: the vertices that have the same parent Height of a tree: the largest level number of a tree Leaves: the vertices that have no offspring 4
  • 5. Levels, Parent-Offspring, Siblings © S. Turaev, CSC 1700 Discrete Mathematics 2 1 5 3 4 6 7 Level 0 Level 1 Level 2 Level 3 Height 3Leaf Root Child / Offspring Parent Siblings 5
  • 6. Theorem: Let 𝑇𝑇, 𝑣𝑣0 be a rooted tree. Then  𝑇𝑇 is irreflexive  𝑇𝑇 is asymmetric  If 𝑎𝑎, 𝑏𝑏 in 𝑇𝑇 and 𝑏𝑏, 𝑐𝑐 in 𝑇𝑇, then 𝑎𝑎, 𝑐𝑐 is not in 𝑇𝑇, for all 𝑎𝑎, 𝑏𝑏 and 𝑐𝑐 in 𝐴𝐴. Trees © S. Turaev, CSC 1700 Discrete Mathematics 6
  • 7. Example: Let 𝐴𝐴 = 𝑣𝑣1, 𝑣𝑣2, 𝑣𝑣3, … , 𝑣𝑣10 and let 𝑇𝑇 = 𝑣𝑣2, 𝑣𝑣3 , 𝑣𝑣2, 𝑣𝑣1 , 𝑣𝑣4, 𝑣𝑣5 , 𝑣𝑣4, 𝑣𝑣6 , 𝑣𝑣5, 𝑣𝑣8 , 𝑣𝑣6, 𝑣𝑣7 , 𝑣𝑣4, 𝑣𝑣2 , 𝑣𝑣7, 𝑣𝑣9 , 𝑣𝑣7, 𝑣𝑣10 Show that 𝑇𝑇 is a rooted tree and identify the root. Trees © S. Turaev, CSC 1700 Discrete Mathematics 7
  • 8. Definition:  If 𝑛𝑛 is a positive integer, we say that a tree is an 𝑛𝑛- tree if every vertex has at most 𝑛𝑛 offspring.  A 2-tree is called a binary tree. Definition:  If all vertices of 𝑇𝑇, other than the leaves, have exactly 𝑛𝑛 offspring, we say that 𝑇𝑇 is a complete 𝑛𝑛-tree.  A complete 2-tree is called a completed binary tree. 𝒏𝒏-trees © S. Turaev, CSC 1700 Discrete Mathematics 8
  • 9.  Let 𝑇𝑇, 𝑣𝑣0 be a rooted tree on the set 𝐴𝐴, and let 𝑣𝑣 be a vertex of 𝑇𝑇.  Let 𝐵𝐵 be the set consisting of 𝑣𝑣 and all its descendants, i.e., all vertices of 𝑇𝑇 that can be reached by a path beginning at 𝑣𝑣.  Let 𝑇𝑇 𝑣𝑣 be the restriction of the relation 𝑇𝑇 to 𝐵𝐵, that is 𝑇𝑇 ∩ (𝐵𝐵 × 𝐵𝐵).  Delete all vertices that are not descendants of 𝑣𝑣 and all edges that do not begin and end at any such vertex. Subtrees © S. Turaev, CSC 1700 Discrete Mathematics 9
  • 10. Theorem: If 𝑇𝑇, 𝑣𝑣0 is a rooted tree and 𝑣𝑣 in 𝑇𝑇, then 𝑇𝑇 𝑣𝑣 is also a rooted tree with root 𝑣𝑣. We will say that 𝑇𝑇 𝑣𝑣 is the subtree of 𝑇𝑇 beginning at 𝑣𝑣. Subtrees © S. Turaev, CSC 1700 Discrete Mathematics 2 31 0 4 5 6 10
  • 11. Theorem: If 𝑇𝑇, 𝑣𝑣0 is a rooted tree and 𝑣𝑣 in 𝑇𝑇, then 𝑇𝑇 𝑣𝑣 is also a rooted tree with root 𝑣𝑣. We will say that 𝑇𝑇 𝑣𝑣 is the subtree of 𝑇𝑇 beginning at 𝑣𝑣. Subtrees © S. Turaev, CSC 1700 Discrete Mathematics 2 0 4 5 6 11
  • 12. Exercise 1: Determine if 𝑅𝑅 is a tree and, if it is, find the root.  𝐴𝐴 = 𝑎𝑎, 𝑏𝑏, 𝑐𝑐, 𝑑𝑑, 𝑒𝑒 𝑅𝑅 = 𝑎𝑎, 𝑑𝑑 , 𝑏𝑏, 𝑐𝑐 , 𝑐𝑐, 𝑎𝑎 , 𝑑𝑑, 𝑒𝑒  𝐴𝐴 = 1, 2, 3, 4, 5, 6 𝑅𝑅 = 2,1 , 3,4 , 5,2 , 6,5 , 6,3 Exercises © S. Turaev, CSC 1700 Discrete Mathematics 12
  • 13. Exercise 2: Consider the rooted tree 𝑇𝑇, 0 . Exercises © S. Turaev, CSC 1700 Discrete Mathematics 0 1 2 4 5 6 8 9 10 11 12 7 3 13 14 15 13
  • 14. Exercise 2: Consider the rooted tree 𝑇𝑇, 0 . 1. List all level-3 vertices 2. List all leaves 3. What are the siblings of 8? 4. What are the descendants of 3? 5. Compute 𝑇𝑇 2 6. Compute 𝑇𝑇 3 7. What is the height of 𝑇𝑇, 0 ? Exercises © S. Turaev, CSC 1700 Discrete Mathematics 14
  • 15. Example: Use a tree to denote the following algebraic expression 3 − 2 × 𝑏𝑏 + 𝑏𝑏 − 2 − 3 + 𝑏𝑏 Labeled Trees © S. Turaev, CSC 1700 Discrete Mathematics + - - 3 2 b x - b 2 3 b + 15
  • 16. Example: Use a tree to denote the following algebraic expression 3 × 1 − 𝑎𝑎 ÷ 4 + 7 − 𝑏𝑏 + 2 × 7 + 𝑎𝑎 ÷ 𝑏𝑏 Labeled Trees © S. Turaev, CSC 1700 Discrete Mathematics 16
  • 17. Positional 𝑛𝑛-tree: • 𝑛𝑛-tree: every vertex has at most 𝑛𝑛 offspring • positional 𝑛𝑛-tree: label the offspring of a given vertex from left to right with numbers 1,2, … , 𝑛𝑛 • some of the offspring in the sequence may be missing Labeled Trees © S. Turaev, CSC 1700 Discrete Mathematics 17
  • 18. Example: positional 3-tree: Labeled Trees © S. Turaev, CSC 1700 Discrete Mathematics 2 2 3 3 3 1 1 3 2 31 2 31 18
  • 19. Example: positional 2-tree: Labeled Trees © S. Turaev, CSC 1700 Discrete Mathematics L R L R R L L L R R 19
  • 20. Visiting Performing appropriate tasks at a vertex will be called visiting the vertex. Tree search The process of visiting each vertex of a tree in some specific order will be called searching the tree or performing a tree search. Tree Searching © S. Turaev, CSC 1700 Discrete Mathematics 20
  • 21. Algorithm PREORDER Step 1: Visit 𝑣𝑣 Step 2: If 𝑣𝑣𝐿𝐿 exists, then apply this algorithm to 𝑇𝑇 𝑣𝑣𝐿𝐿 , 𝑣𝑣𝐿𝐿 Step 3: If 𝑣𝑣𝑅𝑅 exists, then apply this algorithm to 𝑇𝑇 𝑣𝑣𝑅𝑅 , 𝑣𝑣𝑅𝑅 Tree Searching © S. Turaev, CSC 1700 Discrete Mathematics 21
  • 22. Example 1 Tree Searching © S. Turaev, CSC 1700 Discrete Mathematics A B C D F E G J I L K H 1 2 3 4 5 6 7 8 9 10 11 A B C D E F G H I J K L 22
  • 23. Example 2: 𝑎𝑎 − 𝑏𝑏 × 𝑐𝑐 + 𝑑𝑑/𝑒𝑒 Tree Searching © S. Turaev, CSC 1700 Discrete Mathematics × - a b e / + c d × - a b + c / d e 1 2 3 4 5 7 8 6 23
  • 24. Prefix or Polish form: × − 𝑎𝑎 𝑏𝑏 + 𝑐𝑐 / 𝑑𝑑 𝑒𝑒 (𝑎𝑎 = 6, 𝑏𝑏 = 4, 𝑐𝑐 = 5, 𝑑𝑑 = 2, 𝑒𝑒 = 2) 1. × −6 4 + 5 / 2 2 2. × 2 + 5 / 2 2 replacing −6 4 by 2 since 6 − 4 = 2 3. × 2 + 5 1 replacing / 2 2 by 1 since 2/2 = 1 4. × 2 6 replacing + 5 1 by 6 since 5 + 1 = 6 5. 12 replacing × 2 6 by 12 since 2 × 6 = 12 Tree Searching © S. Turaev, CSC 1700 Discrete Mathematics 24
  • 25. Algorithm INORDER Step 1: Search the left subtree 𝑇𝑇 𝑣𝑣𝐿𝐿 , 𝑣𝑣𝐿𝐿 , if it exists Step 2: Visit the root 𝑣𝑣 Step 3: Search the right subtree 𝑇𝑇 𝑣𝑣𝑅𝑅 , 𝑣𝑣𝑅𝑅 , if it exists Tree Searching © S. Turaev, CSC 1700 Discrete Mathematics 25
  • 26. Algorithm POSTORDER Step 1: Search the left subtree 𝑇𝑇 𝑣𝑣𝐿𝐿 , 𝑣𝑣𝐿𝐿 , if it exists Step 2: Search the right subtree 𝑇𝑇 𝑣𝑣𝑅𝑅 , 𝑣𝑣𝑅𝑅 , if it exists Step 3: Visit the root 𝑣𝑣 Tree Searching © S. Turaev, CSC 1700 Discrete Mathematics 26
  • 27. Example: Traveling the tree using INORDER and POSTORDER 𝑎𝑎 − 𝑏𝑏 × 𝑐𝑐 + 𝑑𝑑/𝑒𝑒 Tree Searching © S. Turaev, CSC 1700 Discrete Mathematics × - a b e / + c d INORDER: 𝑎𝑎 − 𝑏𝑏 × 𝑐𝑐 + 𝑑𝑑/𝑒𝑒 POSTORDER: 𝑎𝑎 𝑏𝑏 − 𝑐𝑐 𝑑𝑑 𝑒𝑒 / +× 27
  • 28. Infix notation: Algebraic symbols lie between their arguments 𝑎𝑎 − 𝑏𝑏 × 𝑐𝑐 + 𝑑𝑑 / 𝑒𝑒 (𝑎𝑎 − 𝑏𝑏) × (𝑐𝑐 + (𝑑𝑑/𝑒𝑒)) or 𝑎𝑎 − (𝑏𝑏 × ( 𝑐𝑐 + 𝑑𝑑 /𝑒𝑒)) Tree Searching © S. Turaev, CSC 1700 Discrete Mathematics 28
  • 29. Postfix or reverse Polish: 𝑎𝑎 𝑏𝑏 − 𝑐𝑐 𝑑𝑑 𝑒𝑒 / + × (𝑎𝑎 = 2, 𝑏𝑏 = 1, 𝑐𝑐 = 3, 𝑑𝑑 = 4, 𝑒𝑒 = 2) 1. 2 1 − 3 4 2 / + × 2. 1 3 4 2 / + × replacing 2 1 − with 1 since 2 − 1 = 1 3. 1 3 2 + × replacing 4 2 / with 2 since 4/2 = 2 4. 1 5 × replacing 3 2 + with 5 since 3 + 2 = 5 5. 5 replacing 1 5 × with 5 since 1 × 5 =5 Tree Searching © S. Turaev, CSC 1700 Discrete Mathematics 29
  • 30. Show the result of performing a preorder search of the tree Exercises © S. Turaev, CSC 1700 Discrete Mathematics x y s z t u v 30
  • 31. Show the result of performing an inorder search of the tree Exercises © S. Turaev, CSC 1700 Discrete Mathematics x y s z t u v 31
  • 32. Show the result of performing a postorder search of the tree Exercises © S. Turaev, CSC 1700 Discrete Mathematics x y s z t u v 32
  • 33. Show the result of performing preorder, inorder and postorder searches of the tree 𝑇𝑇 = 𝑎𝑎, 𝑏𝑏 , 𝑎𝑎, 𝑑𝑑 , 𝑏𝑏, 𝑐𝑐 , 𝑏𝑏, 𝑖𝑖 , 𝑑𝑑, 𝑘𝑘 , 𝑑𝑑, 𝑒𝑒 , 𝑐𝑐, 𝑔𝑔 , 𝑐𝑐, ℎ , 𝑒𝑒, 𝑗𝑗 , 𝑒𝑒, 𝑓𝑓 Exercises © S. Turaev, CSC 1700 Discrete Mathematics 33
  • 34. Show the result of performing preorder, inorder and postorder searches of the tree 𝑇𝑇 = 1,2 , 1,3 , 2,4 , 3,5 , 4,6 , 5,7 Exercises © S. Turaev, CSC 1700 Discrete Mathematics 34
  • 35. Evaluate the expressions, which are given in Polish, or prefix, notation • × − + 3 4 − 7 2 ÷ 12 × 3 − 6 4 • ÷ − × 3 2 × 4 3 + 15 × 2 − 6 × 3 Exercises © S. Turaev, CSC 1700 Discrete Mathematics 35
  • 36. Evaluate the expressions, which are given in reverse Polish, or postfix, notation • 4 3 2 ÷ − 5 × 4 2 × 5 × 3 ÷ ÷ • 3 7 × 4 − 9 × 6 5 × 2 + ÷ Exercises © S. Turaev, CSC 1700 Discrete Mathematics 36
  • 37. Draw a binary tree whose preorder search produces • JBACDIHEGF • CATSANDDOGS Draw a binary tree whose postorder search produces • SEARCHING • TREEHOUSE Exercises © S. Turaev, CSC 1700 Discrete Mathematics 37