Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8773483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:18:22+00:00 2026-06-13T18:18:22+00:00

How do you use a Bidirectional BFS to find the shortest path? Let’s say

  • 0

How do you use a Bidirectional BFS to find the shortest path? Let’s say there is a 6×6 grid.
The start point is in (0,5) and the end point is in (4,1). What is the shortest path using bidirectional bfs? There are no path costs. And it is undirected.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:18:23+00:00Added an answer on June 13, 2026 at 6:18 pm

    How does Bi-directional BFS work?

    Simultaneously run two BFS’s from both source and target vertices, terminating once a vertex common to both runs is discovered. This vertex will be halfway between the source and the target.

    Why is it better than BFS?

    Bi-directional BFS will yield much better results than simple BFS in most cases. Assume the distance between source and target is k, and the branching factor is B (every vertex has on average B edges).

    • BFS will traverse 1 + B + B^2 + ... + B^k vertices.
    • Bi-directional BFS will traverse 2 + 2B^2 + ... + 2B^(k/2) vertices.

    For large B and k, the second is obviously much faster the the first.


    In your case:

    For simplicity I am going to assume that there are no obstacles in the matrix. Here is what happens:

    iteration 0 (init):
    front1 = { (0,5) }
    front2 = { (4,1) }
    
    iteration 1: 
    front1 = { (0,4), (1,5) }
    front2 = { (4,0), (4,2), (3,1), (5,1) }
    
    iteration 2:
    front1 = { (0,3), (1,4), (2,5) }
    front2 = { (3,0), (5,0), (4,3), (5,2), (3,2), (2,1) }
    
    iteration 3:
    front1 = { (0,2), (1,3), (2,4), (3,5) }
    front2 = { (2,0), (4,4), (3,3), (5,3), (2,2), (1,1), }
    
    iteration 4:
    front1 = { (0,1), (1,2), .... }
    front2 = { (1,2) , .... }
    

    Now, we have discovered that the fronts intersect at (1,2), together with the paths taken to get there from the source and target vertices:

    path1: (0,5) -> (0,4) -> (0,3) -> (0,2) -> (1,2)
    path2: (4,1) -> (3,1) -> (2,1) -> (1,1) -> (1,2)
    

    We now just need to reverse path 2 and append it to path 1 (removing one of the common intersecting vertices of course), to give us our complete path:

    (0,5) -> (0,4) -> (0,3) -> (0,2) -> (1,2) -> (1,1) -> (2,1) -> (3,1) -> (4,1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a .NET data structure I could use for bidirectional lookup? Here's the
Here is the two classes that I'm use to express a bidirectional OneToMany relationship.
Let's say I have following POJO's using Hibernate. public class User { private String
If I use bidirectional associations in nHibernate, is it necessary for me to add
I use OpenJPA 2.1 on WebSphere Application Server 8. I have a bidirectional oneToMay
Question: I use the bidirectional dicionary class I found here: Bidirectional 1 to 1
I'm searching for the best open source technologies to use to implement a bidirectional
Use Case Show a photo uploaded by the user in a square box with
use C#,want to upload excel file on google doc. bellow syntax use to upload
use Text::Table; my $tb = Text::Table->new(Planet,Radius\nkm,Density\ng/cm^3); $tb->load( [ Mercury,2360,3.7], [ Mercury,2360,3.7], [ Mercury,2360,3.7], );

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.