Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment you will need to make modifications to Algorithm 1 in the course notes (breadth-first search algorithm). Given a digraph G=(V,E) and a
In this assignment you will need to make modifications to Algorithm 1 in the course notes (breadth-first search algorithm). Given a digraph G=(V,E) and a starting node s, Algorithm 1 currently computes two things: 1. The distance d(s,x) from s to x for all vertices xV. 2. For each vertex xV for which d(s,x)=, a parent p[x]. Using the parents we can construct a BFS-tree. We consider here one example. Suppose our starting digraph G1 is the following. When the starting node s=4, then one possible output from Algorithm 1 is the following: This output corresponds to the following BFS-tree: In this assignment your new algorithm will take 4 inputs: - a digraph G=(V,E) - a starting vertex s - a final vertex u - a subset of vertices BV The algorithm you are to write should find a shortest directed path from s to u such that the shortest directed path contains as many of the vertices in B as possible. For example, suppose in addition to graph G1 above, the inputs are s=4,u=6 and B={2,3}. For these inputs, the path in the BFS-tree T1 from s=4 to u=6 is p1=4,1,2,6. Path p1 contains 1 of the vertices in B, since p1B={2}=1. The question is, 'Does there exist another shortest path p from s=4 to u=6 that contains more than 1 of the vertices that belong to B ?' For this example, the answer is yes. Another possible BFS-tree from graph G1 is the following: Now the path from s=4 to u=6 is p2=4,3,2,6 and p2 contains 2 of the vertices from B. Your algorithm should return a single non-negative integer a. This integer is the largest number of vertices from B that can be included in any shortest directed path from s to u. Since d(s,u) is a fixed value, 0ad(s,u)+1, always. The algorithm need not return the actual path from s to u. It is highly recommended that you write your algorithm as a Python function. You may use some other language, but if you do you must also meet the following requirements
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started