Describe a strategy for finding the highest safe rung

Assignment Help Data Structure & Algorithms
Reference no: EM131205997

Text Book - Algorithm Design by Jon Kleinberg and Eva Tardos

Chapter 2 - Basics of Algorithm Analysis

Exercises

Q1. Suppose you have algorithms with the five running times listed below. (Assume these are the exact running times.) How much slower do each of these algorithms get when you (a) double the input size, or (b) increase the input size by one?

(a) n2

(b) n3

(c) 100n2

(d) n log n

(e) 2n

Q2. Suppose you have algorithms with the six running times listed below. (Assume these are the exact number of operations performed as a function of the input size n.) Suppose you have a computer that can perform 1010 operations per second, and you need to compute a result in at most an hour of computation. For each of the algorithms, what is the largest input size n for which you would be able to get the result within an hour?

(a) n2

(b) n3

(c) 100n2

(d) n log n

(e) 2n

(f) 22^n

Q3. Take the following list of functions and arrange them in ascending order of growth rate. That is, if function g(n) immediately follows function f (n) in your list, then it should be the case that f (n) is O(g(n)).

f1(n) = n2.5

f2(n) = √(2n)

f3(n) = n + 10

f4(n) = 10n

f5(n) = 100n

f6(n) = n2 log n

Q4. Take the following list of functions and arrange them in ascending order of growth rate. That is, if function g(n) immediately follows function f (n) in your list, then it should be the case that f (n) is O(g(n)).

g1(n) = 2√(log n)

g2(n) = 2n

g4(n) = n4/3

g3(n) = n(log n)3

g5(n) = nlog n

g6(n) = 22^n

g7(n) = 2n^2

Q5. Assume you have functions f and g such that f (n) is O(g(n)). For each of the following statements, decide whether you think it is true or false and give a proof or counterexample.

(a) log2 f(n) is O(log2g(n)).

(b) 2f(n) is O(2g(n)).

(c) f(n)2 is O(g(n)2).

