How can I find the shortest cycle in a simple (not directed ) bipartite graph using Breadth First Search ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
In a bipartite graph, the shortest possible circle is at least 4 edges long. Since you are using breadth first search you will find the optimum quite fast as long as you increase your travel distance accordingly. All possible 4 edges long path, all possible 5 edges long paths, and so on. The moment you find a path that is a circle, you are done, it is the shortest possible or at least tied for that prize.
Keep all paths explored as to only increase these by 1 more edge each cycle of the search. And use BFS to make sure you have explored all paths.