You are given the root of a binary tree. Determine whether the tree is a complete binary tree.
A binary tree is complete if:
-
Every level, except possibly the last, is completely filled.
-
All nodes in the last level are as far left as possible.
Input
-
root
: root node of a binary tree (or
null
).
Output
-
Return
true
if the tree is complete; otherwise return
false
.
Constraints
-
Number of nodes:
0..10^5
-
Node values are irrelevant to completeness.
Notes
-
Aim for an algorithm that is correct for large trees; discuss time complexity and space usage (e.g., typical BFS approach vs. any space optimizations).