

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Professor: Pruhs; Class: ALGORITHM DESIGN; Subject: Computer Science; University: University of Pittsburgh; Term: Fall 2005;
Typology: Exams
1 / 2
This page cannot be seen from the preview
Don't miss anything!


CS 1510 Midterm 1 Fall 2005
Note that the only difference in the first two problems is the definition of total penalty.
For i= 1 to n Place the ith word on the current line if it fits else place the ith word on a new line
For i= 1 to n Place the ith word on the current line if it fits else place the ith word on a new line
(a) (10 points) Give C-like pseudo-code to compute the length of the longest increasing subsequence. The running time of your code should be O(n^2 ). Include some explanation of your variables and data structures, and of your code in general. I suggest you read the following items in this question before you answer this one. (b) (5 points) Explain how to in O(n) time compute the actual subsequence, that is the longest increasing subsequence, from the data structure constructed by your code in part a.
(c) (5 points) Give C-like pseudo-code to compute the length of the longest increasing sub- sequence in O(n^2 ) time and O(n) space. So you can not afford to use an n by n array.
∑n i=1 v
3 i ,^
∏n i=1 vi). Input: positive integers v 1 ,.. ., vn Output: 1 if there exists a subset S of the integers such that
∑ vi ∈S vi! =^
∏ vi ∈S v
3 i. And 0 otherwise. That is, you want to deterimine if there exists a subset S where the sum of the factorials of the numbers in S is equal to the product of the the cubes of the numbers in S.