Longest simple path in a directed acyclic graph Suppose that we are given a directed acyclic graph G D .V; E/ with realvalued edge weights and two distinguished vertices s and t. Describe a dynamicprogramming approach for finding a longest weighted simple path from s to t. What does the subproblem graph look like? What is the efficiency of your algorithm?
Read moreTable of Contents
Textbook Solutions for Introduction to Algorithms
Question
Image compression by seam carving We are given a color picture consisting of an m n array A1 : : m; 1 : : n of pixels, where each pixel specifies a triple of red, green, and blue (RGB) intensities. Suppose that we wish to compress this picture slightly. Specifically, we wish to remove one pixel from each of the m rows, so that the whole picture becomes one pixel narrower. To avoid disturbing visual effects, however, we require that the pixels removed in two adjacent rows be in the same or adjacent columns; the pixels removed form a seam from the top row to the bottom row where successive pixels in the seam are adjacent vertically or diagonally. a. Show that the number of such possible seams grows at least exponentially in m, assuming that n>1. b. Suppose now that along with each pixel Ai; j , we have calculated a realvalued disruption measure di; j , indicating how disruptive it would be to remove pixel Ai; j . Intuitively, the lower a pixels disruption measure, the more similar the pixel is to its neighbors. Suppose further that we define the disruption measure of a seam to be the sum of the disruption measures of its pixels. Dynamic Programming Give an algorithm to find a seam with the lowest disruption measure. How efficient is your algorithm?
Solution
The first step in solving 15 problem number 8 trying to solve the problem we have to refer to the textbook question: Image compression by seam carving We are given a color picture consisting of an m n array A1 : : m; 1 : : n of pixels, where each pixel specifies a triple of red, green, and blue (RGB) intensities. Suppose that we wish to compress this picture slightly. Specifically, we wish to remove one pixel from each of the m rows, so that the whole picture becomes one pixel narrower. To avoid disturbing visual effects, however, we require that the pixels removed in two adjacent rows be in the same or adjacent columns; the pixels removed form a seam from the top row to the bottom row where successive pixels in the seam are adjacent vertically or diagonally. a. Show that the number of such possible seams grows at least exponentially in m, assuming that n>1. b. Suppose now that along with each pixel Ai; j , we have calculated a realvalued disruption measure di; j , indicating how disruptive it would be to remove pixel Ai; j . Intuitively, the lower a pixels disruption measure, the more similar the pixel is to its neighbors. Suppose further that we define the disruption measure of a seam to be the sum of the disruption measures of its pixels. Dynamic Programming Give an algorithm to find a seam with the lowest disruption measure. How efficient is your algorithm?
From the textbook chapter Dynamic Programming you will find a few key concepts needed to solve this.
Visible to paid subscribers only
Step 3 of 7)Visible to paid subscribers only
full solution