original_docstring: 
      time complexity: O(V+E)
  
      Fact: A DAG has at least one vertex with in-degree 0 and one vertex with out-degree 0
  
      1. Get in-degree of every node
      2. Pick all the vertices with in-degree as 0 and add them into a queue
      3. Remove a vertex from the queue (Dequeue operation) and then.
          Increment count of visited nodes by 1.
          Decrease in-degree by 1 for all its neighboring nodes.
          If in-degree of a neighboring nodes is reduced to zero, then add it to the queue.
      4. Repeat Step 3 until the queue is empty.
      5.  If count of visited nodes is not equal to the number of nodes in the graph then the
          topological sort is not possible for the given graph.
      
docstring: time complexity: O(V+E)
  Fact: A DAG has at least one vertex with in-degree 0 and one vertex with out-degree 0
  
  1. Get in-degree of every node
  2. Pick all the vertices with in-degree as 0 and add them into a queue
  3. Remove a vertex from the queue (Dequeue operation) and then.
  Increment count of visited nodes by 1.
  Decrease in-degree by 1 for all its neighboring nodes.
  If in-degree of a neighboring nodes is reduced to zero, then add it to the queue.
  4. Repeat Step 3 until the queue is empty.
  5.  If count of visited nodes is not equal to the number of nodes in the graph then the
  topological sort is not possible for the given graph.
docstring_tokens: time complexity : O ( V + E ) Fact : A DAG has at least one vertex with in - degree 0 and one vertex with out - degree 0 1 . Get in - degree of every node 2 . Pick all the vertices with in - degree as 0 and add them into a queue 3 . Remove a vertex from the queue ( Dequeue operation ) and then . Increment count of visited nodes by 1 . Decrease in - degree by 1 for all its neighboring nodes . If in - degree of a neighboring nodes is reduced to zero then add it to the queue . 4 . Repeat Step 3 until the queue is empty . 5 . If count of visited nodes is not equal to the number of nodes in the graph then the topological sort is not possible for the given graph .
code: def topological_sort_kahn_algorithm(graph: list, vertices: int) -> list:
      """
      time complexity: O(V+E)
  
      Fact: A DAG has at least one vertex with in-degree 0 and one vertex with out-degree 0
  
      1. Get in-degree of every node
      2. Pick all the vertices with in-degree as 0 and add them into a queue
      3. Remove a vertex from the queue (Dequeue operation) and then.
          Increment count of visited nodes by 1.
          Decrease in-degree by 1 for all its neighboring nodes.
          If in-degree of a neighboring nodes is reduced to zero, then add it to the queue.
      4. Repeat Step 3 until the queue is empty.
      5.  If count of visited nodes is not equal to the number of nodes in the graph then the
          topological sort is not possible for the given graph.
      """
      def get_indegrees():
          indegree: list = [0] * vertices
  
          for src in range(vertices):
              for dest, connect in enumerate(graph[src]):
                  indegree[dest] += 1 if connect == 1 else 0
  
          return indegree
  
      def create_queue(indegree):
          q: deque = deque()
  
          for src, degree in enumerate(indegree):
              if degree == 0:
                  q.append(src)
  
          return q
  
      indegree_list: list = get_indegrees()
      queue: deque = create_queue(indegree_list)
      visited: set = set()
      ts_list: list = []
  
      while queue:  # bfs
          element = queue.popleft()
          ts_list.append(element)
          visited.add(element)
  
          for vertex, connected in enumerate(graph[element]):
              if connected == 1:
                  indegree_list[vertex] -= 1
  
                  if indegree_list[vertex] == 0:
                      queue.append(vertex)
  
      return ts_list if len(visited) == len(graph) else []
code_tokens: def topological_sort_kahn_algorithm ( graph : list , vertices : int ) -> list : def get_indegrees ( ) : indegree : list = [ 0 ] * vertices for src in range ( vertices ) : for dest , connect in enumerate ( graph [ src ] ) : indegree [ dest ] += 1 if connect == 1 else 0 return indegree def create_queue ( indegree ) : q : deque = deque ( ) for src , degree in enumerate ( indegree ) : if degree == 0 : q . append ( src ) return q indegree_list : list = get_indegrees ( ) queue : deque = create_queue ( indegree_list ) visited : set = set ( ) ts_list : list = [ ] while queue : element = queue . popleft ( ) ts_list . append ( element ) visited . add ( element ) for vertex , connected in enumerate ( graph [ element ] ) : if connected == 1 : indegree_list [ vertex ] -= 1 if indegree_list [ vertex ] == 0 : queue . append ( vertex ) return ts_list if len ( visited ) == len ( graph ) else [ ]
short_docstring: time complexity: O(V+E)
  Fact: A DAG has at least one vertex with in-degree 0 and one vertex with out-degree 0
short_docstring_tokens: time complexity : O ( V + E ) Fact : A DAG has at least one vertex with in - degree 0 and one vertex with out - degree 0
comment: """
      time complexity: O(V+E)
  
      Fact: A DAG has at least one vertex with in-degree 0 and one vertex with out-degree 0
  
      1. Get in-degree of every node
      2. Pick all the vertices with in-degree as 0 and add them into a queue
      3. Remove a vertex from the queue (Dequeue operation) and then.
          Increment count of visited nodes by 1.
          Decrease in-degree by 1 for all its neighboring nodes.
          If in-degree of a neighboring nodes is reduced to zero, then add it to the queue.
      4. Repeat Step 3 until the queue is empty.
      5.  If count of visited nodes is not equal to the number of nodes in the graph then the
          topological sort is not possible for the given graph.
      """$SEP$# bfs