How do you find the recurrence relation for an algorithm?
Can you explain how you get a, b and c for masters theorem?
T(n)= aT(n/b)+O(n^c)
lets take an example to find its recurrence relation.
MergeSort Algorithm
void merge(int a[],int temp[],int l,int m,int r){
int temp_pos=l,size=r-l+1,left_end=m-1;
while(l<=left_end&&m<=r){
if(a[l]<a[m])temp[temp_pos++]=a[l++];
else temp[temp_pos++]=a[m++];
}
while(l<=left_end)temp[temp_pos++]=a[l++];
while(m<=r)temp[temp_pos++]=a[m++];
for(int i=0;i<size;i++){
a[r]=temp[r];
r--;
}
}
void mergesort(int a[],int temp[],int l,int r){
if(l<r){
int mid=l+(r-l)/2;
mergesort(a,temp,l,mid);
mergesort(a,temp,mid+1,r);
merge(a,temp,l,mid+1,r);
}
}
Here mergesort() function dividing array a[] into two equal
parts and calling mergesort again with
these two parts of array
let n was size of original array now size of two subproblems is
n/2.
And T(n) was total time for a problem for size n.
T(n) = T(n/2)+T(n/2) + f(n);
T(n) = 2*T(n/2) + f(n);
each mergesort() function also call merge function which runs equal
to size of input array.
merge() function complexity is O(n).
f(n) = O(n)
Therefore T(n) = 2*T(n/2)+O(n)
According to master's Theorem
T(n)= aT(n/b)+O(n^c)
a=2;
b=2;
c=1;
How do you find the recurrence relation for an algorithm? Can you explain how you get...
7. What is the worst-case running time complexity of an algorithm with the recurrence relation T(N) = 2T(N/4) + O(N2)? Hint: Use the Master Theorem.
Explain the Karatsuba-Ofman algorithm to multiply 2 n-bit integers. Derive a recurrence relation for its complexity and solve this recurrence relation.
Problem 1 [15pts. Recall how we solved recurrence relation to find the Big-O (first you need to find closed-form formula). Use same method (expand-guess-verify) to figure out Big-O of this relation. (You can skip last step "verify", which is usually done by math induction). T (1) 1 T(n) T(n-1)+5
3. Determine the asymptotic complexity of the function defined by the recurrence relation. Justify your solution using expansion/substitution and upper and/or lower bounds, when necessary. You may not use the Master Theorem as justification of your answer. Simplify and express your answer as O(n*) or O(nk log2 n) whenever possible. If the algorithm is exponential just give exponential lower bounds c) T(n) T(n-4) cn, T(0) c' d) T(n) 3T(n/3) c, T() c' e) T(n) T(n-1)T(n-4)clog2n, T(0) c'
3. Determine the...
Find an appropriate recurrence relation with initial conditions, and solve the recurrence relation. Find a recurrence relation for the number of ways to arrange cars in a row with n spaces if we can use Cadillacs or Hummers or Fords. A Hummer requires two spaces, whereas a Cadillac or a Ford requires just one space.
4 a) Find a recurrence relation for an, the number of sequences of 1's and 2's and 4's whose sum is n and with no 21 subsequence. b) Find a recurrence relation for an, the number of sequences of 1's and 2's and 4's whose sum is n and with no 44 subsequence. Answer is a) an = an-1+ an-4 + an-2 - an-3, b) an = an-1 + an-2 + an-5 + an-6, please explain how to get it,...
4 a) Find a recurrence relation for an, the number of sequences of 1's and 2's and 4's whose sum is n and with no 21 subsequence. b) Find a recurrence relation for an, the number of sequences of 1's and 2's and 4's whose sum is n and with no 44 subsequence. Answer is a) an = an-1+ an-4 + an-2 - an-3, b) an = an-1 + an-2 + an-5 + an-6, please explain how to get it,...
*algorithm analysis and design*
Solve the following recurrence relation T(n) = Tỉn/2) + 1 Using: 1-Recurrence Tree. 2-Master Therom.
06. Do any two of the following three parts Q6(a). Solve the following recurrence relation; Q6(b). Find a recurrence relation for an, which is the number of n-digit binary sequences with no pair of consecutive 1s. Explain your work. Q6(c) Solve the following problem using the Inclusion-Exclusion formula. How many ways are there to roll 8 distinct dice so that all the six faces appear? Hint: Use N(A'n n. NU)-S-,-1)' )-S-S2+S-(-1)Sn U- All possible rolls of 8 dice, Aj-Roll of...
3. 0 marks Suppose you have an algorithm which has the following recurrence relation for W(n), assuming n is a power of 2, i.e. assuming n-2, k20: for n for n- W()-2W(n/2)+2n+ 2 W(n)- Using back substitution and assuming n is a power of 2, ie. n-2, find an exact (ie non-recursive) formula for Win). Be sure to show your work and to simplify your final answer as much as possible. Note that you do NOT need to verify your...