AlgoThrive
← All tree operations

BST Insert

ComparingInserted

binary search tree

left is smaller, right is larger

50
30
70
20
40
60
80

pseudocode

insert(node, value)
if node is null: return new Node(value)
if value == node.value: return node // duplicate
if value < node.value: node.left = insert(node.left, value)
else: node.right = insert(node.right, value)
return node

Frame 1 / 5

Starting tree

7 values inserted

4

39 unique integers, 199 each — inserted in order to build the starting tree.