Java icon indicating copy to clipboard operation
Java copied to clipboard

[FEATURE REQUEST] Topological Sorting using DFS

Open Shewale41 opened this issue 1 month ago • 3 comments

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.

Shewale41 avatar Oct 25 '25 13:10 Shewale41