Docsity

Sample Midterm Exam - Algorithm Design and Analysis | ECS 122A, Exams of Computer Science

Toggle sidebar
bg1
ECS 122A: Algorithm Design and Analysis Handout M
UC Davis — Charles Martel May 2, 2008
Sample Midterm Exam
1 Short answers [40 points]
•(10) Part A. Solve the following recurrence by finding a Θ() bound for T(n). Assume
that T(n) is 1 for n≤1, and otherwise is defined by the recurrence.
T(n) = 15T(n/4) + 5n2+ 7n
•(15) Part B. For the closest point algorithm we discussed in class, suppose we knew
that every time we divide some number of points k, when we execute the combine step
(where we use the “strip” points which are within dof the dividing line) at most √k
points are within dof the dividing line.
– i) For this setting write a recurrence relation for W(n), the maximum number
of distance computations (where we compute the distance between two pairs of
points). DO NOT use big O notation. Try and give the constants as precisely as
you can. Note that you can ignore work other than distance computations.
– ii) Solve your recurrence to within Θ accuracy.
2 Short answers Midterm 2 version [40 points]
•(10) Part A. Solve the following recurrence by finding a Θ() bound for T(n). Assume
that T(n) is 1 for n≤1, and otherwise is defined by the recurrence.
T(n) = 15T(n/3) + 5n2+ 7n
•(15) Part B. For the closest point algorithm we discussed in class, suppose we knew
that every time we execute the combine step (where we use the “strip” points which
are within dof the dividing line) at most half the points are within dof the dividing
line.
– i) For this setting write a recurrence relation for W(n), the maximum number
of distance computations (where we compute the distance between two pairs of
points). DO NOT use big O notation. Try and give the constants as precisely as
you can. Note that you can ignore work other than distance computations.
– ii) Solve your recurrence to within Θ accuracy.
pf3

Partial preview of the text

Download Sample Midterm Exam - Algorithm Design and Analysis | ECS 122A and more Exams Computer Science in PDF only on Docsity!

ECS 122A: Algorithm Design and Analysis Handout M UC Davis — Charles Martel May 2, 2008

Sample Midterm Exam

1 Short answers [40 points]

  • (10) Part A. Solve the following recurrence by finding a Θ() bound for T (n). Assume that T (n) is 1 for n ≤ 1, and otherwise is defined by the recurrence.

T (n) = 15T (n/4) + 5n^2 + 7n

  • (15) Part B. For the closest point algorithm we discussed in class, suppose we knew that every time we divide some number of points k, when we execute the combine step (where we use the “strip” points which are within d of the dividing line) at most

k points are within d of the dividing line.

  • i) For this setting write a recurrence relation for W (n), the maximum number of distance computations (where we compute the distance between two pairs of points). DO NOT use big O notation. Try and give the constants as precisely as you can. Note that you can ignore work other than distance computations.
  • ii) Solve your recurrence to within Θ accuracy.

2 Short answers Midterm 2 version [40 points]

  • (10) Part A. Solve the following recurrence by finding a Θ() bound for T (n). Assume that T (n) is 1 for n ≤ 1, and otherwise is defined by the recurrence.

T (n) = 15T (n/3) + 5n^2 + 7n

  • (15) Part B. For the closest point algorithm we discussed in class, suppose we knew that every time we execute the combine step (where we use the “strip” points which are within d of the dividing line) at most half the points are within d of the dividing line. - i) For this setting write a recurrence relation for W (n), the maximum number of distance computations (where we compute the distance between two pairs of points). DO NOT use big O notation. Try and give the constants as precisely as you can. Note that you can ignore work other than distance computations. - ii) Solve your recurrence to within Θ accuracy.

ECS 122A Handout M: Sample Midterm Exam 2

3 Algorithm Usage

For each of the following settings specify which of the algorithms we have studied you would use to solve it. You should use the most efficient algorithm (considering both time and space), and you may choose an algorithm which needs minor modifications to work. Briefly justify your choice, indicate how the problem would be solved, and give the running time of your algorithm.

  • You are given a computer network where some pairs of computers (but not all) are connected by a 2-way communication line (so if there is a line between i and j you can send messa ges from i to j and from j to i). Each link has an associated toll b(i, j) which you must pay if you send a message along this link (note b(i, j) = b(j, i). There are c computers and L links in the network. 1. There are some free links where the toll is zero. We want to know if all computers can talk to each other using these free links (so we can ignore the other ones). Also, when it is possible, we want a minimum size set of free links which allows all such computers to talk to each other. 2. Suppose that we determined in i) that there was a free path between each pair of computers. We now consider the delay T [i, j] on the link from i to j which is how long it takes to send such a message. For a path i − j − k the delay is T [i, j] + T [j, k]. Given two specified vertices x and y describe how to find the route of minimum delay from x to y which uses only free arcs. You may assume the graph is stored in adjacency list form where each vertex i has its neighbors sorted in order of increasing toll cost and that f is the number of free arcs in the graph.

4 Minimum Spanning Tree

  • Given an undirected graph with negative and positive edge weights, does Prim’s algo- rithm still find the correct minimum spanning tree?
  • Give an efficient algorithm to find the MAXIMUM weight spanning tree of a graph G (undirected). Determine your algorithms’s running time.

5 Shortest Path

  • Find the shortest path from a source s to all others in a directed graph where all edge weights are 1. Pick the fastest algorithm to solve and give the run time.