r/csinterviewproblems • u/tyroo • Dec 18 '15
[Easy] Level order traversal of a binary tree
Print out a binary tree level by level
a
/ \
b c
/ \ / \
d e f gwould output
[[a],
[b, c],
[d, e, f, g]]
7
Upvotes
5
u/Ochikobore Dec 18 '15
BFS
2
u/parlezmoose Dec 18 '15
Use a 2 dimensional array to capture nodes at each level. Populate it with a recursive tree traversal, return the result
0
u/[deleted] Dec 18 '15
[deleted] — view deleted comment