Binary Search Tree
Binary Search Tree
Binary Search Tree is a node-based binary tree which has a few certain properties. Nodes on the left of the tree contain nodes with a lower value than the node's value while the one on the right contains nodes that have greater keys than the node's value. Also, Binary Search tree can only have a maximal of 2 child node under each node.

In Binary search tree there are traversals:
1. InOrder(Left, Root, Right)
2. PreOrder(Root, Left, Right)
3. PostOrder(Left, Right, Root)
Binary Search Tree is a node-based binary tree which has a few certain properties. Nodes on the left of the tree contain nodes with a lower value than the node's value while the one on the right contains nodes that have greater keys than the node's value. Also, Binary Search tree can only have a maximal of 2 child node under each node.

In Binary search tree there are traversals:
1. InOrder(Left, Root, Right)
2. PreOrder(Root, Left, Right)
3. PostOrder(Left, Right, Root)
//data printing
//preOrder
void preOrder(struct node *node) {
if (node!=NULL) {
printf("%d ", node->key);
preOrder(node->left);
preOrder(node->right);
}
}
//inOrder
void inOrder(struct node *node) {
if (node!=NULL) {
inOrder(node->left);
printf("%d ", node->key);
inOrder(node->right);
}
}
//postOrder
void postOrder(struct node *node) {
if (node!=NULL) {
postOrder(node->left);
postOrder(node->right);
printf("%d ", node->key);
}
}
Comments
Post a Comment