Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91962008

Have any Question?


Related Questions in Computer Engineering

Question suppose you are buying stamps to put on a package

Question : Suppose you are buying stamps to put on a package at the post office. The postage required to send the package is N dollars. You can buy $1, $7, and $10 stamps. You want to find the minimum number of stamps re ...

Question you are in a social situation talking with

Question : You are in a social situation talking with coworkers, friends, or family members who are not familiar with the concept of networking, except for the idea that they turn on their computer and surf the World Wid ...

Questionimplement a calculator for a client-server

Question Implement a calculator for a client-server architecture using socket communication between the client and the server. The client should provide the graphical user interface for the user, and the server should pe ...

A supermarket awards coupons depending on how much a

A supermarket awards coupons depending on how much a customer spends on groceries. For example, if you spend $50, you will get a coupon worth eight percent of that amount. The following table shows the percent used to ca ...

According to the alzheimers association alzheimers disease

According to the Alzheimer's Association, Alzheimer's disease affects 1 in 10 people over the age of 65. What would be the shape, mean, and standard error of the sampling distribution of the proportion who suffer from Al ...

What is the binary representation of the decimal number

What is the binary representation of the decimal number 4.875 assuming the IEE 754 single precision format? Can I get a detailed explanation as well. Thank you

Question developing a more agile approachbullspeculate on

Question: "Developing a More Agile Approach" • Speculate on why corporate culture plays a critical role in developing a more agile product development approach. Provide one (1) real-world example of the role that corpora ...

The scenario is to create a program for a windows company

The scenario is to create a program for a windows company. The program should display the total amount a customer owes, given the number of windows ordered and the price per window. Total owed is calculated by multiplyin ...

A product is made up of three parts that act independently

A product is made up of three parts that act independently of each other. If any of the parts is defective, the product is defective. Part one is defective 5% of the time, part two is defective 10% of the time, and part ...

Answer the following question take a cube graph q3 and add

Answer the following Question : Take a cube graph Q3 and add both face diagonals to one of the cube faces. The resulting graph is not planar, so by Kuratowski's theorem it contains a subdivision of K5 or of K3,3. Draw th ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As