My first instinct was to do a level-order traversal and check for gaps.
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.
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.
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.
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.
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.
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).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.