CSE 321 Homework 5 Solved

35.00 $ 17.50 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . zip solution files instantly, after Payment

Description

Rate this product

1- ) Suppose that you are running a lightweight consulting business – just you, two associates, and some rented equipment. Your clients are distributed between the East Coast and the West Coast of USA, and this leads to the following question. Each month, you can either run your business from an office in New York (NY) or from an office in San Francisco (SF). In month i, you will incur an operating cost of Ni if you run the business out of NY; you will incur an operating cost of Si if you run the business out of SF. (It depends on the distribution of client demands for that month.) However, if you run the business out of one city in month i, and then out of the other city in month i + 1, then you will incur a fixed moving cost of M to switch base offices.

Given a sequence of n months, a plan is a sequence of n locations – each one equal to either NY or SF – such that the ith location indicates the city in which you will be based in the ith month. The cost of a plan is the sum of the operating costs for each of the n months, plus a moving cost of M for each time you switch cities. The plan can begin in either city.

The problem: Given a value for the moving cost M and sequences of operating costs N1 ….. Nn and S1 ….. Sn, find a plan of minimum cost.(Such a plan will be called optimal.)

For example, suppose that n=4, M=10 and the operating costs are given by the following table:

 

# Month 1 Month 2 Month 3 Month 4
NY 1 3 20 30
SF 50 20 2 4

 

Then the plan of minimum cost would be the sequence of locations:

[NY, NY, SF, SF]

with a total cost of 1 + 3 + 2 + 4 + 10 = 20, where the final term of 10 arises because you change locations once.

 

Design a dynamic programming algorithm that takes values for n, M, and sequences of operating costs N1 ….. Nn and Sl …..Sn, and returns the cost of an optimal plan. Implement your algorithm and analyze its worst-case running time. Explain your algorithm in your report file. Β 2-) Suppose that you attend a symposium which has many simultaneous sessions. The lengths of the sessions are not fixed and they begin at various times. As a curious student, you want to join as much sessions as possible. Design a greedy algorithm that finds the optimal list of sessions with the maximum number of sessions. Remember that you can be at only one session at the same time and you cannot leave any session before it is over. Implement your algorithm and analyze its worst-case running time. Explain your algorithm in your report file.

3-) You are given a set of integers S = [-1, 6, 4, 2, 3, -7, -5]. Design a dynamic programming algorithm to check whether there is a subset with the total sum of elements equal to zero. If the algorithm finds such a subset, then print the elements of that subset and terminate the algorithm. Implement your algorithm and analyze its worst-case running time. Explain your algorithm in your report file.

4-) Design a dynamic programming algorithm to find an alignment between two strings with minimum cost. The cost of the alignment is calculated using the following equation:

πΆπ‘œπ‘ π‘‘ = 𝑁 βˆ— π‘šπ‘Žπ‘‘π‘β„Ž_π‘ π‘π‘œπ‘Ÿπ‘’ + 𝑀 βˆ— π‘šπ‘–π‘ π‘šπ‘Žπ‘‘π‘β„Ž_π‘ π‘π‘œπ‘Ÿπ‘’ + 𝐾 βˆ— π‘”π‘Žπ‘_π‘ π‘π‘œπ‘Ÿπ‘’

The match, mismatch and gap scores in the equation are the weights for the matching, mismatching and indent operations, respectively.Β  N, M and K are the count of matches, mismatches and gaps in the alignment, respectively. For example;

 

π‘†π‘’π‘žπ‘’π‘’π‘›π‘π‘’ 𝐴 = 𝐴𝐿𝐼𝐺𝑁𝑀𝐸𝑁𝑇, π‘†π‘’π‘žπ‘’π‘’π‘›π‘π‘’ 𝐡 = 𝑆𝐿𝐼𝑀𝐸

 

π‘šπ‘Žπ‘‘π‘β„Ž_π‘ π‘π‘œπ‘Ÿπ‘’ = 2,Β Β Β Β Β Β Β Β Β  π‘šπ‘–π‘ π‘‘π‘šπ‘Žπ‘‘π‘β„Ž_π‘ π‘π‘œπ‘Ÿπ‘’ = βˆ’2,Β Β Β Β Β Β Β Β  π‘”π‘Žπ‘_π‘ π‘π‘œπ‘Ÿπ‘’ = βˆ’1

 

𝐴 𝐿 𝐼 𝐺 𝑁 𝑀 𝐸 𝑁 𝑇

π΄π‘™π‘–π‘”π‘›π‘šπ‘’π‘›π‘‘ π‘œπ‘“ π‘ π‘’π‘žπ‘’π‘’π‘›π‘π‘’ 𝐴 π‘Žπ‘›π‘‘ 𝐡: { | | | | |Β Β Β Β Β  |Β Β  |

𝑆 𝐿 𝐼 βˆ’ βˆ’ 𝑀 𝐸

 

πΆπ‘œπ‘ π‘‘ = (4 βˆ— (+2)) + (1 βˆ— βˆ’2) + (2 βˆ— βˆ’1) = 4

Implement your algorithm and analyze its worst-case running time. Explain your algorithm in your report file.

5-) Suppose that you have an ancient computer system that needs to do 𝐴 + 𝐡 operation to add numbers 𝐴 π‘Žπ‘›π‘‘ 𝐡. Β For example, the computer does 13 operation to add 5 and 8. You are given an array of integers to calculate the sum of its elements. Design a greedy algorithm to calculate the sum of the array with the minimum number of operations. Implement your algorithm and analyze its worst-case running time. Explain your algorithm in your report file.

 

 

  • HW05-PYTHON-oqdkvd.zip