Docsity

CS 170 - Fall 2003 - Midterm 1: Algorithms and Data Structures, Exams of Algorithms and Programming

Toggle sidebar
bg1
CS 170 - Fall 2003 - Midterm 1
Associate Professor Satish Rao
Problem 1: Recurrences (17 points)
Give asymptotically tight solutions for T(n) for the following recurrences. Give only
brief justification.
T(n) = T(n/2) + n1. T(n) = T(4n/5) + T(n/5) + n2. T(n) = 8T(n/2) + n3
3. T(n) = 2T(n1/3) + 14.
Problem 2: Graph Algorithms (24 points)
Consider the following graph.
Write down an adjacency list representation of the graph. (Write the edges in
clock-wise order, where the closest one to twelve o'clock that is "past" twelve is
first.)
1.
Compute a depth first search tree. (Use the ordering provided above.)2. What are the strongly connected components?3. Compute the shortest path distances, give the order in which the nodes are
"known" to have the correct distance for Dijkstra's algorithm.
4.
CS 170 - Fall 2003 - Midterm 1
CS 170 - Fall 2003 - Midterm 1 1
pf3

Partial preview of the text

Download CS 170 - Fall 2003 - Midterm 1: Algorithms and Data Structures and more Exams Algorithms and Programming in PDF only on Docsity!

CS 170 - Fall 2003 - Midterm 1

Associate Professor Satish Rao

Problem 1: Recurrences (17 points)

Give asymptotically tight solutions for T(n) for the following recurrences. Give only brief justification.

1.T(n) = T(n/2) + n 2.T(n) = T(4n/5) + T(n/5) + n 3.T(n) = 8T(n/2) + n^3 4.T(n) = 2T(n1/3) + 1

Problem 2: Graph Algorithms (24 points)

Consider the following graph.

Write down an adjacency list representation of the graph. (Write the edges in clock-wise order, where the closest one to twelve o'clock that is "past" twelve is first.)

2.Compute a depth first search tree. (Use the ordering provided above.) 3.What are the strongly connected components? Compute the shortest path distances, give the order in which the nodes are "known" to have the correct distance for Dijkstra's algorithm.

CS 170 - Fall 2003 - Midterm 1 1

Problem 3: Algorithm Properties (17 points)

Consider a depth first search of a graph. Argue that a node u is in a cycle if and only if it or one of its descendants in a DFS has a back edge to an ancestor of u or to u.

Given an s and t in a graph G , a bottleneck path from s to t is the path with the largest minimum weight edge. Give an algorithm for computing the bottleneck s — t path.

Problem 4: Shortest Paths (17 points)

Consider the following version of the Bellman-Ford algorithm.

Set d ( v ) = ∞ for all v ∈V, set d ( s ) = 0. Do x times, for all edges, update ( u , v ).

Here update ( u , v ) is defined as follows: update( u , v ): { if d ( v ) > d ( u ) + d ( u , v ) then d ( v ) = d ( u ) + d ( u , v ). }

Notive that the order of the updates on the edges is arbitrary.

Given an n -node graph with no negative cycles, how large should x be to guarantee that the distance labels are correct for a graph with n nodes and m edges. (Be careful, x is the number of times that the loop runs.)

Given the following graph, what is the smallest value of x where the algorithm has the correct distance labels for any order of the edge relaxations in an iteration.

How should you modify the algorithm, so that in the first iteration where the distance labels are correct, you can halt? (Modify update to keep track of something and check for it at the end of the set of relaxations.)

For any graph with a well defined shortest path tree, describe an ordering of the edges, where one iteration of Bellman-Ford algorithm suffices to relax all

Problem 3: Algorithm Properties (17 points) 2