content: 
  import java.util.*;
  
  public class BFS {
      private int V;
      private LinkedList<Integer> adj[];
  
      // Create a graph
      BFS(int v) {
          V = v;
          adj = new LinkedList[v];
          for (int i = 0; i < v; ++i)
              adj[i] = new LinkedList<Integer>();
      }
  
      // Add edges to the graph
      void addEdge(int v, int w) {
          adj[v].add(w);
      }
  
      // BFS algorithm
      void BFS_algorithm(int s) {
  
          boolean visited[] = new boolean[V];
  
          LinkedList<Integer> queue = new LinkedList<Integer>();
  
          visited[s] = true;
          queue.add(s);
  
          while (!queue.isEmpty()) {
              s = queue.poll();
              System.out.print(s + " ");
  
              for (Integer neighbour : adj[s]) {
                  if (!visited[neighbour]) {
                      visited[neighbour] = true;
                      queue.add(neighbour);
                  }
              }
          }
      }
  
      public static void main(String args[]) {
          BFS g = new BFS(4);
          /* Here Give Your Input */
          g.addEdge(0, 1);
          g.addEdge(0, 2);
          g.addEdge(1, 2);
          g.addEdge(2, 0);
          g.addEdge(2, 3);
          g.addEdge(3, 3);
  
          System.out.println("Following is Breadth First Traversal " + "(starting from vertex 2)");
  
          g.BFS_algorithm(2);
      }
  }
  