Home > CS3310: Design and Analysis of Algorithms > Group HW 1Group HW 1
Lighter or heavier? You have n > 2 identical-looking coins and a two-pan balance scale with no weights. One of the coins is a fake, but you don’t know whether it’s lighter or heavier than the genuine coins, which all weigh the same.
Design a \Theta(1) algorithm to determine whether the fake coin is lighter or heavier than the others.
Consider the following algorithm:
ALGORITHM Secret(A[0..n-1])
// Input: An array A[0..n-1] of n real numbers
minval \leftarrow A[0]; maxval \leftarrow A[0]
for i \leftarrow 1 to n-1 do
if A[i] \lt minval
minval \leftarrow A[i]
if A[i] \gt maxval
maxval \leftarrow A[i]
return maxval \text{$-$} minval
Solve the following recurrence relation:
x(n) = x(n/2) + n \text{ for } n > 1, \quad x(1) = 1 \text{ (solve for $n=2^k$)}
Frying hamburgers There are n hamburgers to be fried on a small grill that can hold only two hamburgers at a time.
Each hamburger has to be fried on both sides; frying one side of a hamburger takes 1 minute, regardless of whether one or two hamburgers are fried at the same time.
Consider the following recursive algorithm for executing this task in the minimum amount of time: