Trees and Binary Search Tree
A tree is a data structure composed of nodes that has the following characteristics:
1. Each tree has a root node (at the top) having some value.
2. The root node has zero or more child nodes.
3. Each child node has zero or more child nodes, and so on. This create a subtree in the tree. Every node has it’s own subtree made up of his children and their children, etc. This means that every node on its own can be a tree.
A binary search tree (BST) adds these two characteristics:
1. Each node has a maximum of up to two children.
2. For each node, the values of its left descendent nodes are less than that of the current node, which in turn is less than the right descendent nodes (if any).
struct
node*
search(int data
){
struct
node
*current
= root
;
printf("Visiting elements: ");
while(current
->data
!= data
){
if(current
!=
NULL)
{
printf("%d ",current
->data
);
//go to left tree
if(current
->data
> data
){
current
= current
->leftChild
;
}//else go to right tree
else
{
current
= current
->rightChild
;
}
//not found
if(current
==
NULL){
return
NULL;
}
}
}
return current
;
}
Tirthankar Pal
MBA from IIT Kharagpur with GATE, GMAT, IIT Kharagpur Written Test, and Interview
2 year PGDM (E-Business) from Welingkar, Mumbai
4 years of Bachelor of Science (Hons) in Computer Science from the National Institute of Electronics and Information Technology
Google and Hubspot Certification
Brain Bench Certification in C++, VC++, Data Structure and Project Management
10 years of Experience in Software Development out of that 6 years 8 months in Wipro
Selected in Six World Class UK Universities:-
King's College London, Durham University, University of Exeter, University of Sheffield, University of Newcastle, University of Leeds
No comments:
Post a Comment