Grokking the Engineering Manager Coding Interview
0% completed
Introduction to Tree Breadth First Search Pattern
You are given a binary tree. Return its values one level at a time.
1
/ \
2 3 becomes [[1], [2, 3], [4, 5, 6]]
/ \ \
4 5 6
The root is level zero. Its children form the next level. Their children form the level after that.
A normal recursive traversal often goes deep into one branch first. It may visit node 4 before node 3. That order does not match the required output.
We need to visit all nodes at one depth before visiting a deeper node.
A queue provides this order. A queue follows First In, First Out order
.....
.....
.....
Like the course? Get enrolled and start learning!
Ahmed k
· 4 years ago
Nothing about construction and conversion?
Reading Progress
0%