HW08
Transcription
HW08
CIS 121 Homework Assignment 8 Given: March 05, 2015 Due: April 02, 2015 Note: The homework is due on Thursday, April 02 at the beginning of the class. For late submissions, please refer to the Late Submission Policy on the course webpage: http://www.seas.upenn.edu/∼cis121/ Please write concise and clear solutions; you will get only a partial credit for correct solutions that are either unnecessarily long or not clear. Whenever you present an algorithm, first give a precise description of your algorithm in English, and only then if you consider it useful, present it in a pseudocode form. You should always argue the correctness of your algorithm and give an analysis of its time complexity. You are allowed to discuss ideas for solving homework problems in groups of up to 3 people but you must write your solutions independently. Also, you must write on your homework the names of the people with whom you discussed. Finally, you are not allowed to use any material outside of the class notes and the textbook. Any violation of this policy may seriously affect your grade in the class. 1. We have a connected graph G = (V, E), and a specific vertex u ∈ V . Suppose we compute a depth-first search tree rooted at u, and obtain a tree T that includes all nodes of G. Suppose we then compute a breadth-first search tree rooted at u, and obtain the same tree T . Prove that G = T . (In other words, if T is both a depth-first search tree and a breadth-first search tree rooted at u, then G cannot contain any edges that do not belong to T .) 2. Prof. Stewart is consulting for the president of a corporation that is planning a technical event. Prof. Stewart is given a list of n researchers to choose from and a list of all pairs of people who have collaborated on research with each other. We assume that the “collaboration” relation is symmetric, i.e., if person A has collaborated with person B then person B also has collaborated with person A. Prof. Stewart has to invite as many people as possible, subject to the constraint: each person attending the event should have at least six other people whom they have collaborated with. Give an efficient algorithm that takes as input a list of n people and a list of pairs of people who have collaborated with each other and outputs the list of invitees. Justify the running time of your algorithm? 3. Given a tree T = (V, E), let Γ(T ) denote the maximum distance between any two vertices in T . Give an O(n) algorithm for computing Γ(T ), where n is the number of vertices in T . 2 Homework Assignment 8 March 05, 2015 4. You are given an undirected graph G = (V, E) in which the edge weights are restricted. In particular, each edge has a positive integer weight in the range {1, 2, . . . , W }. Give an algorithm that computes shortest paths from a given source vertex s ∈ V on such graphs in O((n + m) log W ) time. 5. Consider the following problem: there are n cities and there are direct roads connecting some pairs of cities. All roads are one-way, but a pair of cities, say A and B may have two one-way roads between them, one going from A to B and the other going from B to A. Associated with each road is a positive number that indicates the time it takes to go from one city to another (if there are two roads connecting a pair of cities, the time associated with each road may be different). This network of one-way roads is such that every city is reachable from every other city. There is a special city S. Give an efficient algorithm to find the routes that take the smallest amount of time to reach from every city to every other city with the constraint that all routes must pass through S. 6. Consider a graph G = (V, E) that is connected and has at most n + 8 edges, where n = |V |. Give an algorithm with running time O(n) that takes a near-tree G with costs on its edges, and returns a minimum spanning tree of G. You may assume that all the edge costs are distinct.