Lecture 1 Trees
Lecture 1 Trees
4 2 5 1 3
Preorder Traversal
Algorithm Inorder(tree)
1. Visit the root.
2. Traverse the left subtree, i.e., call
Inorder(left-subtree)
3. Traverse the right subtree, i.e., call
Inorder(right-subtree)
1 2 4 5 3
Postorder Traversal
Algorithm Inorder(tree)
1. Traverse the left subtree, i.e., call
Inorder(left-subtree)
2. Traverse the right subtree, i.e., call
Inorder(right-subtree)
3. Visit the root.
4 5 2 3 1
Example
Binary Search Trees
Binary Search Tree is a node-based binary tree data structure which
has the following properties:
• The left subtree of a node contains only nodes with keys lesser than
the node’s key.
• The right subtree of a node contains only nodes with keys greater
than the node’s key.
• The left and right subtree each must also be a binary search tree.