Where does a level end?
transcript
A queue visits a tree level by level. But the children join the same queue. So where does one level end? One number answers it.
Round two starts with three and ten in the queue. Take three. Add its children, one and six. Take ten. Add its child, fourteen. The length changed all the time. It cannot mark the end. The size before the round was two. That marks the end.
Round one has a size of one. Take the root. Round two has a size of two. Take three and ten. Round three has a size of three. Take one, six and fourteen. Round four has a size of one. Take four, and you are done.
Write down the queue's size before the round. Loop exactly that many times. Everything behind them is the next level.
The size is a snapshot of one level. Take it before any child is added. Each node is still handled once. Full breakdown in the lecture.