Binary search tree is one of most important data structure in programming.So lets see how to work with a binary search tree manually.
Main property of a binary search tree is all of the values in the left sub-tree are less than the value in the root and all of the values in the right sub-tree are greater than the root.
when we enter a data set to a binary search tree.first value goes to the root.If next value is greater than root it is the right child of root. If next value is less than root it is the left child of root.
Lets enter this data set in to a binary search tree.
{ 8, 3, 6, 10, 1, 4, 7, 14, 13}
8 is the root of this BST. 3 is the left child of 8 (root) because 3 is less than 8. 10 is the right child of the 8 (root) because 10 is greater than 8. Next element of the array is 1. 1 goes to left sub-tree of 8 because 1 is less than 8 and it is the left child of the 3 because 1 is less than 3. So on after completing the BST it will looks like this.
Lets try another exercise.
{ 50, 72, 54, 17, 12, 23, 19, 14, 76, 9, 54, 67}
After entering this data set into BST it will look like this
Subscribe to:
Post Comments (Atom)
Optimize you working enviorenment : Single command to create & move to a directory in linux (C Shell, Bash)
Usually move to a directory just after creating is bit of a anxious task specially if the directory name is too long. mkdir long-name-of...
-
PPA stands for Personal Package Archive and it is a special software repository for uploading source packages to be built and published as a...
-
When we write a C++ program we use g++ -Wall -o sample sample.cpp command (file name is sample.cpp) to compile the program then we run the ...
-
Binary search tree is one of most important data structure in programming.So lets see how to work with a binary search tree manually. Main ...
Simple.. Well explained.
ReplyDeleteThank you for your comment.
Delete