Table of Contents
How do you add to BST?
Algorithm
- Create a new BST node and assign values to it.
- insert(node, key) i) If root == NULL, return the new node to the calling function. ii) if root=>data < key. call the insert function with root=>right and assign the return value in root=>right.
- Finally, return the original root pointer to the calling function.
Which is not binary search tree?
Difference between Binary Tree and Binary Search Tree:
BINARY TREE | BINARY SEARCH TREE |
---|---|
IN BINARY TREE there is no ordering in terms of how the nodes are arranged | IN BINARY SEARCH TREE the left subtree has elements less than the nodes element and the right subtree has elements greater than the nodes element. |
What is a binary search tree (BST)?
A binary search tree (BST) is a node based binary tree data structure which has the following properties. • The left subtree of a node contains only nodes with keys less than the node’s key.
How to check if a tree is BST or not?
3) Check if the temp array is sorted in ascending order, if it is, then the tree is BST. We can avoid the use of a Auxiliary Array. While doing In-Order traversal, we can keep track of previously visited node.
What are the properties of binary search tree?
A binary search tree (BST) is a node based binary tree data structure which has the following properties. • The left subtree of a node contains only nodes with keys less than the node’s key. • The right subtree of a node contains only nodes with keys greater than the node’s key.
How to use inorder traversal in binary search tree?
Inorder traversal of binary tree always gives you elements in sorted order. We will use min max range for a node. If node.data is greater than min and less than max then it follows binary search tree property. When you traverse right, current node should be less than max.