Вы находитесь на странице: 1из 2

Advanced Analysis of Algorithms (Spring14)

Problem set #2 1. Undirected vs. directed connectivity. (a) Prove that in any connected undirected graph G = (V, E ) there is a vertex v V whose removal leaves G connected. (Hint: Consider the DFS search tree for G.) (b) Give an example of a strongly connected directed graph G = (V, E ) such that, for every v V , removing v from G leaves a directed graph that is not strongly connected. (c) In an undirected graph with two connected components it is always possible to make the graph connected by adding only one edge. Give an example of a directed graph with two strongly connected components such that no addition of one edge can make the graph strongly connected. 2. Give a linear algorithm to compute the chromatic number of graphs where each vertex has degree at most 2. Must such graphs be bipartite? 3. Two paths in a graph are called edge-disjoint if they have no edges in common. Show that in any undirected graph, it is possible to pair up the vertices of odd degree and nd paths between each such pair so that all these paths are edge-disjoint. 4. A mother vertex in a directed graph G = (V, E ) is a vertex v such that all other vertices G can be reached by a directed path from v . (a) Give an O(n + m) algorithm to test whether a given vertex v is a mother of G, where n = |V | and m = |E |. (b) Give an O(n + m) algorithm to test whether graph G contains a mother vertex. 5. Squares. Design and analyze an algorithm that takes as input an undirected graph G = (V, E ) and determines whether G contains a simple cycle (that is, a cycle which doesnt intersect itself) of length four. Its running time should be at most O(|V |3 ). You may assume that the input graph is represented either as an adjacency matrix or with adjacency lists, whichever makes your algorithm simpler. 6. Suppose an arithmetic expression is given as a tree. Each leaf is an integer and each internal node is one of the standard arithmetical operations (+, , , /). For example, the expression 2 + 3 4 + (3 4)/5 is represented by the tree in Figure below. Give an O(n) algorithm for evaluating such an expression, where there are n nodes in the tree. Graph Algorithms

Page 1 of 2

7. Suppose a CS curriculum consists of n courses, all of them mandatory. The prerequisite graph G has a node for each course, and an edge from course v to course w if and only if v is a prerequisite for w. Find an algorithm that works directly with this graph representation, and computes the minimum number of semesters necessary to complete the curriculum (assume that a student can take any number of courses in one semester). The running time of your algorithm should be linear. 8. Your job is to arrange n ill-behaved children in a straight line, facing front. You are given a list of m statements of the form i hates j . If i hates j , then you do not want put i somewhere behind j , because then i is capable of throwing something at j . (a) Give an algorithm that orders the line, (or says that it is not possible) in O(m + n) time. (b) Suppose instead you want to arrange the children in rows such that if i hates j , then i must be in a lower numbered row than j . Give an ecient algorithm to nd the minimum number of rows needed, if it is possible.

Page 2 of 2

Вам также может понравиться