The "Check Completeness of a Binary Tree interview question" asks you to verify if a given binary tree is "complete." A complete binary tree is one where every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. This structural property is essential for representing trees in arrays (like in a Binary Heap).
Companies like Lyft and Meta ask the "Check Completeness of a Binary Tree coding problem" to test a candidate's knowledge of tree traversals, particularly Breadth-First Search (BFS). It evaluates your ability to recognize a specific pattern in the order nodes are visited. It also checks if you understand the conceptual difference between "full", "perfect", and "complete" trees.
This problem is best solved using the Level Order Traversal (BFS) pattern.
null children to the queue.null node in a level-order traversal, you should never see another non-null node.null from the queue and subsequently pop a valid (non-null) node, the tree is not complete.Tree: [1, 2, 3, 4, 5, null, 7]
[1]. Pop 1, push children 2, 3.[2, 3]. Pop 2, push children 4, 5.[3, 4, 5]. Pop 3, push children null, 7.[4, 5, null, 7]. Pop 4, push null, null.[5, null, 7, null, null]. Pop 5, push null, null.[null, 7, null, null, null, null]. Pop null. Set a flag seen_null = true.seen_null is true, but current node is not null!
Result: False.null children into the queue, which is the key to detecting "gaps."Master BFS for trees! Level-order traversal is the go-to "Tree interview pattern" for any problem that involves the shape or width of a tree. Always consider how null nodes affect the structure when properties like "completeness" are involved.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Binary Tree Level Order Traversal II | Medium | Solve | |
| Even Odd Tree | Medium | Solve | |
| Minimum Number of Operations to Sort a Binary Tree by Level | Medium | Solve | |
| Binary Tree Level Order Traversal | Medium | Solve | |
| Binary Tree Zigzag Level Order Traversal | Medium | Solve |