Docsity

UC Berkeley CS 170 Final Exam May 16, Exams of Algorithms and Programming

Toggle sidebar
bg1
UC Berkeley—CS 170 Final
Lecturer: Satish Rao May 16
Final for CS 170
Print your name: ,
(last) (first)
Sign your name:
Write your section number (e.g., 101):
Write your SID:
Three pages of notes is permitted. No electronic devices, e.g. cell phones and calculators,
are permitted. Do all your work on the pages of this examination. If you need more space,
you may use the reverse side of the page, but try to use the reverse of the same page where
the problem is stated.
You have 180 minutes. The questions are of varying difficulty, so avoid spending too long
on any one question.
In all algorithm design problems, you may use high-level pseudocode or sketch it in English
as long as you make yourself clear.
WARNING: Almost all the answers should be short. No more than a two or three
sentences (or a few equations) should suffice. No novels please. Writing more may negatively
impact your grade.
DO NOT TURN THE PAGE UNTIL YOU ARE TOLD TO DO SO.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download UC Berkeley CS 170 Final Exam May 16 and more Exams Algorithms and Programming in PDF only on Docsity!

UC Berkeley—CS 170 Final Lecturer: Satish Rao May 16

Final for CS 170

Print your name:

(last) (first)

Sign your name:

Write your section number (e.g., 101):

Write your SID:

Three pages of notes is permitted. No electronic devices, e.g. cell phones and calculators, are permitted. Do all your work on the pages of this examination. If you need more space, you may use the reverse side of the page, but try to use the reverse of the same page where the problem is stated.

You have 180 minutes. The questions are of varying difficulty, so avoid spending too long on any one question.

In all algorithm design problems, you may use high-level pseudocode or sketch it in English as long as you make yourself clear.

WARNING: Almost all the answers should be short. No more than a two or three sentences (or a few equations) should suffice. No novels please. Writing more may negatively impact your grade.

DO NOT TURN THE PAGE UNTIL YOU ARE TOLD TO DO SO.

Problem Score/Points Name/Section/etc. 1 / 2 / 3 / 4 / 5 / 6 / 7 / 8 / 9 / 10 / Total /

1. Chapter 1.

  1. Prove that if a = x mod n and b = y mod n that a + b = x + y mod n.
  2. Euclid’s extended theorem states that for any a, b, there are integers x and y where gcd(a, b) = xa + by. Use this theorem to prove that a has an multiplicative inverse mod p if p is a prime.
  3. Give an RSA private/public key pair using p = 5 and q = 7.

3. Chapter 3.

  1. Consider a depth first search the computed pre and post ordering numberings. Which of the following cannot be the post order numberings and a node u where pre(u) = 3 and post(u) = 13. If there is an edge (u, v), which of the following [pre, post] numberings for v is not possible: [5, 8] or [6, 17] or [1, 6] or [2, 14] or [18, 27].
  2. For a dag, which of the above pairs is not possible?

4. Chapter 4

  1. In the union-find data structure with union by rank, give a lower bound on the number of nodes in a rank r tree. (Assume that initially the rank of a node is set to 0.)
  2. If in some step of the greey set cover algorithm one covered 15 out of the 78 remaining elements, give a lower bound on the number of sets required by any optimal solution to the original set cover problem require.

6. Chapter 6

  1. Describe the subproblem definition and update rule for a dynamic programming so- lution for the Knapsack problem given items (w 1 , v 1 )... (wn, vn), that runs in time O(nV ), where V is the total value of the items. (In the book, the runtime was (nW ), so be careful. You will get zero credit.)
  2. Describe the subproblem definition and update rule for a dynamic programming so- lution for the Knapsack problem above that does not allow one to reuse items, again your runtime is allowed to run in time depending on V (but not W .)
  3. What is the subproblem definition and update rule for a dynamic programming solu- tion for the problem of finding a solving the edit distance problem on strings x 1... xn and y 1... ym where the cost of the first gap in a sequence is 2 and a subsequent gap is cost 1. (E.g., the cost of the alignment: a − −b and axyb is 3.)

7. Chapter 7

I want to make shoes: Air Jordans and Ground Raos. I make a profit of 100 dollars on Air Jordans, and a loss of 10 dollars on Ground Raos. To keep myself happy, I have to make at no fewer than 1 Ground Rao for each Air Jordan. I can only make 110 shoes in all, and each Air Jordan takes 2 units of talent where as a ground Rao takes (wastes?) 1 unit of talent. The total talent is 100.

  1. Express my profit maximization problem as a linear program.
  2. What is the dual program?
  3. Give the coordinates of two vertices of the simplex.
  4. Illustrate the simplex method on this simplex, beginning from the non-optimal vertex (0, 0).

9. Chapter 8

  1. Give a reduction from 3SAT (the set of satisfiable formulas with at most three literals per clause) to 3SAT 3 (the set of satisfiable 3 − SAT formulas where each variable appears at most three times.)
  2. Give a reduction from Subset-Sum (given a 1 ,... , an and a number K find a subset of the ai’s that sum to K) to the Knapsack without repitition problem (given a set of items, (w 1 , v 1 ),... , (wn, vn) and a weight W and a value V find a subset of items that have total weight at most W and value at least V .)

10. Chapter 9

Give a factor of two approximation algorithm for the 2-TSP problem where one is given a set of cities, distances among the cities that obey triangle inequalities, and two cities a and b, where salesmen are based. One wishes to find a tour for each salesman where each city is visited by one of the salesman (each tour return the salesman home.)