BST Lecture 1 - Class Notes
BST Lecture 1 - Class Notes
b. Insertion - O(log(n))
c. Deletion - O(log(n))
d. Traversals - O(n)
classNode{
Int data;
Node left,right;
Node(int d){
data=d;
left=right=null;
}
}
Return node;
}
Return node;
}
If(null ) return 0;
Return 1
+ size(root.left)
+ size(root.right);
if(val>root.val){
root.right = deleteNode(root.right, val);
}
else if(val < root.val){
root.left = deleteNode(root.left, val);
}
else {
//actual deleteion
if(root.left == null)
return root.right;
else if(root.right == null)
return root.left;
else{
root.val = minValue(root.right);
root.right = deleteNode(root.right, root.val);
}
}
return root;
}
Validate BST
Given a binary tree with N number of nodes, check if that input tree is BST (Binary
Search Tree) or not. If yes, print true, print false otherwise.
https://course.acciojob.com/idle?question=3b992182-31dd-4aaa-
a4fd-914a6a9669ff