cs5800recitations.pdf - CS5800 Recitations A Selection of...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS5800 Recitations A Selection of Questions+Answers Fall 2017 – CCIS, NEU Problem 1. Suppose you start at the top-left corner of an n × m 2D array A and want to get to the bottom-right corner. The only way you can move is by either going right or going down. Moreover, every cell A ij has a positive integer C ij associated with it. If a path uses A ij , a price equal to C ij has to be paid. Design and analyze an algorithm that find the least expensive path. Solution sketch. This problem is best solved using dynamic programming. Let P [ i, j ] denote the cost of the cheapest path from A ij to A mn . Clearly, P [ m, n ] = C mn . Now, assume that we are in cell A ij for 1 i < m and 1 j < n . Since there are only two possible moves from any cell, we can write the cost recursively as P [ i, j ] = C ij + min { P [ i + 1 , j ] , P [ i, j + 1] } . Extra care is needed to handle corner cases, such as when i = m or j = n . The running time is O ( mn ), since, in a bottom-up approach, each cell is processed exactly once. Finally, note that this recurrence gives us the optimal value not the path itself. Nonetheless, the corresponding path can always be found by appropriate bookkeeping (see the books). Problem 2. Suppose that we are given a directed acyclic graph G = ( V, E ) with real- valued edge weights and two distinguished vertices s and t . Describe an algorithm for finding a longest weighted simple path from s to t . What is the efficiency of your algorithm? Can the same algorithm be applied to an undirected graph?
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

0/0 PREVIEWS LEFT
Sign up to access 24/7 study resources for your classes

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