Explain the runtime of the dynamic programming algorithm

Assignment Help Data Structure & Algorithms
Reference no: EM132958989

Question 1: Recall the FOLDS AND CUTS problem from Assignment 2, where you are given a rectangular strip of paper P of length t with n ≥ 0 vertical folds, located at distances f1, f2 ... fn, A from the left end of P. Let fn+1 = 1. In the "dual" version of the problem, you are also given a nonnegative integer k. You want to cut P along exactly k < n folds, such that the maximum length of the k + 1 resulting strips is as short as possible. We'll denote this length by L(n, k).

More generally, for any i in the range [01..n], let Pi denote the strip of paper of length fi+i that has folds at distances f1, f2,f3 , fi. If we cut Pi, along exactly j folds, where 0 ≤ j ≤ i, such that the maximum length of the j + 1 resulting strips is as short as possible, we denote the resulting maximum length by L(i, j).

For example, if f1, f2, ....fi are 1,3,7, respectively, f4 = t = 10, and k = 2 then cutting at 3 and 7 is optimal, resulting in a max length L(3, 2) = 4. Also for this example, L(2, 1) = L(2, 2) = 4, while L(2,0) = 7.
1. When k < n, explain why L(n, k) ≤ l.
2. When k < n, explain why L(n, k) ≥ l/ l/k+1 .
3. Write a recursive definition of L(i, j) when 0 ≤ j ≤ i. You do not need to provide a justification for your recurrence.
4. Using your recurrence, give a memoized algorithm for computing L(n, k) .
5. Explain the runtime of your algorithm.

A rectangular strip of paper P of length £ has n vertical folds, located at distances f1, f2, .....fn , fn from the left end of P. We'll let 10 = 0 and fn+i = 1, and assume that all of the fi are distinct. See Figure ??.

For a given positive M, you want to cut P along a minimum number of folds so that the resulting strips {Si, ... , sk} each have length at most M. You can assume that M > fil4 - fi, for any i, 0 ≤ i ≤ n.

Question 2: Olaf has a collection of m types of ornaments, each with a unique colour (labelled from 1 to m), and a tree T with n vertices. He is very peculiar about decorating the tree. Each vertex v can be assigned an ornament of colour cv between integers 4 and I.,. In addition, to maximize the contrast between two ornaments along a single edge, he would like the sum of icu - c„) across all edges uv in T, or the beauty of T, to be as large as possible. The beauty of a tree with just one node is 0.

1. Show that an optimal assignment of ornaments exist such that either cv = 4 or ri, for every v.

2. Let BEAuTY(vre) denote the maximum beauty of v's subtree if ce, = 4 and let BEAUTY(V, r) denote the maximum beauty of v's subtree if cv = rv. Provide recurrences for BEAUTY(V, .e) and BEAUTY(V, r) (these recurrences can depend on each other), and give the expression for the maximal beauty of T.

