Basic asymptotics.
∀ a>1
an ∈ O(nᵃ). It's enough to show that for n>n₀,an ≤ anᵃi.e.
n ≤ nᵃtake logs (base
n) of both sides1 ≤ awhich is true.
∀ a>0, b > 0,
nᵃ+nᵇ ∈ O(nᶜ)where c=a+b. W.l.o.g, suppose a ≤ bnᵃ + nᵇ ≤ 2nᵇ nᵇ ≤ nᶜ (take logs of both sides) nᵃ + nᵇ ≤ 2nᶜ
This recurrence is straightforward master theorem. Don't forget substitution method and recursion tree.
Some notation:
lg n ≡ log₂ n;lg² n ≡ (lg n)²IH:T(n) ≤ c (lg² n), for somec≥ 1.T(n) ≤ c lg² (n/2) (apply IH) = c (lg n -1)² = c [lg² n - 2lg n +1] = c lg² n - [2c·lg(n) - c]To force residual non-negative, we need
2 lg(n) ≥ 1This holds for any integer
n≥ 2String Append
Concatentation is Θ(1)
T(l) = T(l-1) + Θ(1) = ∑{ Θ(1) | 0 ≤ i ≤ l} = Θ(l)S ∘ a is Θ(|S|)
T(l) = T(l-1) + Θ(k+l) ≤ T(l-1) + c(k+l) ≤ ∑ { c(k+i) | 0 ≤ i ≤ l } ≤ ckl + cl(l+1)/2 ∈ O(kl + l²)
Ω proof would be the same, with a difference constant and ≥ instead of ≤
Unlucky Pete.
Formulating problem
N ≡ ∑ { Xᵢ |i≥ 1} Xᵢ = 1 if UP takes the course ≥ i times, 0 otherwiseCalculating expectation
E[N] = E[∑Xᵢ] = ∑ E[Xᵢ] (L.O.E.) E[Xᵢ] = (1-p)ⁱ/(1-p) E[N] = ∑ { (1-p)ⁱ/(1-p) | i ≥ 1} = ∑ { (1-p)ⁱ | i ≥ 0} = 1/(1-(1-p)) Geometric series = 1/p
The random part of the run time is how many times the
repeatloop runs. Note thatA[p]has a1/nchance of being the maximum, and apply the same analysis as for question 4 to getE[N] = ∑ { (1-1/n)ⁱ | i ≥ 0} = nSince each iteration is
Θ(n), that gives a total ofΘ(n²)Solving recurrences
T(n) = ∑ { iᶜ ∣ 1≤ i ≤ n }. Bound above byntimes largest term. Bound below byn/2times then/2smallest term.Θ(n^{c+1})T(n) = ∑ { cⁱ ∣ 1≤ i ≤ n }Geometric series.