Docsity

Spanning Trees - Efficient Algorithms and Intractable Problems - Exams, Exams of Algorithms and Programming

Toggle sidebar
bg1
CS 170, Fall 1998
Midterm 1
Problem #1
1. (15 points) What are the strongly connected components of the directed graph shown below? (Just circle
them).
Perform depth-first search on the graph shown above. For each vertex show the pre-order and post-order
numbers, and label each edge with T, F, B, C depending on whether it is a tree, forward, back or cross edge.
(As always, when in DFS we have a choice, we always select the alphabetically first vertex.)
Can you add an edge to this graph to make it strongly connected?
Problem #2
2. (15 points) We are given a tree T = (V,E) rooted at vertex r is an element of V. Recall that vertex u is an
ancestor of vertex v in the rooted tree, if the path from r to v in the tree goes through u.
We wish to preprocess the tree by associating numbers with the vertices, so that queries of the form "is u an
ancestor of v?" can be answered in constant time. The preprocessing should take linear time. (Hint: Think
depth-first search.)
A. Brief description or pseudocode for the preprocessing
B. Brief description or pseudocode for answering a query
CS 170, Midterm 1, Fall 1998
CS 170, Fall 1998 Midterm 1 1
pf3

Partial preview of the text

Download Spanning Trees - Efficient Algorithms and Intractable Problems - Exams and more Exams Algorithms and Programming in PDF only on Docsity!

CS 170, Fall 1998

Midterm 1

Problem

  1. (15 points) What are the strongly connected components of the directed graph shown below? (Just circle them).

Perform depth-first search on the graph shown above. For each vertex show the pre-order and post-order numbers, and label each edge with T, F, B, C depending on whether it is a tree, forward, back or cross edge. (As always, when in DFS we have a choice, we always select the alphabetically first vertex.)

Can you add an edge to this graph to make it strongly connected?

Problem

  1. (15 points) We are given a tree T = (V,E) rooted at vertex r is an element of V. Recall that vertex u is an ancestor of vertex v in the rooted tree, if the path from r to v in the tree goes through u. We wish to preprocess the tree by associating numbers with the vertices, so that queries of the form "is u an ancestor of v?" can be answered in constant time. The preprocessing should take linear time. (Hint: Think depth-first search.)

A. Brief description or pseudocode for the preprocessing

B. Brief description or pseudocode for answering a query

CS 170, Fall 1998 Midterm 1 1

C. Justification of correctness (for both).

D. Running time and justification (for both).

Problem

  1. (15 points) We wish to find the minimum spanning tree of the graph below.

Give the order in which edges will be added to the MST by Prim's algorithm. Start the algorithm from vertex A.

Repeat for Kruskal's algorithm.

Show the final configuration of the UNION-FIND tree at the end of Kruskal's algorithm. (UNION-FIND means of course "with path compression". In case of ties, always make the alphabetically larger node the root.)

Problem

  1. (15 points) In Internet routing, the delays on lines are usually negligible, but the delays on routers may be substantial. This motivates a different kind of shortest path problem:

We are given a graph with weights on its vertices. The weight of a path is the sum of the weights of the vertices on the path --including the endpoints. Give an algorithm for finding a shortest path between two nodes s and t. Your algorithm should run as fast as Dijkstra's.

A. Brief description or pseudocode

Problem #2 2