Question

In: Computer Science

For all algorithm design problems, part of the grade depends on efficiency. For every graphG =...

For all algorithm design problems, part of the grade depends on efficiency. For every graphG = (V,E), the vertex set is {1,2,··· ,n}. We use n to denote the number of vertices and m to denote number of edges. Unless otherwise stated, all graphs are represented as adjacency lists. Each problem is worth 40 points.

  1. Giveanalgorithmthat,givenanundirectedgraphGandnodes,createsanarrayShortestCountin which ShortestCount[i] is the number of shortest paths from s to vertex i. Provide a proof by induction that your algorithm is correct. Derive its runtime.

    (Tip: Start with the BFS algorithm as given in the text, in which nodes are organized into layers Li based on distance from s, and update the counts as you build the tree.)

Solutions

Expert Solution

Method is very simple. We have to perform Breadth First Search with little modification. Here we have to modify BFS that whenever algorithm visit vertex v which is not yet completely explored from vertex u then we increment ShortestCount[v] by ShortestCount[u] because number of shortest path from s to v will increase by ShortestCount[u] once vertex u is also on the way of shortest path from s to v. In this way by the end of algorithm, we will have ShortestCount[i] for every vertex.

ALGO(G=(V,E), n)

1. For i = 1 to n

2........ShortestCount[i] = 0, Color[i] = White

3. Queue.Add(s); ShortestCount[s] = 1 //Add start vertex in Queue

4. While Queue.NotEmpty()

5.........u = Queue.dequeue() ; Set color[u] = Black

6.........For all vertices v adjacent to u with Color[v] != Black .

7................Color[v] = Brown

8...............ShortestCount[v] = ShortestCount[v] + ShortestCount[u] //increment shortest count of v by ShortestCount[u]

9. Return

Now ShortestCount[i] will store number of shortest path from s to vertex i in time O(|V|+|E|) which is time complexity of BFS.

Please comment for any clarification .


Related Solutions

Develop an Algorithm and java program using Design Recipe for the following problems. Draw a flowchart...
Develop an Algorithm and java program using Design Recipe for the following problems. Draw a flowchart to compute the largest and smallest of 4 numbers : Write a Java Program for the above flowchart, use methods(functions), and nested if-else statements. Take input from the user using the Scanner object. Use separate methods to compute the Largest and Smallest of the numbers. Method 1 Name: findLargest(param 1, param 2, param 3, param 4) Method 2 Name: findSmallest(param 1, param 2, param...
This question concerns the case of two input sequences. Prove that every algorithm that outputs all...
This question concerns the case of two input sequences. Prove that every algorithm that outputs all longest common subsequences of two input sequences has a worst-case running time that is exponential. To do so, show how to define, for every positive integer n, two length-n sequences Xn, Yn with lower bound (c^n) different longest common subsequences, where c>1 is a constant. You are allowed to use an alphabet of size n, i.e., the symbols in Xn, Yn can come from...
Which Sorting algorithm are in place algorithm and which are not? Is it advantageous to design...
Which Sorting algorithm are in place algorithm and which are not? Is it advantageous to design in place sorting algorithm? How this in place term is related to the time complexity and space complexity of the program?
a) A highway design includes the intersection of a +4.8% grade with a -4.2% grade at...
a) A highway design includes the intersection of a +4.8% grade with a -4.2% grade at station 1052+75 at elevation 851.50 feet above sea level. Calculate the center-line elevation along this highway for every 50-ft station on a parabolic curve of 600 feet length. b) What is the minimum stopping sight distance on this vertical curve and the maximum safe speed on this section of road for wet pavement
Good performance (obtaining a grade of A+) in this probability class depends on your attendance (A)...
Good performance (obtaining a grade of A+) in this probability class depends on your attendance (A) and completion of assignments (C). The probability that you will receive a grade of A+ are 95%, 75%, 50%, and 0%, if you attend the class and complete the assignments, if you attend but do not complete assignments, if you do not attend but complete assignments, and if you neither attend nor complete assignments, respectively. Further assume that if you attend the class, there...
All necessary steps much show for these problems, please. Use the Euclidean algorithm to find gcd(12345,...
All necessary steps much show for these problems, please. Use the Euclidean algorithm to find gcd(12345, 54321). Write gcd(2420, 70) as a linear combination of 2420 and 70. The work to obtain the gcd is provided. 2420 = 34(70) + 40 70 = 1(40) + 30 40 = 1(30) + 10 30 = 3(10) + 0 Determine if 1177 is prime or not. If it is not, then write 1177 as a product of primes Find gcd(8370, 465) by unique...
Exercises a - b refer to the recursive algorithm SelectionSort (a.) In one part of algorithm...
Exercises a - b refer to the recursive algorithm SelectionSort (a.) In one part of algorithm SelectionSort, the index of the maximum item in a list must be found. This requires comparisons between list elements. In an n-element (unsorted) list, how many such comparisons are needed in the worst case to find the maximum element? How many such comparisons are needed in the average case? (b.) Defining the basic operation as the comparison of list elements and ignoring the amount...
Efficiency in production (as part of allocative efficiency) is achieved if an economy's combination of goods...
Efficiency in production (as part of allocative efficiency) is achieved if an economy's combination of goods (two goods produced with one resource) falls on its Production Possibilities Frontier. Yet allocative efficiency additionally requires optimality in consumption. Explain overall allocative efficiency (do not worry about the possibilities of international trade)-- its conditions in the absence of market failures and why it does not hold in reality.
Efficiency in production (as part of allocative efficiency) is achieved if an economy's combination of goods...
Efficiency in production (as part of allocative efficiency) is achieved if an economy's combination of goods (two goods produced with on resource) falls on its Production Possibilities Frontier. Yet allocative efficiency additionally requires optimality in consumption. Explain overall allocative efficiency (do not worry about the possibilities of international trade)-- its condition in the absence of market failures and why it does not hold in reality.
      Design an algorithm for each of the exercises and type it into a word document....
      Design an algorithm for each of the exercises and type it into a word document. Upload the document to PE1 assignment folder. The roots of quadratic equation: Design an algorithm to find the real roots of a quadratic equation of the form ax2+bx+c=0, where a, b, c are all real numbers and a is nonzero
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT