Start by defining a binary search tree and its ordering property, then walk through the insertion algorithm step-by-step, comparing the new key with each node and moving left or right until finding the correct null position. Conclude by discussing time complexity and edge cases like duplicate keys or an empty tree.
Pro tip: Mention that insertion in a BST is essentially a search for the correct null spot, and highlight that the shape of the tree (and thus performance) depends on insertion order, which motivates self-balancing trees like AVL or Red-Black trees.
State that for any node, all keys in the left subtree are smaller and all keys in the right subtree are larger (or equal, depending on convention).
Begin with the root node and compare the new key with the current node's key.
If the new key is less than the current node's key, move to the left child; if greater, move to the right child. Repeat until a null child pointer is found.
Create a new node with the key and attach it as the left or right child of the last node visited, depending on the comparison.
Discuss time complexity O(h) where h is height (O(log n) balanced, O(n) worst-case), and handle duplicates or empty tree.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.