← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Google SWE interview with a tree problem. Pretty standard algorithmic round, nothing too wild, but the question had more edge cases than I initially gave it credit for.

Questions Asked (1)

Q1

Given a binary tree, determine whether it is a complete binary tree.

Algorithms & Data Structures
Author's notes

My first instinct was to do a level-order traversal and check for gaps.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the definition of a complete binary tree, then propose a level-order traversal (BFS) that checks for two conditions: no node after a null child, and all nodes are as far left as possible. Alternatively, use a recursive approach with index counting to ensure nodes are numbered consecutively from 1 to n.

Pro tip: Mention that the BFS approach can be done in O(n) time and O(n) space, but you can optimize space to O(width) by using a queue that only stores non-null nodes and tracking the first null. Also, discuss edge cases like empty tree and single node.

1. Define complete binary tree

State that a complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.

2. Choose an approach

Decide between BFS with null flag or recursive index counting. Explain the trade-offs: BFS is intuitive and iterative; recursive is elegant but may risk stack overflow for skewed trees.

3. Implement BFS with null flag

Perform level-order traversal. Once a null child is encountered, set a flag. If any non-null node is seen after the flag, return false. Also ensure no node has a right child without a left child.

4. Implement recursive index counting

Assign an index to each node (root=1, left=2*i, right=2*i+1). Count total nodes. Recursively check that each node's index is less than or equal to the total count and that indices are unique.

5. Analyze complexity and edge cases

Discuss time and space complexity for both approaches. Mention edge cases: empty tree (true), single node (true), and trees with missing left child but present right child (false).

Key Points to Mention

  • Definition of complete binary tree: all levels filled except possibly last, filled from left to right.
  • BFS approach: use queue, track null child, ensure no non-null after null.
  • Recursive approach: use index counting, total node count, and check index <= n.
  • Time complexity: O(n) for both approaches.
  • Space complexity: O(n) for BFS (queue) and O(h) for recursion (stack).
  • Edge cases: empty tree, single node, and trees with right child but no left child.

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