---
description: 102. Binary Tree Level Order Traversal
---

# iterative BFS binary tree search

```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;
    }
}
```
