Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: TheAlgorithms/Python
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: vedprakash226/Python
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 4 commits
  • 1 file changed
  • 2 contributors

Commits on Oct 20, 2024

  1. Issue 12192 fixed, Traversal direction is considered from top to bott…

    …om as stated.
    Ved Prakash Vishwakarma authored and Ved Prakash Vishwakarma committed Oct 20, 2024
    Copy the full SHA
    e08aadd View commit details
  2. Issue 12192 fixed with all checks passed

    Ved Prakash Vishwakarma authored and Ved Prakash Vishwakarma committed Oct 20, 2024
    Copy the full SHA
    239b8c8 View commit details
  3. comment updated

    Ved Prakash Vishwakarma authored and Ved Prakash Vishwakarma committed Oct 20, 2024
    Copy the full SHA
    7ac458d View commit details

Commits on Oct 23, 2024

  1. Copy the full SHA
    c57f334 View commit details
Showing with 3 additions and 2 deletions.
  1. +3 −2 sorts/topological_sort.py
5 changes: 3 additions & 2 deletions sorts/topological_sort.py
Original file line number Diff line number Diff line change
@@ -17,16 +17,17 @@

def topological_sort(start: str, visited: list[str], sort: list[str]) -> list[str]:
"""Perform topological sort on a directed acyclic graph."""
# consider edge direction from top to bottom
current = start
# add current to visited
visited.append(current)
neighbors = edges[current]
# as the current node encounter add it to the topo sort list
sort.append(current)
for neighbor in neighbors:
# if neighbor not in visited, visit
if neighbor not in visited:
sort = topological_sort(neighbor, visited, sort)
# if all neighbors visited add current to sort
sort.append(current)
# if all vertices haven't been visited select a new one to visit
if len(visited) != len(vertices):
for vertice in vertices: