Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

24.12.12 file:///home/trig-ger/Necessary/Downlo...ercise-wk01-Analysis-of-alogrithms.

htm #1

COURSES ABOUT  LARRY DEPLUME 

Robert Sedgewick

Algorithms, Part I Kevin Wayne

Home
Exercises: Analysis of Algorithms
Syllabus

Schedule To specify an array or sequence of values in an answer, you must separate the values by a
single space character (with no punctuation and with no leading or trailing whitespace).
Booksite For example, if the question asks for the first ten powers of two (starting at 1), the
only accepted answer is:
Lectures
1 2 4 8 16 32 64 128 256 512
Survey
If you wish to discuss a particular question and answer in the forums, please post the
Exercises entire question and answer, including the seed (which is used by the course staff to
uniquely identify the question) and the explanation (which contains the correct answer).
Programming Assignments

Job Interview Questions

Discussion Forums
Question 1
Join a Meetup (seed = 777280)
Download http://coursera.cs.princeton.edu/algs4/Timing.class

Using the value 777280 for the seed, estimate the order of growth of the running time
of the function call Timing.trial(N, seed) as a function of N. To do so, write a program
that
calls Timing.trial(N, seed) for different values of N and measures how long each
function call
takes (e.g., via the Stopwatch library in algs4.jar). Then, formulate a doubling
hypothesis to
estimate the order of growth.

Assume that the running time obeys a power law T(N) ~ a N^b. For your answer, enter the
constant b. Your answer will be marked as correct if it is within 5% of the target
answer -
we recommend using two digits after the decimal separator, e.g., 2.34.

Question 2
(seed = 152000)
What is the order of growth of the worst case running time of the following code
fragment
as a function of N?

int sum = 0;
for (int i = 0; i < N; i++)
for (int j = 1; j <= N*N; j = j*2)
sum++;

log N

N^1/2
24.12.12 file:///home/trig-ger/Necessary/Downlo...ercise-wk01-Analysis-of-alogrithms.htm #2

N log N

N^3/2

N^2

N^5/2

N^3

N^4

N^5

N^6

N^7

Question 3
(seed = 770816)
Given the following definition of a MysteryBox object:

public class MysteryBox {


private long x0, x1, x2, x3;
private double y0, y1, y2, y3;
private boolean z0, z1;
private int[] a = new int[288];

...
}

Using the 64-bit memory cost model from lecture, how many bytes does each object of type
MysteryBox use?

In accordance with the Honor Code, I certify that my answers here are my own work.

In accordance with the Honor Code, I certify that my answers here are my own work.

You might also like