Lect 5 - Sliit
Lect 5 - Sliit
Structures and
Algorithms
Lecture 05
https://yongdanielliang.github.io/
animation/web/BST.html
Binary Search Tree - BST
Find
Insert
https://futurecoder.io/course/#ide
Activity
Draw the following BST s.
• 40,20,30,60,10,50,70
• 70,60,50,40,30,20,10
heightRec(15) – LEVEL 2
Slide 69,70,71 heightRec(20) -> null, it returns -1. – LEVEL3
htSoFar = (max of -1, -1) + 1 = 0
htSoFar = (max of 0, -1) + 1 = 1 – LEVEL2
htSoFar = (max of 1, 1) + 1 = 2 – LEVEL1
Traversing – In order
• Recursively Print left subtree
• Print current node
• Recursively Print right sub tree
if CurrentNode != NULL
inOrder(currNode.getLeft())
print (currNode.getKey())
inOrder(currNode.getRight())
if CurrentNode != NULL
print (currNode.getKey())
inOrder(currNode.getLeft())
inOrder(currNode.getRight())
if CurrentNode != NULL
inOrder(currNode.getLeft())
inOrder(currNode.getRight())
print (currNode.getKey())