wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Coursera Design Algorithm

Total questions: 27

Worksheet time: 15mins

Name
Class
Date
1.

Question 1) 3-way-Merge Sort : Suppose that instead of dividing in half at each step of Merge Sort, you divide into thirds, sort each third, and finally combine all of them using a three-way merge subroutine. What is the overall asymptotic running time of this algorithm? (Hint: Note that the merge step can still be implemented in O(n) time.)


a)
  • n(log(n))2

  • n2 log(n) 

  • п 

  • n log(n)

 

b)
  • n2 log(n) 

  • п 

  • n log(n)

 

c)
  • п 

  • n log(n)

d)
  • n log(n)

2.

You are given functions f and g such that f(n) = O(g(n)). Is f(n) log2(f(n)) = O(g(n) log2(g(n))) ? (Here cis some positive constant.) You should assume that f and g are nondecreasing and always bigger than 1.

a)
  • Sometimes yes, sometimes no, depending on the functions f and g

b)
  • Sometimes yes, sometimes no, depending on the constant c

c)
  • False

d)
  • True

3.

Assume again two (positive) nondecreasing functions f and g such that f(n) = O(g(n)). Is 27(n) = O(29(n)) ? (Multiple answers may be correct, you should check all of those that apply.)

a)
  • Always

  • yes

b)
  • Never

c)
  • Sometimes yes, sometimes no (depending on f and g)

d)
  • if f(n) ≤ g(n) for all sufficiently large n

4.

K-way-Merge Sort. Suppose you are given k sorted arrays, each with n elements, and you want to combine them into a single array of kn elements. Consider the following approach. Using the merge subroutine taught in lecture, you merge the first 2 arrays, then merge the 3rd given array with this merged version of the first two arrays, then merge the 4th given array with the merged version of the first three arrays, and so on until you merge in the final (kth) input array. What is the running time taken by this successive merging algorithm, as a function of k and n? (Optional: can you think of a faster way to do the k-way merge procedure ?)

a)
  • θ(nk)

b)
  • θ(nk)

c)
  • θ(n2 k) 

d)

  • θ(n log(k))

5.

Arrange the following functions in increasing order of growth rate (with g(n) following f(n) in your list if and only if f(n) = O(g(n)))

  • a)22 n

  • b)2 n2

  • c)n2 log(n)

  • d)n

  • e)n2 n

a)

dcbae

b)

bcdae

c)

aecbd

d)

dcbae

6.

This question will give you further practice with the Master Method. Suppose the running time of an algorithm is governed by the recurrence T(n) = 7 T(n / 3) +n2. What’s the overall asymptotic running time (i.e, the value of T(n))?

  • Ө(n2 log n) 

  • Ө(n2)

  • Ө(n2.81)

  • Ө(n log n)

a)
  • Ө(n2 log n) 

b)
  • Ө(n2)

c)
  • Ө(n2.81)

d)
  • Ө(n log n)

7.

This question will give you further practice with the Master Method. Suppose the running time of an algorithm is governed by the recurrence T(n) = 9T(n / 3) +n2. What’s the overall asymptotic running time (i.e, the value of T(n))?

a)
  • Ө(n2 log n) 

b)
  • Ө(n2)

c)
  • Ө(n3.17)

d)
  • Ө(n log n)

8.

This question will give you further practice with the Master Method. Suppose the running time of an algorithm is governed by the recurrence T(n) = 5T(n / 3) +4n. What’s the overall asymptotic running time (i.e, the value of T(n))?

 

a)
  • Ө(n2.59)

b)
  • Ө(n2)

c)
  • Ө(nlog 3 / log 5)

d)
  • )

  • Ө(n5/3)

e)
  • Ө(nlog 3 / (5))

9.

Consider the following pseudocode for calculating a where a and bare positive integers)  

FastPower(a,b) :    if b = 1        return a  else    c : = a*a   ans := Fast Power(c,[b/2])  if b is odd      return a*ans  else return ans end

a)
  • Ө(b log(b)) 

b)
  • Ө(log(b))

c)
  •  

  • Ө(b)

d)
  • Ө(√b)

10.

Choose the smallest correct upper bound on the solution to the following recurrence T(1) = 1 and T (n) ≤ T( [√n]) +1 for n > 1. Here [x] denotes the “floor” function, which rounds down to the nearest integer. (Note that the Master Method does not apply.)

a)

 

  • 0(log n)

b)
  • 0(√n)

c)
  • 0(1)

d)
  • 0(log log n ) 

11.

Let 0 < a <.5 be some constant (independent of the input array length n). Recall the Partition subroutine employed by the QuickSort algorithm, as explained in lecture. What is the probability that, with a randomly chosen pivot element, the Partition subroutine produces a split in which the size of the smaller of the two subarrays is ≥ a times the size of the original array?

a)
  • 1 – 2 ✲ a

b)
    • a

c)
    • 1 – a

d)
  • 2 – 2✲a

12.

Define the recursion depth of QuickSort to be the maximum number of successive recursive calls before it hits the base case — equivalently, the number of the last level of the corresponding recursion tree. Note that the recursion depth is a random variable, which depends on which pivots get chosen. What is the minimum-possible and maximum-possible recursion depth of QuickSort, respectively?

a)
  • Minimum: Θ(log(n)); Maximum: Θ(n)

b)
  • Minimum: Θ(log(n)); Maximum: Θ(n log(n))

c)
  • Minimum: Θ(1); Maximum: Θ(n)

d)
  • Minimum: Θ(√n); Maximum: Θ(n)

13.

Consider a group of k people. Assume that each person’s birthday is drawn uniformly at random from the 365 possibilities. (And ignore leap years.) What is the smallest value of k such that the expected number of pairs of distinct people with the same birthday is at least one?

[Hint: define an indicator random variable for each ordered pair of people. Use linearity of expectation.]

a)
  • 28

b)
    • 27

c)
    • 20

d)
  • 23

e)
  • 366

14.
  • Let X1, X2, X3 denote the outcomes of three rolls of a six-sided die. (l.e., each Xi  is uniformly distributed among 1,2,3,4,5,6, and by assumption they are independent.) Let Y denote the product of X1 and X2 and Z the product of X2 and X3. Which of the following statements is correct?

a)
  • Y and Z are independent, but E[Y ✱ Z] ≠ E[Y]✱ E[Z].

b)
  • Y and Z are independent, and E[Y ✱ Z] ≠ E(Y] ✱ E[Z]

c)
  • .

    • Y and Z are not independent, and E[Y ✱ Z] ≠ E(Y] ✱ E[Z].

d)
  • Y and Z are not independent, but E[Y ✱ Z] ≠ E(Y] ✱ E[Z].

15.

How many different minimum cuts are there in a tree with n nodes (ie. n – 1 edges)?

a)
  • 2n –2

b)
  • (n2)

c)
    • n – 1

d)
  • n

16.

Let “output” denote the cut output by Karger’s min cut algorithm on a given connected graph with n vertices, and let p =1/(n2) . Which of the following statements are true? 

For hints on this question, you might want to watch the short optional video on “Counting Minimum Cuts”.

a)
  • For every graph G with n nodes, there exists a min cut (A, B) of G such that Pr[out = (A, B] ≥ p.

b)
  • For every graph G with n nodes and every min cut (A,B), Pr[out = (A, B] ≤ p.

c)
    • For every graph G with n nodes and every min cut (A, B) of G, Pr[out = (A, B] ≥ p

d)
  • For every graph G with n nodes, there exists a min cut (A, B) such that Pr(out = (A, B)] <p.

e)
  • There exists a graph G with n nodes and a min cut (A, B) of G such that Pr[out = (A, B]≤ p

17.

Let .5< a < 1 be some constant. Suppose you are looking for the median element in an array using RANDOMIZED SELECT (as explained in lectures). What is the probability that after the first iteration the size of the subarray in which the element you are looking for lies is ≤ a times the size of the original array?

a)
  • 1 –a/2

b)
    • 1– a

c)
    • 2*a-1

d)
  • A –½

18.

The minimum s-t cut problem is the following. The input is an undirected graph, and two distinct vertices of the graph are labelled “s” and “t”. The goal is to compute the minimum cut i.e., fewest number of crossing edges) that satisfies the property that s and t are on different sides of the cut.

