Quiz1
Solution
Chapter 4
Answer 1 when sub problem becomes small enough that we no longer
recurse it, then the recursion is bottoms out.
Answer 2 Different methods of solving recursion are as follow: Substitution, Recursion tree, master theorem.
Answer 3 B
Answer 4 We guess T(n)≤cn^2 for a particular c Then:
T(n)≤c(n−1)^2+n=cn^2−2cn+c+n
If we pick c=1 we have:
n^2−2n+1+n=n^2−n+1≤n^2 for n≥1
Answer 5 C
Answer 6
Answer 7
Equation a:- T(n)=2T(n/4)+n=Θ(n)
Equation b:-T(n)=2T(n/4)+n^2= Θ(n^2
)
Answer 8 True
Answer 9 T(n)=n^2+T(n−2) = n^2+(n−2)^2+T(n−4)
n/2
=∑ (n−2i)^2 = Θ(n^3)
i=0
Quiz1
Solution
Chapter 5
Answer 1: - we call an algorithm randomized if its behavior is determined
not only by its input but also by values produced by a random-number
generator.
Answer 2: - You hire once when the best candidate is first. There is1/n
chance of that happening (n! positions in(n−1)! of which they are first).You
hire n times when the candidates come in increasing order, which is1/n !.
Answer 3: - D
Answer 4: - The probability that each person gets their hat back is 1/n. Let
Xi be the event that the I th person gets their hat back. Thus:
n
E[X]=E[X1+X2+…+Xn ]=∑ E[Xi]=1
i=1
Answer 5: -It does not. It always changes the position of each element. We
cannot get the identity permutation, but we also can't get any permutation
where an element is at the same place.
Answer6: - Ω(nlgn)
Quiz1
Solution
Set 2
Answer1 Divide Conquer Combine
Answer2 Recursion in computer science is a method where the solution to a
problem depends on solutions to smaller instances of the same problem
Answer 3 B
Answer 4 A
Answer 5 a) T(n) = T(n-1) + n
b) Is the solution asymptotically tight bound? Verify your answer
Quiz1
Answer 6 Answer the following questions: (4)
a)
b) T(n) = 4T(n/2) + n2√n.
c) T(n) = 3T(n/2) + n lg n
Solution
Quiz1
d) T(n) = 4T(n/2) + n2 lg n.
Solution
Quiz1
Solution
Chapter 5
Answer 1
Answer 2
Sample space is {H, T}.
• Pr {H} = Pr {T} = 1/2.
• Define indicator random variable XT
XT = I {T} = 1 if H occurs or 0 if T occurs.
Where XT counts the number of tails in one flip.
• Since Pr {T} = 1/2, we have to calculated the expected value of
the indicator random variable.
E[XT] = E[I{T}]
= 1. Pr {H} + 0. Pr {T}
= 1. (1/2) + 0. (1/2)
= 1/2
Answer 3 Average cost of hiring a candidate is O(Cin + Chm)
Worst case occurs when we hire all n, therefore:
Quiz1
Solution
Worst case of hiring a candidate is O(Chn).
Where Ch = Cost of hiring a candidate
n = total number of candidates
Answer 4 An algorithm is randomized if its behavior is determined in part
by values produced by a random-number generator.
• RANDOM(a, b) returns an integer r , where a ≤ r ≤ b and each of the
b−a+1possible values of r is equally likely.
• In practice, RANDOM is implemented by a pseudorandom-number
generator, which is a deterministic method returning numbers that .look.
random and pass statistical tests.
Answer 5 For HIRE-ASSISTANT problem, we have assumed that
- For any given input, the number of times we hire a new office
assistant will always be the same.
- The number of times we hire a new office assistant depends only on
the input.
- In fact, it depends only on the ordering of the candidate’s ranks that it
is given.
- Some rank orderings will always produce a high hiring cost. Some
will always produce low hiring cost and some may be in between.
To randomize this process, rather than interviewing the candidates in the
order presented, we will randomly permuted the order beforehand.
- The randomization is now in the algorithm, not in the input
distribution.
- Given a particular input, we can no longer say what its hiring cost will
be. Each time we run the algorithm, we can get a different hiring cost.
- No particular input always elicits worst-case behavior.
- Bad behavior occurs only if we get “unlucky” numbers from the
random number generator.
Answer 6
Quiz1
Solution
Answer 7
The expected hiring cost is: O(Ch ln n)
Where Ch = Cost of hiring a candidate
n = total number of candidates
Answer 8 Since HIRE-ASSISTANT always hires candidate 1, it hires
exactly once if and only if no candidates other than candidate 1 are hired.
This event occurs when candidate 1 is the best candidate of the n, which
occurs with probability 1/n.
Answer 9 HIRE-ASSISTANT hires n times if each candidate is better than
all those who were interviewed (and hired) before. This event occurs
precisely when the list of ranks given to the algorithm is 1, 2, . . . , n. which
occurs with probability 1/n!.
© Copyright 2026 Paperzz