HW2_April2018_solutions.pdf

Describe an algorithm to do this solution we can

Info icon This preview shows pages 3–4. Sign up to view the full content.

View Full Document Right Arrow Icon
paths, we also want to know how many shortest paths there are. Describe an algorithm to do this. Solution: We can achieve this easily by modifying the Dijkstra Algorithm procedure ModDijkstra ( E, V, s ) Create priority queue Q for v V do dist [ v ] ← ∞ , count [ v ] 1 add v into Q end for dist [ s ] 0 while Q 6 = do u argmin u 0 ( dist [ u 0 ]) remove u from Q for v s.t. ( u, v ) E do τ dist [ u ] + length ( u, v ) if τ < dist [ v ] then dist [ v ] τ , count [ v ] count [ u ] . reset counting end if if τ = dist [ v ] then count [ v ] = count [ v ] + count [ u ] end if end for end while end procedure 3
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
5. Suppose that you are given a directed graph with non-negative edge weights, and a target node t . You want to find the shortest path to target node t from every other node. (Notice that this is different from what we covered in class: in class, we considered the problem of finding the shortest path from the specified node to every other node.) Describe an algorithm to calculate these values. Solution: Apply Dijistra’s algorithm on the reversed graph G R and use target t as source 4
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern