CMPS 256 - Advanced Algorithms and Data Structures: Final Examination, Exams of Algorithms and Programming

Aub finals for programming algorithms and data structures dated 2013-2014, with solutions

Typology: Exams

2012/2013

Uploaded on 05/14/2023

unknown user
unknown user 🇱🇧

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMPS 256 ADVANCED ALGORITHMS AND DATA STRUCTURES
Summer 2013 14
Final Examination
Monday July 14, Bliss 105, 8:00 10:00 a.m.
Instructions.
This quiz is scored out of 100.
This quiz is open book and open notes: you can use the textbook, notes you have taken in class,
and your homework solutions.
Show your work, as partial credit will be given.
You may use any algorithm that was covered in class. Just give the name of the algorithm and
the chapter or page number in the book where the algorithm is given. If taken from your lecture
notes, just say “lecture notes.”
For questions that require you to write an algorithm, you must prove that your algorithm has
the required running time.
Please draw a horizontal line to separate each answer from the next.
Best of luck!
Problem 1 (20 points).
Give the running time of the following, expressed only in terms of n. You may express this as
Θ(f(n)), for suitable f(n).
{n > 0}
i:= 1;
while in3
j:= 1;
while ji
j:= j+ 1;
endwhile
i:= i+ 1;
endwhile
Sample solution. Running time given by the following summation, by putting the limits of
the loop as the limits of the sum:
n3
X
i=1
i
X
j=1
1
the summand is 1 since inner loop body has constant running time. We could also have used a
constant c. The cost of i:= i+ 1 is ignored since its lower order.
The above simplifies to
n3
X
i=1
i
which is Θ(n6).
1
pf3

Partial preview of the text

Download CMPS 256 - Advanced Algorithms and Data Structures: Final Examination and more Exams Algorithms and Programming in PDF only on Docsity!

CMPS 256 — ADVANCED ALGORITHMS AND DATA STRUCTURES

Summer 2013 – 14 Final Examination Monday July 14, Bliss 105, 8:00 – 10:00 a.m.

Instructions. This quiz is scored out of 100. This quiz is open book and open notes: you can use the textbook, notes you have taken in class, and your homework solutions. Show your work, as partial credit will be given. You may use any algorithm that was covered in class. Just give the name of the algorithm and the chapter or page number in the book where the algorithm is given. If taken from your lecture notes, just say “lecture notes.” For questions that require you to write an algorithm, you must prove that your algorithm has the required running time.

Please draw a horizontal line to separate each answer from the next. Best of luck!

Problem 1 (20 points).

Give the running time of the following, expressed only in terms of n. You may express this as Θ(f (n)), for suitable f (n).

{n > 0 } i := 1; while i ≤ n^3 j := 1; while j ≤ i j := j + 1; endwhile i := i + 1; endwhile

Sample solution. Running time given by the following summation, by putting the limits of the loop as the limits of the sum: ∑n^3

i=

∑^ i

j=

the summand is 1 since inner loop body has constant running time. We could also have used a constant c. The cost of i := i + 1 is ignored since its lower order.

The above simplifies to ∑n^3

i=

i

which is Θ(n^6 ).

Problem 2 (20 points).

Part a (10 points). Given an LLRB, suppose that we swap the colors of all the edges. Is the result, in general, a valid LLRB? Explain.

Sample solution. No, can have red-red violations

Part b (10 points). Is it possible to have a LLRB with 1, 000 , 000 nodes and no red edges? Explain.

Sample solution. An LLRB with no red links must be compete, due to the black balance condition, and so it must have 2n^ − 1 nodes for some n. 1, 000 , 000 is not of this form, so an LLRB with 1, 000 , 000 nodes must have some red links.

Problem 3 (20 points).

Part a (10 points). Give an algorithm to count the number of nodes in each connected component of an undirected graph. Must run in time O(V + E).

Sample solution. Run the conected components algortihm in the slides. Create a counts array, which is indexed by the component number. Traverse the cc array, and increment counts[i] for each node v with cc[v] = i.

Part b (10 points). Give an algorithm to determine if a connected undirected graph G contains an articulation point. An articulation point is a node whose removal would break G into two disconnected components.

Must run in time O(V (V + E)).

Sample solution. For each node v, do the following. Delete v and run the connected compo- nents algorithm and count the number of components. If count = 2 then v is an articulation point.

Problem 4 (20 points).

Let G be a weighted directed graph and suppose that G contains an edge from u to v swth weight 0. Suppose now that we merge the nodes u and v. Will the shortest path lengths in G remain the same, in general, or will they change. Explain.

Sample solution. No, since this can create new paths in G.