# 7.0 Introduction



&#x20;Here are the steps of our algorithm:

1. Start by pushing the `root` node to the queue.
2. Keep iterating until the queue is empty.
3. In each iteration, first count the elements in the queue (let’s call it `levelSize`). We will have these many nodes in the current level.
4. Next, remove `levelSize` nodes from the queue and push their `value` in an array to represent the current level.
5. After removing each node from the queue, insert both of its children into the queue.
6. If the queue is not empty, repeat from step 3 for the next level.

Example 1:

![](https://3044525046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbBKA61iq4XbibNMK4M%2Fuploads%2F3LKJdeTK834lLUHFa5Ba%2Fimage.png?alt=media\&token=ec48c660-700c-49d0-ba6a-6799c8323d4f)

![](https://3044525046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbBKA61iq4XbibNMK4M%2Fuploads%2FL2JWtHnWq1rmS0QHTtZn%2Fimage.png?alt=media\&token=b3f7fd2f-aced-4186-9567-0dcaae16b7de)



![](https://3044525046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbBKA61iq4XbibNMK4M%2Fuploads%2FcIr0cPsnZgwe5wUKiv59%2Fimage.png?alt=media\&token=876938c1-32d6-46e9-bcee-426ea37c3a2d)

![](https://3044525046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbBKA61iq4XbibNMK4M%2Fuploads%2F5LdbwE6Pi32KMzMv5DGe%2Fimage.png?alt=media\&token=e7173d36-a5d0-48c7-8784-b528bb47b04c)

![](https://3044525046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbBKA61iq4XbibNMK4M%2Fuploads%2FVTm2nJSviWAUl5xRoAvX%2Fimage.png?alt=media\&token=fdebdd3d-1f00-4d2e-8716-2bcb5184643b)

![](https://3044525046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbBKA61iq4XbibNMK4M%2Fuploads%2F2iDGIPhhQBRLBnV6HwGP%2Fimage.png?alt=media\&token=54a0ed1f-b396-416d-b146-7c159fcb0e74)

![](https://3044525046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbBKA61iq4XbibNMK4M%2Fuploads%2FyO6hN9mdZAzooit1Ox8c%2Fimage.png?alt=media\&token=56470d4f-2a93-495e-ad7f-f158c2687ebd)

![](https://3044525046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbBKA61iq4XbibNMK4M%2Fuploads%2FNMfna54zI532rAYc2fQx%2Fimage.png?alt=media\&token=7a20a144-645e-425a-9269-30128c74ed3e)
