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

feat: add Depth first search #2815

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

adi776borate
Copy link

Description of Change

  • Added a new function to count the number of paths in a graph.
  • Implemented a test case to validate the functionality of the new function.
  • Improved documentation for better understanding of the algorithm.

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational - Doxygen guidelines
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes: The new function counts the number of unique paths between two nodes in a graph. It can be particularly useful in graph-related problems where pathfinding is necessary.

@realstealthninja realstealthninja changed the title feat: add count_paths algorithm with a test case feat: add Depth first search Oct 12, 2024
@adi776borate
Copy link
Author

I've updated the algorithm and added more test cases as per the feedback received. Please review the latest changes. Thank you!

graph/number_of_paths.cpp Outdated Show resolved Hide resolved
graph/number_of_paths.cpp Outdated Show resolved Hide resolved
graph/number_of_paths.cpp Outdated Show resolved Hide resolved
};
std::uint32_t n3 = 5, u3 = 0, v3 = 4;
assert(graph::count_paths(graph3, u3, v3, n3) == 3); // There are 3 paths from node 0 to 4

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a test case for empty array
std::vector<std::vectorstd::uint32_t> graph5 = {{}};

this should return 0 as there is no path

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made the latest changes as per your feedback. I hope this meets the requirements now. Looking forward to your review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants