Advanced Data Structures: Binary Search Tree
Advanced Data Structures: Binary Search Tree
M.Jeevana Sujitha
Asst Professor
ToArray
learn how to organise data in a binary search tree
implementation
Each node has atmost two children i.e left and right
child
What makes a binary tree a BST
struct node
{
int data;
struct node* left;
struct node* right;
}
struct node* root=NULL;
Construction of a BST
Search for 9:
Step-1: Compare 9 with 15(root) 9<15
go to left subtree
Step-2: Compare 9 with 6 (9>6) go
to right subtree
Step-3: Compare 9 with 7 (9>7) go
to right subtree
Step-4: Compare 9 with 13 (9<13)
go to left subtree
Step-5: Compare 9 with 9 element
found.
“C” Code for searching an element in a
binary search tree