Please help me with this algorithm question. Thank you so much. ================
ID: 3590157 • Letter: P
Question
Please help me with this algorithm question. Thank you so much.
==========================================================
necteu patils IOl SUOL. 11l dloll Crrectiess i dlaly2e lUs tlme conipiexlty 3. (30 points) Design an algorithm that runs in time O(VI E) that takes as input a con- nected, undirected, unweighted graph G = (V,E), a source vertex s E V, and a target vertex t V, and finds the number of shortest paths from s to t. Argue your algorithm's correctness and analyze its time complexity.Explanation / Answer
This can be done using BFS..
Here is the algorithm...
(i) First mark the all nodes as visited
(ii) Do not add the nodes to the queue
(iii) Add the nodes to the DFS along with number of incoming paths.
(iv) Ignore adding nodes to stack if it is visited
(v) If node found in queue then do not add it but add counts together (eg.. if user visits one->two, then increase two count value from 0 to 1)
(vi) Walkthrough the nodes in queue and notedown he counts.
(vii) When facing final node, the number stored for that nodee is the our required number of shortest paths.
Here complexity is O( |V| + |E| )
Proof: Here nodes are stored in queue only once (no nodes will repeate), So |v|
And Loop over all vertices edges with while loop, so {E}
So total complexity will be O( |V| + |E| )
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.