Suppose someone gives you a subroutine for this s-t minimum cut problem via an API. Your job is to solve the original minimum cut problem (the one discussed in the lectures), when all you can do is invoke the given min s-t cut subroutine. (That is, the goal is to reduce the min cut problem to the min s-t cut problem.)

Now suppose you are given an instance of the minimum cut problem — that is, you are given an undirected graph (with no specially labelled vertices) and need to compute the minimum cut. What is the minimum number of times that you need to call the given min s-t cut subroutine to guarantee that you’ll find a min cut of the given graph? 

a)

  • 2n

b)
    • N

c)
    • (n2)

d)
  • n – 1

19.

Recall the Partition subroutine that we used in both QuickSort and RSelect. Suppose that the following array has just been partitioned around some pivot element: 3, 1, 2, 4, 5, 8, 7, 6,9

Which of these elements could have been the pivot element? (Hint: Check all that apply, there could be more than one possibility!)

a)

  • 5

b)
    • 9

c)
    • 3

d)
  • 2

e)
  • 4

20.

Here is an array of ten integers: 5 3 8 9 1 7 0 2 6 4

Suppose we run Merge Sort on this array. What is the number in the 7th position of the partially sorted array after the outermost two recursive calls have completed (i.e., just before the very last Merge step)? (When we say “7th” position, we’re counting positions starting at 1; for example, the input array has a “0” in its 7th position.)

a)

  • 1

b)
    • 2

c)
    • 3

d)
  • 4

21.

What is the asymptotic worst-case running time of MergeSort, as a function of the input array length n?

a)
  • θ(log n)

b)
    • θ(n log n)

c)
    • θ(n)

d)
  • θ(n2)

22.

What is the asymptotic running time of Randomized QuickSort on arrays of length n, in expectation over the choice of random pivots) and in the worst case, respectively?

a)
  • Ө(n log n) [expected) and Ө(n log n) [worst case]

b)
    • Ө(n2) [expected] and Ө(n2) [worst case] 

c)
    • Ө(n) [expected] and Ө(n log n) [worst case] 

d)
  • Ө(n log n) [expected] and Ө(n2) [worst case]

23.

Let f and g be two increasing functions, defined on the natural numbers, with f(1),g(1) ≥1. Assume that f(n) =O(g(n)). Is 2f(n) ) = 0(29(n)) ? (Multiple answers may be correct, check all that apply.)

a)

  • Never

b)
    • Maybe, maybe not (depends on the functions f and g).

c)
    • Always

d)
  • Yes if f(n) ≤ g(n) for all sufficiently large n

24.

Let 0 < a <.5 be some constant. Consider running the Partition subroutine on an array with no duplicate elements and with the pivot element chosen uniformly at random (as in QuickSort and RSelect). What is the probability that, after partitioning, both subarrays (elements to the left of the pivot, and elements to the right of the pivot) have size at least a times that of the original array?

a)

  • 2 – 2a

b)
    • A

c)
    • 1 – a

d)
  • 1 – 2a

25.

Suppose you are given k sorted arrays, each with n elements, and you want to combine them into a single array of kn elements. Consider the following approach. Divide the k arrays into k/2 pairs of arrays, and use the Merge subroutine taught in the Merge Sort lectures to combine each pair. Now you are left with k/2 sorted arrays, each with 2n elements. Repeat this approach until you have a single sorted array with kn elements. What is the running time of this procedure, as a function of k and n?

a)

  • θ(n log k)

b)
    • θ(nk log n)

c)
    • θ(nk log k)

d)
  • θ(nk2)

26.

Running time of Strassen’s matrix multiplication algorithm: Suppose that the running time of an algorithm is governed by the recurrence T(n) = 7T(n/2) + n2. What’s the overall asymptotic running time (i.e., the value of T(n))?

a)

  • θ(n2 log n)

b)
  • θ(nlog 2/ log 7)

c)
    • θ(nlog2(7))

d)
  • θ(n2)

27.

Recall the Master Method and its three parameters a, b, d. Which of the following is the best interpretation of ba, in the context of divide-and-conquer algorithms?

a)

  • The rate at which the total work is growing (per level of recursion).

b)
    • The rate at which the number of subproblems is growing (per level of recursion).

c)
    • The rate at which the work-per-subproblem is shrinking (per level of recursion).

d)
  • The rate at which the subproblem size is shrinking (per level of recursion).