Skip to content

Conversation

piyushkumar0707
Copy link
Contributor

🚀 Overview

This PR adds a comprehensive implementation of the Breadth-First Search (BFS) algorithm with advanced features including shortest path finding and distance-based vertex discovery.

✨ Features

  • Queue-based BFS traversal - Level-by-level graph exploration
  • Shortest path finding - Find shortest unweighted path between vertices
  • Distance-based search - Find all vertices at specific distance
  • Path reconstruction - Complete path from source to target
  • Comprehensive documentation - Time O(V+E) and space O(V) complexity
  • Multiple utility functions - Various BFS applications in one file

🎯 Why This Matters

BFS is essential for:

  • Shortest path in unweighted graphs
  • Level-order traversal of trees
  • Connected components analysis
  • Social network analysis (degrees of separation)
  • Web crawling algorithms
  • GPS navigation (unweighted scenarios)

📚 Implementation Details

  • Time Complexity: O(V + E) for traversal, path finding
  • Space Complexity: O(V) for queue and visited tracking
  • Algorithm: Queue-based level-by-level exploration
  • Special Features:
    • bfs_shortest_path() - Returns path and distance
    • bfs_vertices_at_distance() - Finds vertices at exact distance

🧪 Testing

Comprehensive examples including:

  • Basic BFS traversal from different starting points
  • Shortest path finding with path reconstruction
  • Distance-based vertex discovery
  • Complex connected graphs with multiple components

📁 Files Added

  • graph_algorithms/breadth_first_search.r - Complete BFS implementation
  • Updated DIRECTORY.md with BFS entry

🔗 Complements

This pairs perfectly with DFS to provide complete graph traversal coverage for the repository.

🎃 Hacktoberfest 2025

Adds another fundamental algorithm with practical applications, enhancing the repository's educational value for computer science students.

- Implement BFS with queue-based traversal
- Include shortest path finding functionality
- Add function to find vertices at specific distances
- Comprehensive examples with complex graphs
- Create new graph_algorithms directory
- Update DIRECTORY.md to include the new algorithm
@Copilot Copilot AI review requested due to automatic review settings October 4, 2025 18:15
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a new Breadth-First Search (BFS) implementation with shortest path and distance-based utilities, plus an index entry in DIRECTORY.md.

  • Implements three BFS-related functions (traversal, shortest path, vertices at distance).
  • Adds embedded example/demo code executing on load.
  • Updates directory listing with a Graph Algorithms section.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 12 comments.

File Description
graph_algorithms/breadth_first_search.r Adds BFS traversal, shortest path, and distance query functions plus inline executable examples.
DIRECTORY.md Adds Graph Algorithms section pointing to new BFS implementation.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@siriak
Copy link
Member

siriak commented Oct 4, 2025

Please check the comments

@piyushkumar0707
Copy link
Contributor Author

@siriak sir all conflicts has been resolved

@siriak siriak merged commit b0f8ccf into TheAlgorithms:master Oct 5, 2025
2 checks passed
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