Chapter 3 Flashcards
Show that for any real constants a and b, where b > 0,
Is 2^{n + 1} = O(2^n)2n+1=O(2n)? Is 2^{2n} = O(2^n)22n=O(2n)?
Prove that the running time of an algorithm is Ξ(g(n)) if and only if its worst-case running time is O(g(n)) and its best-case running time is Ξ©(g(n)).
Rank the following functions by order of growth; that is, find an arrangement π1, π2, β¦ , π12 of the functions satisfying π1 = Ξ©(π2 ), π2 = Ξ©(π3 ), β¦ , π11 = Ξ©(π12). Partition your list into equivalence classes such that functions π(π) and π(π) are in the same class if and only if π(π) = Ξ(π(π)).
Prove:
- π! = π(π^π).
- π! = Ο(2 π).
- lg(π !) = Ξ(π lg π).
Answer
.
f. Prove, from the first, we know that 0β€ f(n) β€ cg(n) and we need to prove that 0 β€ df(n )β€ g(n), which is straightforward with d=1/c.
g. Disprove, letβs pick f(n) = 2^nf(n)=2n. We will need to prove that
βc1β,c2β,n0 β: β n β₯ n0β, 0 β€ c1 ββ 2^n/2 β€ 2n β€ c2 ββ 2^n/2,
which is obviously untrue.
h. Prove, let g(n) = o(f(n)). Then
βc,n0 β: β nβ₯n0β , 0 β€ g(n) < cf(n).
We need to prove that
βc1β,c2β,n0 β: β n β₯ n0β , 0 β€ c1βf(n) β€ f(n) + g(n) β€ c2βf(n).
Thus, if we pickc1β=1 and c2β=c+1, it holds.
Write a recursive algorithm to implement the Tower of Hanoi game. The Tower of Hanoi is a very famous game. In this game, there are three pegs and N number of disks placed one over the other in decreasing size. The objective of this game is to move the disks one by one from the first peg to the last peg. And there is only one condition, we cannot place a bigger disk on top of a smaller disk. What is the time complexity of your algorithm?