Skip to content
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

[ALGO] Topological Sorting (DFS-Based) #70

Closed
6 tasks
bobluppes opened this issue Aug 13, 2023 · 6 comments
Closed
6 tasks

[ALGO] Topological Sorting (DFS-Based) #70

bobluppes opened this issue Aug 13, 2023 · 6 comments
Assignees
Labels
enhancement New feature good first issue Good for newcomers help wanted Extra attention is needed

Comments

@bobluppes
Copy link
Owner

Topological Sorting (DFS-Based)

A topological sort is a linear ordering of all vertices in a directed graph such that a vertex is only visited after its dependencies are visited. The goal of this issue is to implement topological sorting based on DFS.

The existing DFS functionality (depth_first_traverse) should be re-used, rather than implementing a new DFS traversal.

See the wikipedia entry for more details.

Syntax

The algorithm should have the following syntax:

template <typename V, typename E, graph_type T>
[[nodiscard]] return_type your_algorithm_name(const graph<V, E, T>& graph);

This should live in the graaf::algorithm namespace under include/graaflib/algorithm/topological_sorting.h.

Definition of Done

This issue is done when:

  • The algorithm is implemented
  • The new function has a javadoc-style comment explaining the interface
  • Appropriate tests are added under test/graaflib/algorithm/topological_sorting_test.cpp
  • A test coverage of at least 95% is reached
  • A documentation entry is added under docs/docs/algorithms under the appropriate category
    • Just adding a short description and the algorithm syntax here is fine
    • See the wiki on how to build the documentation locally
  • The algorithm is added to the list of algorithms in README.md
@bobluppes bobluppes added enhancement New feature help wanted Extra attention is needed good first issue Good for newcomers labels Aug 13, 2023
@Hromz
Copy link
Contributor

Hromz commented Aug 17, 2023

Hey @bobluppes ! Assign to me please. I wanna work on this after MST.

@bobluppes
Copy link
Owner Author

Hi @Hromz, of course, would be happy to! Assigning this to you

@Hromz
Copy link
Contributor

Hromz commented Sep 4, 2023

Hey @bobluppes, You have mentioned using existing DFS functionality. Right now, the solution I can propose is to store edges and process them after. It would be simple if we had a post-order callback.
Another approach is to add a new DFS (12 lines of code) and use the existing cycle detection algorithm.
Correct me if I'm wrong or missed something.
I'm looking forward to your answer! :)

@bobluppes
Copy link
Owner Author

Hi @Hromz, looking at the pseudo algorithm on wikipedia, do you mean a callback to add the node to the list of sorted nodes?

I would also be fine with adding a separate DFS implementation for this functionality.

@Hromz
Copy link
Contributor

Hromz commented Sep 5, 2023

Correct, callback to the list. Alright, i'll add separate DFS implementation and change it in the future if needed.

@bobluppes
Copy link
Owner Author

Correct, callback to the list. Alright, i'll add separate DFS implementation and change it in the future if needed.

Thanks! For now we can keep it in the anonymous namespace of the topological sorting algorithm. We can see if it makes sense to expose it later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants