11.07.2015 Views

Homework Assignment #1 - Department of Computing Science ...

Homework Assignment #1 - Department of Computing Science ...

Homework Assignment #1 - Department of Computing Science ...

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Problem 7. (10 marks) Consider the following program:Smallest (A, f, l)**Precondition: A[f . . . l] is an array <strong>of</strong> integers, f ≤ l and f, l ∈ N.**Postcondition: Returns the smallest element <strong>of</strong> A[f . . . l].if f = l thenreturn A[f]elsem = ⌊ f+l2 ⌋return min(Smallest(A, f, m), Smallest(A, m + 1, l))end ifa. (3 marks) Write a recurrence relation which describes the time complexity <strong>of</strong> this program in terms <strong>of</strong>the size <strong>of</strong> array A.b. (2 marks) Using the master theorem, give a Θ bound on the complexity <strong>of</strong> this program.c. (3 marks) Write a non-recursive version <strong>of</strong> Smallest(A, f, l) (in pseudo-code).d. (2 marks) Find the worst case running time <strong>of</strong> this new program and express it in Θ notation.Problem 8. (10 marks) An evil king has a cellar containing n bottles <strong>of</strong> expensive wine and his guardshave just caught a spy trying to poison the king’s wine. Fortunately, the guards caught the spy afterhe succeeded in poisoning only one bottle. Unfortunately, they don’t know which one. To make mattersworse, the poison the spy used was very deadly — just on drop diluted even a billion to one will stillkill someone. Even so, the poison works slowly — it takes a full month for the person to die. Design analgorithm that allows the evil king to determine exactly which one <strong>of</strong> his wine bottles was poisoned in justone month’s time while expending at most O(log n) <strong>of</strong> his wine tasters. Prove your claims.2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!