- #1
darkvalentine
- 12
- 0
Homework Statement
1. HOARE-PARTITION(A,p,r) rearrange the array A[p...r] into 2 (possibly empty) subarray A[p...q] and A[q+1...r], so that each element of A[p...q] is at most A[p], and each element of A[q+1...r] is at least A[p].
x<-A[p]
i<-p-1
j<-r+1
while true
do repeat j<-j-1
until A[j]<=x
repeat i<-i+1
until A>=x
if i<j
then exchange A <-> A[j]
else return j
Find the worst time complexity in term of p and r.2/ Prove by induction on k :
(1+1/n)^k < 1 + k/n + k^2/n^2 for 1<= k <=n
Homework Equations
The Attempt at a Solution
1/ For the first repeat until I got time complexity to be O(r-p), but then I stuck.
2/ For base case it's true, but no clue how to do the inductive case.
Last edited: