← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Interviewed at Google for a software engineering role and got a classic BST question. Pretty standard but I fumbled parts of the explanation more than I expected.

Questions Asked (1)

Q1

Walk me through how insertion works in a binary search tree.

Algorithms & Data Structures
Author's notes

I knew this cold, or so I thought.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

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.

1. Define BST property

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).

2. Start at root

Begin with the root node and compare the new key with the current node's key.

3. Traverse left or right

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.

4. Insert at null position

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.

5. Analyze complexity and edge cases

Discuss time complexity O(h) where h is height (O(log n) balanced, O(n) worst-case), and handle duplicates or empty tree.

Key Points to Mention

  • BST ordering property: left < node < right
  • Insertion always adds a new leaf node
  • Comparison at each step determines direction
  • Time complexity: O(h) where h is tree height
  • Worst-case O(n) for skewed tree, best-case O(log n) for balanced
  • Handling duplicates: either reject, count, or define a consistent rule

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.