Skip to content

[FEATURE REQUEST] Topological Sorting using DFS #6938

@Shewale41

Description

@Shewale41

What would you like to Propose?

Title: Add Topological Sorting Algorithm using Depth-First Search (DFS)


🧠 Overview

Implement a DFS-based topological sort for directed acyclic graphs (DAGs). This algorithm is crucial in scheduling, dependency resolution, and compiler design.

📂 Implementation Details

  • Folder: src/main/java/com/thealgorithms/datastructures/graphs/
  • Filename: TopologicalSortDFS.java
  • Approach:
    • Perform DFS traversal maintaining visited nodes.
    • Push finished nodes to a stack and pop for topological order.
    • Detect cycles to validate DAG property.

✅ Expected Deliverables

  • Implementation with adjacency list representation.
  • Test cases with valid DAGs and cyclic graphs.
  • Well-commented explanation and sample output.

🧑‍💻 Additional Notes

This algorithm fills an important gap in graph algorithms and complements existing BFS and shortest-path methods.

Issue details

🧠 Overview

Implement a DFS-based topological sort for directed acyclic graphs (DAGs). This algorithm is crucial in scheduling, dependency resolution, and compiler design.

Additional Information

🧠 Overview

A Threaded Binary Tree improves binary tree traversal efficiency by replacing null pointers with in-order predecessor or successor links. This reduces stack usage and recursion overhead.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions