Traverse to all the nodes connected to current vertex and push new path to queue
List < Integer > lastNode = g . get ( last ) ; for ( int i = 0 ; i < lastNode . size ( ) ; i ++ ) { if ( isNotVisited ( lastNode . get ( i ) , path ) ) { List < Integer > newpath = new ArrayList < > ( path ) ; newpath . add ( lastNode . get ( i ) ) ; queue . offer ( newpath ) ; } } } }