Question

In: Computer Science

give an example of a simple, undirected, weighted graph such that breadth-firstsearch outputs a search-tree that...

give an example of a simple, undirected, weighted graph such that breadth-firstsearch outputs a search-tree that is not a single source shortest path tree. Youranswer must

(a) Specify the graphG= (V, E)by specifyingVandE.

(b) Specify the weight functionw.

(c) Specify an ordering of the vertices and the search-tree output by breadth-first search assuming the specified graph and ordering.

(d) Specify a valid single-source shortest path treeT= (V, ET)by specifyingETand its root, the first vertex in your specified ordering.

(e) Include a clear explanation of why the search-tree output by breadth-firstsearch is not a valid single-source shortest path tree ofG.

Solutions

Expert Solution

This is Dijikstra's algorithm

Given a graph and a source vertex in the graph, find shortest paths from source to all vertices in the given graph.

Dijkstra’s algorithm is very similar to Prim’s algorithm for minimum spanning tree. Like Prim’s MST, we generate a SPT (shortest path tree) with given source as root. We maintain two sets, one set contains vertices included in shortest path tree, other set includes vertices not yet included in shortest path tree. At every step of the algorithm, we find a vertex which is in the other set (set of not yet included) and has a minimum distance from the source.

Below are the detailed steps used in Dijkstra’s algorithm to find the shortest path from a single source vertex to all other vertices in the given graph.
Algorithm
1) Create a set sptSet (shortest path tree set) that keeps track of vertices included in shortest path tree, i.e., whose minimum distance from source is calculated and finalized. Initially, this set is empty.
2) Assign a distance value to all vertices in the input graph. Initialize all distance values as INFINITE. Assign distance value as 0 for the source vertex so that it is picked first.
3) While sptSet doesn’t include all vertices
….a) Pick a vertex u which is not there in sptSet and has minimum distance value.
….b) Include u to sptSet.
….c) Update distance value of all adjacent vertices of u. To update the distance values, iterate through all adjacent vertices. For every adjacent vertex v, if sum of distance value of u (from source) and weight of edge u-v, is less than the distance value of v, then update the distance value of v.

Let us understand with the following example:

The set sptSet is initially empty and distances assigned to vertices are {0, INF, INF, INF, INF, INF, INF, INF} where INF indicates infinite. Now pick the vertex with minimum distance value. The vertex 0 is picked, include it in sptSet. So sptSet becomes {0}. After including 0 to sptSet, update distance values of its adjacent vertices. Adjacent vertices of 0 are 1 and 7. The distance values of 1 and 7 are updated as 4 and 8. Following subgraph shows vertices and their distance values, only the vertices with finite distance values are shown. The vertices included in SPT are shown in green colour.


Pick the vertex with minimum distance value and not already included in SPT (not in sptSET). The vertex 1 is picked and added to sptSet. So sptSet now becomes {0, 1}. Update the distance values of adjacent vertices of 1. The distance value of vertex 2 becomes 12.

Pick the vertex with minimum distance value and not already included in SPT (not in sptSET). Vertex 7 is picked. So sptSet now becomes {0, 1, 7}. Update the distance values of adjacent vertices of 7. The distance value of vertex 6 and 8 becomes finite (15 and 9 respectively).

Pick the vertex with minimum distance value and not already included in SPT (not in sptSET). Vertex 6 is picked. So sptSet now becomes {0, 1, 7, 6}. Update the distance values of adjacent vertices of 6. The distance value of vertex 5 and 8 are updated.

We repeat the above steps until sptSet does include all vertices of given graph. Finally, we get the following Shortest Path Tree (SPT).


Related Solutions

ive an example of a simple, undirected graph that has a single source shortestpath tree which...
ive an example of a simple, undirected graph that has a single source shortestpath tree which breadth-first search will not return for any ordering of its vertices.Your answer must (a) Specify the graphG= (V, E)by specifying V and E. (b) Specify the single source shortest path treeT= (V, ET) by specifying E T and also specifying the roots∈V. (c) and include a clear explanation of why the breadth-first search algorithm we discussed in class will never produce T for any...
Using C++: Create a function to search an undirected weighted graph and find the highest weighted...
Using C++: Create a function to search an undirected weighted graph and find the highest weighted edge between two specific values. This should include a class declaration and the definition for all required members that are needed to support the search. NO NEED to code those members. You can assume any other data structures such as stack, heap, or linked list is defined (so you can use their standard functions without declaring or defining them).
Which graph search method will be better for finding a cycle in an undirected graph: a...
Which graph search method will be better for finding a cycle in an undirected graph: a BTS or a DFS? In detail, describe (create) an algorithm for finding a cycle in any undirected graph, explaining why the algorithm assures to find a cycle if there exists one.
2) Explain the difference between TREE-SEARCH and GRAPH-SEARCH. Support your answer with an example.
2) Explain the difference between TREE-SEARCH and GRAPH-SEARCH. Support your answer with an example.
Describe the A* algorithm. Give one search example: give one graph as example with a heuristic...
Describe the A* algorithm. Give one search example: give one graph as example with a heuristic function for each node; give the start node and goal node; apply the A* algorithm on this problem. Show the steps and sequence of nodes visited in order that leads to the optimal solution.
Give an algorithm to detect whether a given undirected graph contains a cycle. If the graph...
Give an algorithm to detect whether a given undirected graph contains a cycle. If the graph contains a cycle, then your algorithm should output one. (It should not output all cycles in the graph, just one of them.) The running time of your algorithm should be O(m + n) for a graph with n nodes and m edges.
In a simple undirected graph H the sum of vertex degrees is 60. What is the...
In a simple undirected graph H the sum of vertex degrees is 60. What is the smallest possible number of vertices in this graph? What is the largest possible number of vertices in the graph?
Write a python code to generate a random undirected weighted graph and calculate the shortest distance...
Write a python code to generate a random undirected weighted graph and calculate the shortest distance from node i to node j (shortest path algorithm) where i is not equal to j. Store the results in text file. Thank you!
5. Suppose we are given both an undirected graph G with weighted edges and a minimum...
5. Suppose we are given both an undirected graph G with weighted edges and a minimum spanning tree T of G . (a) Describe an algorithm to update the minimum spanning tree when the weight of a single edge e is decreased. (b) Describe an algorithm to update the minimum spanning tree when the weight of a single edge e is increased. In both cases, the input to your algorithm is the edge e and its new weight; your algorithms...
Suppose you are given an undirected, connected, weighted graph G. You want to find the heaviest...
Suppose you are given an undirected, connected, weighted graph G. You want to find the heaviest weight set of edges that you can remove from G so that G is still connected. Propose an optimal greedy algorithm for this problem and prove that it is optimal. (Hint: use matroid theory!).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT