CSE220 L11 Tree PNP
CSE220 L11 Tree PNP
Lecture 11
Tree
Prantik Paul [PNP]
Lecturer
Department of Computer Science and Engineering
BRAC University 1
Trees
2
Why Trees?
3
Trees - Root/Leaf/Non-Leaf
4
Trees - Parent/Child/Siblings
5
Trees - Edge/Path
n nodes → n-1 edges
6
Trees - Degree
7
Trees - Depth/Height/Level
8
Trees - Depth/Height/Level
10
Trees - Characteristics
11
Trees - Build a Tree
Dynamic
Sequential
Representation
Representation
withwith
Linked
Array
List 12
Binary Trees
13
Binary Trees
14
Binary Tree - Full/Strict Binary Tree
25
Binary Trees - Traversal (In-order)
26
Binary Trees - Traversal (Post-order)
27
Binary Trees - Array Representation
Any node that is placed at index i, will have its left child
placed at 2i and its right child at 2i+1
28
Binary Trees - Array Representation
29
Binary Trees - Tree Node
30
Binary Trees - Preorder Traversal
31
Binary Trees - Inorder Traversal
Do yourself
32
Binary Trees - Postorder Traversal
Do yourself
33
Binary Trees - Count Nodes of Tree
34
Binary Trees - Find Level of a Node
35
Binary Trees - Find Height of a Node
If node is None
return -1
else
return 1 + max(left_subtree_height, right_subtree_height)
Do yourself
36
Binary Trees - Build Tree From Array
37
Binary Trees - Build Array From Tree
38