Tuesday, October 16, 2012

Binary Search Tree


Binary Search Tree is a binary tree where left child of a node is less than the key of the Parent node and the key in the right child is greater than the parent node.We can design many kind of BST(Binary Search Tree) for some nodes or values.And there average searching time may be different.In Binary Search tree searching is easy. Time complexity of searching in case BST is nlogn.


Binary Tree
Traversal of a Binary TreeThe traversal of binary tree invloves visiting each node in the tree exactly once. Binary tree traversal is usefull in many applications.There are 3 popular method of Binary tree traversal.These methods are:-
1) Inorder Traversal.(Left,Root,Right)
2) Preorder Traversal.(Root,Left,Right)
3) Postorder Traversal.(Left,Right,Root)

 For the above tree:   Inorder Traversal is    5 , 10 , 12 , 20 , 30.
                                    Preorder Traversal is   20 , 10 , 5 , 12 , 30.           
                                    Postorder Traversal is   5 , 12 , 10 , 30 , 20.





No comments: