code: def traversals(edges, mode='bfs'):
      
      edges = np.asanyarray(edges, dtype=np.int64)
      if len(edges) == 0:
          return []
      elif not util.is_shape(edges, (-1, 2)):
          raise ValueError('edges are not (n,2)!')
  
      # pick the traversal method
      mode = str(mode).lower().strip()
      if mode == 'bfs':
          func = csgraph.breadth_first_order
      elif mode == 'dfs':
          func = csgraph.depth_first_order
      else:
          raise ValueError('traversal mode must be either dfs or bfs')
  
      # make sure edges are sorted so we can query
      # an ordered pair later
      edges.sort(axis=1)
      # set of nodes to make sure we get every node
      nodes = set(edges.reshape(-1))
      # coo_matrix for csgraph routines
      graph = edges_to_coo(edges)
  
      # we're going to make a sequence of traversals
      traversals = []
  
      while len(nodes) > 0:
          # starting at any node
          start = nodes.pop()
          # get an (n,) ordered traversal
          ordered = func(graph,
                         i_start=start,
                         return_predecessors=False,
                         directed=False).astype(np.int64)
  
          traversals.append(ordered)
          # remove the nodes we've consumed
          nodes.difference_update(ordered)
  
      return traversals
docs: Given an edge list, generate a sequence of ordered
      depth first search traversals, using scipy.csgraph routines.
  
      Parameters
      ------------
      edges : (n,2) int, undirected edges of a graph
      mode :  str, 'bfs', or 'dfs'
  
      Returns
      -----------
      traversals: (m,) sequence of (p,) int,
                  ordered DFS or BFS traversals of the graph.