• 沒有找到結果。

Algorithm Design and Analysis Homework #5 Due: 1pm, Monday, December 26, 2011

N/A
N/A
Protected

Academic year: 2022

Share "Algorithm Design and Analysis Homework #5 Due: 1pm, Monday, December 26, 2011"

Copied!
4
0
0

加載中.... (立即查看全文)

全文

(1)

Algorithm Design and Analysis Homework #5

Due: 1pm, Monday, December 26, 2011

=== Homework submission instructions ===

• Submit the answers for writing problems (including your programming report) through the CEIBA system (electronic copy) or to the TA in R432 (hard copy).

Please write down your name and school ID in the header of your documents. You also need to submit your programming assignment (problem 1) to the Judgegirl System(http://katrina.csie.ntu.edu.tw/judgegirl/).

• Each student may only choose to submit the homework in one way; either all as hard copies or all through CEIBA except the programming assignment. If you submit your homework partially in one way and partially in the other way, you might only get the score of the part submitted as hard copies or the part submitted through CEIBA (the part that the TA chooses).

• If you choose to submit the answers of the writing problems through CEIBA, please combine the answers of all writing problems into only one file in the doc/docx or pdf format, with the file name in the format of “hw5 [student ID].{pdf,docx,doc}”

(e.g. “hw5 b99902010.pdf”); otherwise, you might only get the score of one of the files (the one that the TA chooses).

• For each problem, please list your references (they can be the names of the classmates you discussed the problem with, the URL of the information you found on the Internet, or the names of the books you read). The TA can deduct up to 100% of the score assigned to the problems where you don’t list your references.

Problem 1. (30%) 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 49 Indian rupees, 1 Indian rupee buys 2 Japanese yen, and 1 Japanese yen buys 0.0107 U.S. dollars. Then, by converting cur- rencies, a trader can start with 1 U.S. dollar and buy 49 × 2 × 0.0107 = 1.0486 U.S.

1

(2)

dollars, thus turning a profit of 4.86 percent. Suppose that we are given n currencies c1, c2, ..., cn and an n × n table R of exchange rates, such that one unit of currency ci buys R[i, j] units of currency cj. We would like to find a sequence of currencies hci1, ci2, ..., ciki such that R[i1, i2] · R[i2, i3] · · · R[ik−1, ik] · R[ik, i1] is maximized, where k ≤ n. If max {R[i1, i2] · R[i2, i3] · · · R[ik−1, ik] · R[ik, i1]} > 1, we call this set of currencies profitable. To result in successful arbitrage, a sequence of exchanges must begin and end with the same currency, but any starting currency may be considered.

Input:

The first line contain n, 2 ≤ n ≤ 50. The next n lines represent the exchange rate table R in the following format:

R[1, 1] R[1, 2] R[1, 3] . . . R[1, n]

R[2, 1] R[2, 2] R[2, 3] . . . R[2, n]

. . .

R[n, 1] R[n, 2] R[n, 3] . . . R[n, n]

with all numbers ranging from 10−5 to 105. Output:

For each intput table you must determine whether a sequence of exchanges exists that results in a profit of more than 1 percent (0.01). If a sequence exists you must print the sequence of exchanges that results in a profit. If there is more than one sequence that results in a profit of more than 1 percent you must print a sequence of minimal length and starting currency index, i.e., one of the sequences that uses the fewest exchanges of currencies to yield a profit. All profiting sequences must consist of n or fewer transactions where n is the dimension of the table giving exchange rates. You should output the profitable sequence in the following format:

i1, i2, ..., ik, i1

where i1, i2, ..., ik, i1 is the sequence of the indices of the currencies in the profitable ex- change, where i1 < ij, for j = 2, ..., k. The indices from i2 to ik are all distinct. If no profitable sequence can be found, output “Not profitable”. All numbers in this output line are separated by comma.

Sample Input 1:

2

(3)

3

1 0.6 0.8 1.6 1 1.2 1.2 0.7 1

Sample Output 1:

Not profitable Sample Input 2:

3

1 0.05 0.21 16 1 4 5.1 0.09 1

Sample Output 2:

1,3,1

Please write a program to solve this problem. Please also submit a report in which you give a clear description of your algorithm and analyze the running time of your algorithm.

Problem 2. (10%) Read section 17.4 on the textbook. Then solve problem 17.4-3 on page 471.

Problem 3. (20%) Solve problem 17-5 on page 476 in the textbook.

Problem 4. (20%) Solve problem 17-1 on page 472. Key sentence: bit-reversal permu- tation swaps elements whose indices have binary representations that are the reverse of each other.

Problem 5. (20%) Nesting boxes

A d-dimensional box with dimensions (x1, x2, ..., xd) nests within another box with di- mensions (y1, y2, ..., yd) if there exists a permutation π on 1, 2, ..., d such that xπ(1) <

y1, xπ(2) < y2, ..., xπ(d) < yd.

1. Argue that the nesting relation is transitive.

3

(4)

2. Describe an efficient method to determine whether or not one d-dimensional box nests inside another.

3. Suppose that you are given a set of n d-dimensional boxes {B1, B2, ..., Bn}. Give an efficient algorithm to find the longest sequence hBi1, Bi2, ..., Biki of boxes such that Bij nests within Bij+1 for j = 1, 2, ..., k − 1. Express the running time of your algorithm in terms of n and d. (Hint: construct a directed graph where the vertices represents the boxes.)

4

參考文獻

相關文件

For his major contributions to the analysis of algorithms and the design of programming languages, and in particular for his contributions to. “The Art of Computer Programming”

Since everyone needs to write the final solutions alone, there is absolutely no need to lend your homework solutions and/or source codes to your classmates at any time.. In order

Since everyone needs to write the final solutions alone, there is absolutely no need to lend your homework solutions and/or source codes to your classmates at any time.. In order

Since everyone needs to write the final solutions alone, there is absolutely no need to lend your homework solutions and/or source codes to your classmates at any time.. In order

If you have stored the distance between every two cities in a table, what is the time complexity you need to find the optimal solution of travelling salesman problem.. Calculation

Unless granted by the instructor in advance, you must turn in a printed/written copy of your solutions (without the source code) for all problems.. For problems marked with (*),

Since everyone needs to write the final solutions alone, there is absolutely no need to lend your homework solutions and/or source codes to your classmates at any time.. In order

• Submit the answers for writing problems (including your programming report) through the CEIBA system (electronic copy) or to the TA in R432 (hard copy).. Please write down your