{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

06algfinal - Algorithms CMSC-37000 Final Exam Instructor...

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

View Full Document Right Arrow Icon
Algorithms CMSC-37000 Final Exam. March 14, 2006 Instructor: L´ aszl´ o Babai Show all your work . Do not use text, notes, or scrap paper. When describing an algorithm in pseudocode, explain the meaning of your variables (in English). This exam contributes 30% to your course grade. Take this problem sheet home. 1. (4 points) Given a digraph G by an array of adjacency lists, find an adjacency list representation of the reverse digraph in linear time. De- scribe your algorithm is pseudocode. 2. (12 points) (Segmentation) Consider the list of integers (1 , 2 , . . . , n ). A segment is a contiguous sublist, ( i, i + 1 , . . . , j ) where i j . A segmentation means splitting up the list into segments. For instance, for n = 8, a possible segmentation is (1 , 2 , 3) , (4) , (5 , 6 , 7 , 8). We are given a triangular array p ( i, j ) (1 i j n ) of segment penalties (real numbers); the “penalty” of segment ( i, . . . , j ) is p ( i, j ). The cost of the segmentation is the sum of the penalties of the segments. In the example, the cost is p (1 , 3) + p (4 , 4) + p (5 , 8). Find, in O ( n 3 ) time, the optimal (min-cost) segmentation. Give your algorithm in pseudocode. Make sure you define your variables . Name the method used. 3. (8+4+5) (a) Describe in pseudocode the algorithm that finds the median of n numbers using a linear number of comparisons.
Background image of page 1

Info iconThis 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 ]}