Data Structures and Algorithms: Trees and Tree Traversals
Data Structures and Algorithms: Trees and Tree Traversals
Algorithms [CC2411w]
trees and tree traversals
What are trees
Binary tree
Binary Search Trees
2-3 trees
M-Tree
B-trees
Red black tree
Avial trees
Heap
Graphs
Representation of Trees –Binary tree
Representation of Trees –Binary tree
Terms with binary tree
Root:
Height:
Proper Tree:
Improper Tree:
Full tree:
Complete Tree:
Children:
Parent:
Leaf Node:
Balance:
Exercise
Applications of trees
Struct Node { };
Class tree { };
Exercise-BST
Operations on a BST
Insertion
Search
DFS
BFS
Update
getMaxNode
getMinNode
Traversal
Inorder
Preorder
postorder
Delete
Isbalanced
Balance
getHeight
constructor
insertion
Node * getMaxNode()
getMinNode
Node * getMinNode()
getHeight
NLR
Traversal-Inorder – used in DFS
LNR
Traversal-Postorder
LRN
Deletion from BST
Balance
Void balance()
Convert normal BST to a tree with min possible height
Idea:
Count number of nodes
Create dynamic array
Travese tree in in-order and store results in array
Construct BST from sorted array
Rearrange root
destructor
BFS-breadth first search