Skip to content

Fix the DFS implementation of Topological Sort #12791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jun 10, 2025
commit 2b47bd452064fad7110601d8c4b04a18e7723329
3 changes: 0 additions & 3 deletions sorts/topological_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,9 @@ def topological_sort(graph: dict[str, list[str]]) -> list[str]:
result = []

def visit(node: str) -> None:

is_being_visited.add(node)

for neighbor in graph.get(node, []):

if neighbor in visited:
continue

Expand Down Expand Up @@ -103,7 +101,6 @@ def visit(node: str) -> None:


if __name__ == "__main__":

graph: dict[str, list[str]] = {
"A": ["B", "C"],
"B": ["D", "E"],
Expand Down