hw3_s.pdf - Algorithms CSE 101 Homework III Turn in...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Algorithms: CSE 101 — Homework III Turn in solutions to problems 8, 14, 22, 24 Problem 1: Alternative minimum-spanning-tree algorithms (CLRS) In this problem, we give pseudocode for three different algorithms. Each one takes a graph as input and returns a set of edges T . For each algorithm, you must either prove that T is a minimum spanning tree or prove that T is not a minimum spanning tree. Also describe the most efficient implementation of each algorithm, whether or not it computes a minimum spanning tree. 1. MAYBE-MST-A ( G, w ) 1 sort the edges into nonincreasing order of edge weights w 2 T E 3 for each edge e , taken in nonincreasing order by weight 4 do if T - { e } is a connected graph 5 then T T - e 6 return T 2. MAYBE-MST-B ( G, w ) 1 T ← ∅ 2 for each edge e , taken in arbitrary order 3 do if T ∪ { e } has no cycles 4 then T T e 5 return T 3. MAYBE-MST-C ( G, w ) 1 T ← ∅ 2 for each edge e , taken in arbitrary order 3 do T T ∪ { e } 4 if T has a cycle 5 then let e 0 be the maximum-weight edge on c 6 T T - { e 0 } 7 return T Solution. Problem 2: Arbitrage (CLRS) Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 U.S. dollar buys 46.4 1
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Indian rupees, 1 Indian rupee buys 2.5 Japanese yen, and 1 Japanese yen buys 0.0091 U.S. dollars. Then, by converting currencies, a trader can start with 1 U.S. dollar and buy 46 . 4 × 2 . 5 × 0 . 0091 = 1 . 0556 U.S. dollars, thus turning a profit of 5 . 56 percent. Suppose that we are given n currencies c 1 , c 2 , . . . , c n and an n × n table R of exchange rates, such that one unit of currency c i buys R [ i, j ] units of currency c j . 1. Give an efficient algorithm to determine whether or not there exists a sequence of currencies h c i 1 , c i 2 , . . . , c i k i such that R [ i 1 , i 2 ] · R [ i 2 , i 3 ] · · · R [ i k - 1 , i k ] · R [ i k , i 1 ] > 1 Analyze the running time of your algorithm 2. Give an efficient algorithm to print out such a sequence if one exists. Analyze the running time of your algorithm. Solution. Problem 3: Bottleneck shortest s - t path If P is a path in a weighted graph G , let maxweight ( P ) be the maximum of all the weights of the edges in P . Give a polynomial-time algorithm to solve the following problem: Given an undirected graph whose edges have positive integral weights, and two distinct vertices s and t , among all s - t paths P find one for which maxweight ( P ) is minimized. Solution. Problem 4: Building a new road (DPV) There is a network of roads G = ( V, E ) connecting a set of cities V . Each road in E has an associated length l e . There is a proposal to add one new road to this network, and there is a list E 0 of pairs of cities between which the new road can be built. Each such potential road e 0 E 0 has an associated length. As a designer for the public works department you are asked to determine the road e 0 E 0 whose addition to the existing network G would result in the maximum decrease in the driving distance between two fixed cities s and t in the network. Give an efficient algorithm for solving this problem.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern