Docsity

Comprehensive Algorithms Exam, Spring 2003, Exams of Algorithms and Programming

Toggle sidebar
bg1
Comprehensive Examination
Algorithms
Spring 2003
Instructions: Solve any three of the following four problems. Each problem is worth ten points.
Before giving more detailed descriptions of algorithms, briefly describe the main ideas and
techniques, in 1-3 sentences. Complete pseudocode is not required, as long as you clearly state
what your algorithm is doing. You may use without proof any well-known algorithms. Give at
least an informal proof for all your answers; for algorithms, this should include a convincing
argument of correctness as well as a time analysis. The time complexity of your algorithms will
influence your score; for instance, you might get only 8 or 9 points for an O(n2) algorithm if
there is an O(n log n) algorithm. The relative weight of efficiency versus correctness is given
after the specific problems.
1. Give an algorithm to find the longest simple path in a tree. (Recall that a tree is an undirected
graph which is acyclic and connected). For instance, in the tree shown below, the longest
path has length 5. [Correctness 7 points; efficiency 3 points.]
2. You are given an undirected graph with strictly positive edge lengths, along with a specific
starting vertex s. The goal is to determine, for each vertex u of the graph, whether there is a
unique shortest path from s to u. The algorithm should return an array usp such that
usp[u]={
1 if the shortest path from s to u is unique
0 if not
Show how this can be achieved using a modification of Dijkstra’s algorithm. [Correctness 7
points; efficiency 3 points.]
pf2

Partial preview of the text

Download Comprehensive Algorithms Exam, Spring 2003 and more Exams Algorithms and Programming in PDF only on Docsity!

Comprehensive Examination

Algorithms

Spring 2003

Instructions: Solve any three of the following four problems. Each problem is worth ten points. Before giving more detailed descriptions of algorithms, briefly describe the main ideas and techniques, in 1-3 sentences. Complete pseudocode is not required, as long as you clearly state what your algorithm is doing. You may use without proof any well-known algorithms. Give at least an informal proof for all your answers; for algorithms, this should include a convincing argument of correctness as well as a time analysis. The time complexity of your algorithms will influence your score; for instance, you might get only 8 or 9 points for an O ( n^2 ) algorithm if there is an O ( n log n ) algorithm. The relative weight of efficiency versus correctness is given after the specific problems.

  1. Give an algorithm to find the longest simple path in a tree. (Recall that a tree is an undirected graph which is acyclic and connected). For instance, in the tree shown below, the longest path has length 5. [Correctness 7 points; efficiency 3 points.]
  2. You are given an undirected graph with strictly positive edge lengths, along with a specific starting vertex s. The goal is to determine, for each vertex u of the graph, whether there is a unique shortest path from s to u. The algorithm should return an array usp such that

usp[u]= {

1 if the shortest path from s to u is unique 0 if not

Show how this can be achieved using a modification of Dijkstra’s algorithm. [Correctness 7 points; efficiency 3 points.]

  1. You are given a sequence of numbers a1 , a2 ,... , an , and also an integer k. You want to partition the sequence into k groups, each of which consists of (zero or more) consecutive numbers from the sequence. For instance, for k = 3, a possible partitioning of the sequence 15,1, 5, 2,10, 4, 8 is into the three groups 15;1, 5, 2,10; 4, 8. The cost of a group is the sum of the numbers in it; and the overall cost of the partitioning is the largest of these group costs. In the example, the groups shown have costs 15,18 and 12, respectively, and the overall cost is
    1. This is the lowest cost achievable.

Give a dynamic programming algorithm which returns the cost of the optimal partitioning. Hint : one possible solution uses the following recurrence: for m < n and j < k ,

≤ =+

m

i l

B m j l m B l j ai

1

( , ) minmax ( , 1 ),

Be sure to handle the base cases. [Correctness 7 points; efficiency 3 points.]

  1. You are given an undirected graph in the form of an adjacency list. For each node u , let TwoDegree( u ) denote the sum of the degrees of u ’s neighbors. Give an algorithm which sorts the nodes according to this value. [Correctness 5 points; efficiency 5 points.]