3. Explain the runtime of the dynamic programming algorithm based on your recur¬rence. (You don't need to write the dynamic programming algorithm.)

Question 3: You are the manager of the Abbotsford branch of a large multinational company, and your company just bought out a small business based in Brampton, Ontario. However, your company has not found a manager for the Brampton branch yet, so they have asked you to oversee both branches until the end of the year. There are n days remaining in the year.

Because you will be spending a fair amount of time in Brampton, you have determined that it will be more convenient to stay in hotels in both cities, rather than continuing to rent your apartment in Abbotsford. You cannot stay in either location for more than 7 days because you do not want to be away from either branch for too long. You must determine how to split your time between Abbotsford and Brampton in a way that minimizes the total cost of your hotels and flights.

The cost of your flight/hotel depends on the day (weekends/holidays might be more expensive, or there might be promotions on certain days) and the city. You are given four arrays that provide the cost of the hotels and flights for each day.

The arrays fA, hi., hA, and hB, each of length n, are defined as follows:

fA[i] is the cost of flying to Abbotsford on day i
fs[i] is the cost of flying to Brampton on day i
hA [i] is the cost of staying in a hotel in Abbotsford on day i

hB [i] is the cost of staying in a hotel in Brampton on day i

Question 4: You are looking to minimize the cost of accommodations plus flights, subject to the constraint that you cannot spend more than 7 days in one location. You can assume that your flights are always in the morning (so if you are flying between cities on day i, you only have to pay for a hotel in your destination city that day).

Let CA [i] be the lowest possible value of the objective function for days 1 to i, assuming you are staying in Abbotsford on day i. Similarly, let CB[i] be the lowest possible value of the objective function for days 1 to i, assuming you are staying in Brampton on day i. In either case, assume that you are staying in Abbotsford on day 0. The solutions to Tutorial 7 provide recurrences for these values.

1. Using the recurrences from Tutorial 7, write pseudo-code for an iterative dynamic programming algorithm that takes fA, fB, hA and hB as input and populates the arrays CA and CB for every value 1 < i < n. Note: it is acceptable to leave min() operations in your pseudo-code instead of writing out an inner loop.

2. State the running time of your algorithm from part 1 as a function of n. No justification needed.

Reference no: EM132958989

Questions Cloud

Necessary for effective and efficient project management : What leadership skill do you find most necessary for effective and efficient project management? Why? Include references.
Compute what will the price be four years from now : A 20-year, $1,000 par value bond has a 6% annual payment coupon. If the yield to maturity remains at its current rate, what will the price be 4 years from now?
Importance of recruitment and selection in business : 'The importance of recruitment and selection in business and organisations is arguably the easiest concept to grasp in the practice of HRM' (Hinton, Woods and Z
Compute npv for both projects for bahamas recreation corp : Compute the incremental IRR for the cash flows. Cash flows on two mutually exclusive projects for the Bahamas Recreation Corporation
Explain the runtime of the dynamic programming algorithm : Explain the runtime of the dynamic programming algorithm based on your recur¬rence. (You don't need to write the dynamic programming algorithm.)
Calculate sandhill earnings per share : Calculate Sandhill's 2020 earnings per share. During 2020, Sandhill has not declared or paid any dividend on 107,000 non-cumulative preferred shares.
Why should a company not recognise a profit : Why should a company not recognise a profit when they purchase inventory? Because profit is a function of sales and cost of sales, not purchases
Find what is cost of common equity for summerdahl resort : What is the cost of common equity? The stock is expected to pay a dividend of $2.00 a share at the end of the year (D1 = $2.00).
Prepare the ending balances for plan assets : Determine the pension expenses recognized in 2020. Prepare the ending balances (31 December 2020) for plan assets, PBO, and calculate net pension liability.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Perform a radix sort

Perform a radix sort, using a decimal basis (that is sorting into 10 buckets, ordered 0 to 9) on the given list:

  Convert a sorted double-linked list to a binary search tree

Write a program to convert a sorted double-linked list to a binary search tree - Find the middle node in the doubly linked list and set it as root, convert the left sublist and set it as left subtree, convert the right sublist and set it as right s..

  Find the shortest paths from s to all the other nodes

Find the Minimum-Cost Spanning Trees for the above graph using the following algorithms.

  Write program that implement a binary search of sorted array

Write and test a program that instantiates a function template that returns the minimum of two values. Write and test a program that instantiates a function template that implements a binary search of a sorted array of objects.

  Find a regular expression for the complement of the language

Assuming Σ = {a, b}, find a regular expression for the complement of the language L = L(aa*bb*). Hint: consider a multi-step approach: (i) construct a DFA M1 that accepts L; (ii) modify it to make M2 that accepts Lc.

  Write a program to test your implementation of stack class

Write a program to test your implementation of this Stack class. You also need to provide at least 4 test cases for this program to test all the methods including constructor, push, pop, peek and size, and to test dynamic resizing

  Implement the selection sort algorithm for sorting an array

Implement the Selection Sort algorithm for sorting an array of n elements. This algorithm has n-1 iterations, each selecting the next largest element a[j] and swapping it with the ele- ment that is in the position where a[j] should be.

  Prepare an essay that describing use of an olap data cube

Write a 2 to 3 page essay describing the use of an OLAP Data Cube. Your essay should also describe the operations of Drill Down, Roll Up, Slice, and Dice.

  Solving the problem based on the linked list

A linked list contains a cycle if, starting from some node p, following a sufficient number of next links brings us back to node p.

  Modify the recursive quicksort to call mergesort

Modify the recursive quicksort to call mergeSort on its current subarray if the level of recursion has reached depth.

  Create algorithm prompt for and receive employee number

Create algorithm which will prompt for and receive the employee number from operator at terminal. Your program is to search array of valid employee numbers to check that employee number is XXXXX,

  Define the use strings and characters

Define the use strings and characters

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd