SHOW AND EXPLAIN ALL WORK CLEARLY! NO SCRIBBLES! THE FOLLOWING HAS TO DO WITH US
ID: 3912312 • Letter: S
Question
SHOW AND EXPLAIN ALL WORK CLEARLY! NO SCRIBBLES! THE FOLLOWING HAS TO DO WITH USING EITHER BREADTH FIRST SEARCH OR DEPTH FIRST SEARCH.
10. A number of art museums around the country have been featuring work by an artist named Mark Lombardi (1951-2000), consisting of a set of intricately rendered graphs. Building on a great deal of research, these graphs encode the relationships among people involved in major political scandals over the past several decades: the nodes correspond to partici- pants, and each edge indicates some type of relationship between a pair of participants. And so, if you peer closely enough at the drawings, you can trace out ominous-looking paths from a high-ranking U.S. govern- ment official, to a former business partner, to a bank in Switzerland, to a shadowy arms dealer. Such pictures form striking examples of social networks, which, as we discussed in Section 3.1, have nodes representing people and organi zations, and edges representing relationships of various kinds. And the short paths that abound in these networks have attracted considerable attention recently, as people ponder what they mean. In the case of Mark Lombardi's graphs, they hint at the short set of steps that can carry you from the reputable to the disreputable. Of course, a single, spurious short path between nodes v and w in such a network may be more coincidental than anything else; a large number of short paths between v and w can be much more convincing. So in addition to the problem of computing a single shortest v-w path in a graph G, social networks researchers have looked at the problem of determining the number of shortest v-w paths. This turns out to be a problem that can be solved efficiently. Suppose we are given an undirected graph G(V, E), and we identify two nodes v and w in G. Give an algorithm that computes the number of shortest v-w paths in G. (The algorithm should not list all the paths; just the number suffices.) The running time of your algorithm should be O(m + n) for a graph with n nodes and m edgesExplanation / Answer
DFS-A(G,s)
for all v in V[G] do
visited[v] := false
end for
S := EmptyStack
Push(S,s)
while not Empty(S) do
u := Pop(S)
if not visited[u] then
visted[u] := true
for all w in Adj[u] do
if not visited[w] then
Push(S,w)
end if
end for
end if
end while
//this does not exceed time complexity of O(n+m).
//DFS-A can have multiple copies on the stack at the same time. However, the total number of iterations of the innermost loop of DFS-A cannot exceed the number of edges of G, and thus the size of S cannot exceed m. The running time of DFS-A is O(n + m).
// im providing you other solution which is also with the same time complexity, bt in a different approach.
2nd Model:
DFS-B(G,s)
for all v in V[G] do
visited[v] := false
end for
S := EmptyStack
visited[s] := true
Push(S,s)
while not Empty(S) do
u := Pop(S)
if there is at least one unvisited vertex in Adj[u] then
Pick w to be any unvisited vertex in Adj[u]
Push(S,u)
visited[w] := true
Push(S,w)
end if
end while
//No vertex can be on the stack in more than one place. The size of S is thus not more than n. The time complexity of DFS-B is O(n + m).
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.