Q6. Consider the following basic problem. You're given an array A consisting of n integers A[1], A[2],..., A[n] . You'd like to output a two-dimensional n-by-n array B in which B[i, j] (for i < j) contains the sum of array entries A[i] through A[j]-that is, the sum A[i]+ A[i + 1]+ ...+ A[j] . (The value of array entry B[i, j] is left unspecified whenever i ≥ j, so it doesn't matter what is output for these values.)

Here's a simple algorithm to solve this problem.

For i = 1, 2, . . . , n

For j = i + 1, i + 2, . . . , n

Add up array entries A[i] through A[j]

Store the result in B[i, j]

Endfor

Endfor

(a) For some function f that you should choose, give a bound of the form O(f (n)) on the running time of this algorithm on an input of size n (i.e., a bound on the number of operations performed by the algorithm).

(b) For this same function f, show that the running time of the algorithm on an input of size n is also Ω(f(n)). (This shows an asymptotically tight bound of Θ(f(n)) on the running time.)

(c) Although the algorithm you analyzed in parts (a) and (b) is the most natural way to solve the problem-after all, it just iterates through the relevant entries of the array B, filling in a value for each-it contains some highly unnecessary sources of inefficiency. Give a different algorithm to solve this problem, with an asymptotically better running time. In other words, you should design an algorithm with running time O(g(n)), where limn→∞ g(n)/f (n) = 0.

Q7. There's a class of folk songs and holiday songs in which each verse consists of the previous verse, with one extra line added on. "The Twelve Days of Christmas" has this property; for example, when you get to the fifth verse, you sing about the five golden rings and then, reprising the lines from the fourth verse, also cover the four calling birds, the three French hens, the two turtle doves, and of course the partridge in the pear tree. The Aramaic song "Had gadya" from the Passover Haggadah works like this as well, as do many other songs.

These songs tend to last a long time, despite having relatively short scripts. In particular, you can convey the words plus instructions for one of these songs by specifying just the new line that is added in each verse, without having to write out all the previous lines each time. (So the phrase "five golden rings" only has to be written once, even though it will appear in verses five and onward.)

There's something asymptotic that can be analyzed here. Suppose, for concreteness, that each line has a length that is bounded by a constant c, and suppose that the song, when sung out loud, runs for n words total. Show how to encode such a song using a script that has length f (n), for a function f (n) that grows as slowly as possible.

Q8. You're doing some stress-testing on various models of glass jars to determine the height from which they can be dropped and still not break. The setup for this experiment, on a particular type of jar, is as follows. You have a ladder with n rungs, and you want to find the highest rung from which you can drop a copy of the jar and not have it break. We call this the highest safe rung.

It might be natural to try binary search: drop a jar from the middle rung, see if it breaks, and then recursively try from rung n/4 or 3n/4 depending on the outcome. But this has the drawback that you could break a lot of jars in finding the answer.

If your primary goal were to conserve jars, on the other hand, you could try the following strategy. Start by dropping a jar from the first rung, then the second rung, and so forth, climbing one higher each time until the jar breaks. In this way, you only need a single jar-at the moment it breaks, you have the correct answer-but you may have to drop it n times (rather than log n as in the binary search solution).

So here is the trade-off: it seems you can perform fewer drops if you're willing to break more jars. To understand better how this trade-off works at a quantitative level, let's consider how to run this experiment given a fixed "budget" of k ≥ 1 jars. In other words, you have to determine the correct answer-the highest safe rung-and can use at most k jars in doing so.

(a) Suppose you are given a budget of k = 2 jars. Describe a strategy for finding the highest safe rung that requires you to drop a jar at most f (n) times, for some function f (n) that grows slower than linearly. (In other words, it should be the case that limn→∞ f (n)/n = 0.)

(b) Now suppose you have a budget of k > 2 jars, for some given k. Describe a strategy for finding the highest safe rung using at most k jars. If fk(n) denotes the number of times you need to drop a jar according to your strategy, then the functions f1, f2, f3,... should have the property that each grows asymptotically slower than the previous one: limn→∞ fk(n)/fk-1(n) = 0 for each k.

Reference no: EM131205997

Questions Cloud

Explain the common price setting strategies of airlines : Examine the common price setting strategies of airlines that use game theory. Predict the potential effects of such pricing strategies on the demand for seats, and conclude the resulting impact on the profitability of the airlines.
Explain the basic tenets of rawl''s theory of justice : Consider a two person, two commodity pure exchange economy, with:U q  q,U q  q q q qand q q q Derive the contract curve as an implicit function of q and q.
Future contract was entered long time : A future contract was entered long time ago. It curretly has 6 months to maturity. The continuously compounded is of risk-free rate is 5% per annum, stock price is $15, the delivey is $14.
Explain three optimal decision rules for katrinas candies : Create three optimal decision rules for Katrina's Candies (e.g., whether to hire more staff or hire temporary workers to meet production schedules.
Describe a strategy for finding the highest safe rung : Suppose you are given a budget of k = 2 jars. Describe a strategy for finding the highest safe rung that requires you to drop a jar at most f (n) times, for some function f (n) that grows slower than linearly. (In other words, it should be the cas..
Write the expressions for the voltages vc and vr : The capacitor of given figureis initially charged to 40 V before the switch is closed. Write the expressions for the voltages vC and vR and the current iC for the decay phase.
Describe the type of retail business it is : Ask questions that interest you that might include how they got to this position, what size store they manage (dollar figures), their trade radius (customer reach), and so on. How long have they worked in retail? Previous experience?
Explain the basic tenets of rawl''s theory of justice : Consider a two person, two commodity pure exchange economy, with:U q  q,U q  q q q qand q q q Derive the contract curve as an implicit function of q and q. What condition on the coefficients  and ß will ensure that t..
What specifically do living wage ordinances call for : What specifically do "living wage" ordinances call for? How is the "living wage" different from the "minimum wage?" Who is helped, who is hurt by a living wage requirement? What underlying data is used to justify a living wage requirement?

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  How much time will it take to sort the array

If an arbitrary item is added to the end of an already sorted list, how much time will it take to sort the array again using insertion sort?

  Algorithm for a bank account

Write algorithm to settle following question: A bank account starts out with $10,000. Interest is compounded monthly at 6 percent per year (0.5 percent per month).

  What are the potential benefits of knowledge management

What are the potential benefits of knowledge management projects

  Initialize accumulator variable for total rainfall to zero

Set a constant named SIZE to 12. This represents the total number of elements in the array. Initialize an accumulator variable for the total rainfall to 0.

  Create a report based on the query

Increase the font size of the Total Purchases by Customer label (in the strCustomerNameFooter section) to 11 and the =Sum calculated control to 10 points. Change the font color of both to dark blue.

  Determine the order of insertions

Determine the order of insertions with this set of numbers that will result in a perfectly balanced BST(Binary Search Tree) and show the result of a preorder traversal of this tree.

  Program for stack by using dynamically allocated array

Write a C++ class which implements stack by using a dynamically allocated array. Initial size of particular stack must be determined when it is created.

  Draw a binary search tree for an array

Draw a binary search tree for an array of element from 0 to 20

  Building a tree for conversion purposes

Creating a Tree Class, Building a Tree. Converting Morse code to English characters. Concepts tested by this program: Generic Classes, Utility Class, New concepts tested by this program, Linked Trees, Building a Tree for conversion purposes.

  Data information decision

Data Information Decision

  An optimization technique concept

Write an Genetic Algorithm: An Optimization Technique Concept

  Explain how to use an avl tree or a red-black tree

What does a splay tree look like if its entries are accessed in increasing order by their keys? Explain how to use an AVL tree or a red-black tree to sort ncomparable elements in O(nlog n) time in the worst case.

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