Store elements at every level separately during level order traversal
Store elements at every level separately during level order traversal
To explain the problem, say we have the following tree:
And we want to store elements at every level in a separate list. For this example, we would have the following three lists:
1
2 3
4 5 6 7
We will use the usual BFS algorithm but with a small modification. To know the level, we will keep two variables: one to store the numbers of variables in the current level and the second to store the…
View On WordPress
















