Skip to content

Conversation

Prathameshk2024
Copy link

  1. Purpose:
    Finds the shortest path between a source and target node in an unweighted graph.

  2. Approach:
    Runs two simultaneous BFS searches — one from the source and one from the target — until both meet.

  3. Initialization:
    Sets up two queues, two visited lists, and two parent arrays for tracking paths.

  4. Search Process:
    Expands nodes alternately from both sides and checks for a meeting node (common visited vertex).

  5. Path Reconstruction:
    Once the meeting node is found, it traces back to form the complete shortest path from source to target.

Output:
Returns the path, distance (number of edges), and a flag found = TRUE if a path exists.

Complexity:

Time: O(b^(d/2)) → faster than normal BFS

Space: O(V)

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.

1 participant