> For the complete documentation index, see [llms.txt](https://ucan.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ucan.gitbook.io/notes/iterative-bfs-binary-tree-search.md).

# iterative BFS binary tree search

102\. Binary Tree Level Order Traversal

```java

class Solution {
    public List<List<Integer>> levelOrder(TreeNode root) {
        //BFS soltion using FIFO queue
        Queue<TreeNode> queue =new LinkedList<>();
        List<List<Integer>> result = new LinkedList<>();
        if (root==null) return result;
        queue.add(root);
        while(!queue.isEmpty()){
            int size = queue.size();
            List<Integer> list = new LinkedList<>();
            while(size-->0){
                // retrive and remove the first element of queue : queue.poll();
                root = queue.poll();
                list.add(root.val);
                if (root.left!=null) queue.add(root.left);
                if (root.right!=null) queue.add(root.right);
            }
            result.add(list);
        }
        return result;
    }
}
```
