Problem 5: Recurrence relations and detailed analysis of recursive algorithm efficiency
g(n: non-negative integer)
1. if n ≤ 1 then return n
2. else return (5 * g(n─1) ─ 6 * g(n─2))
MergeSort divides the array to be sorted into two equal halves, calls itself recursively on each half to sort that subarray, and then calls the Merge algorithm to merge the two sorted halves in linear time. This leads to its two recurrence relations T(n)=2T(n/2)+cn, n>1; T(1)=c. We solved these recurrences using the Recursion Tree method in class to show that T(n)=cnlog2n+cn and therefore its complexity order is Θ(nlog2n). Now consider the question of whether Merge Sort will be faster if we split the array into three equal one-thirds, made a recursive call on each one-third to sort it and used a modified Merge algorithm to merge the three sorted subarrays into one wholly sorted array. Assuming that we can merge three sorted one-thirds in linear time, i.e., with the same cn work, the corresponding recurrences are:
T(n)=3T(n/3)+cn, n>1; T(1)=c.
What is the complexity order of this new MergeSort algorithm, that you obtain by applying the Master Theorem?
A. Θ(n) B. Θ(nlgn) C. Θ(cn) D. Θ(nlog3n) E. Master Theorem cannot be applied
Solve the recurrences of this modified MergeSort using the more precise Recursion Tree method. It can be seen from the table that total work done by all recursive executions = T(n) = cn * (______________). What is the correct expression to fill in this blank?
A. lgn B. log3n C. log3n+1 D. lgn+1 E. none of these are correct
level |
Level number |
Total # of recursive executions at this level |
Input size to each recursive execution |
Work done by each recursive execution, excluding the recursive calls |
Total work done by the algorithm at this level = column3*column5 |
0 |
0 |
30 |
n/30 |
c(n/30) |
cn |
1 |
1 |
31 |
n/31 |
c(n/31) |
cn |
2 |
2 |
32 |
n/32 |
c(n/32) |
cn |
The level just above the base case level |
(log3n-1) |
3(logntobase3-1) = (nlog3tobase3)/3 = n/3 |
n/3(logntobase3-1)=3 |
c(3) |
cn |
Base case level |
log3n |
3logntobase3 = nlog3tobase3 = n |
n/3logntobase3=1 |
c(1) |
cn |
For question 1:-
By applying Master Theorem:-
If f(n) = Θ(nc) where c = Logba then T(n) = Θ(ncLog n)
here c=1 , b=3, a=3
we get T(n) = Θ(nlogn) (Option B)
For question 2:-
By applying Recursion Tree method ,
we get log3n(Option B)
Problem 5: Recurrence relations and detailed analysis of recursive algorithm efficiency g(n: non-negative integer)  
Part A Analyze the following recurrences and show their time complexity functions using (I) iteration method and (2) Master Theorem. AI. T(n) = 2T 3 A2. T(n) = 3T 2n АЗ. Т(п) — Т(п — 2) + 3 А4. Т(п) — 2Т (п — 1) + 1 A5. T(n)= 4T +n log n A6. T(n) = 3T +n log n n2 A7. T(n) = 27 Part B Do 2.3-4 (р39) and Problem 2-1 (р39) Part C Implement MERGE-SORT() algorithm that...
Implement MERGE-SORT() algorithm that reads from a file named “inputHW02.txt” a list of double numbers (max = 3,000,000 numbers), sorts those numbers and indicates time consumption. This programming question will address the advantage of using iteration loops over recursive calls as well as using INSERTION-SORT() as a procedure in MERGESORT(). Your program must perform the following actions: 1. Opens the given file name and reads all double numbers. For simplicity, we assume this file only contains numbers and nothing else....
Implement MERGE-SORT() algorithm that reads from a file named “inputHW02.txt” a list of double numbers (max = 3,000,000 numbers), sorts those numbers and indicates time consumption. This programming question will address the advantage of using iteration loops over recursive calls as well as using INSERTION-SORT() as a procedure in MERGESORT(). Your program must perform the following actions: 1. Opens the given file name and reads all double numbers. For simplicity, we assume this file only contains numbers and nothing else....
3a. Runtime Analysis: For each of the following recursive algorithms, state the recurrence equation that is the runtime of the algorithm. Briefly describe how you determined each term. You do not need to provide the runtime bound – just the equation. T(n) = Product(array, p) // n is size of array if (p>n) return 1 if (array[p] != 0) return array[p] * Product(array, p+1) else return Product(array, p+1) Describe terms: T(n) = Describe terms: // modified merge sort mod Merge(...
Implement MERGE-SORT() algorithm that reads from a file named “inputHW02.txt” a list of double numbers (max = 3,000,000 numbers), sorts those numbers and indicates time consumption. This programming question will address the advantage of using iteration loops over recursive calls as well as using INSERTION-SORT() as a procedure in MERGESORT(). Your program must perform the following actions: 1. Opens the given file name and reads all double numbers. For simplicity, we assume this file only contains numbers and nothing else....
Implement MERGE-SORT() algorithm that reads from a file named “inputHW02.txt” a list of double numbers (max = 3,000,000 numbers), sorts those numbers and indicates time consumption. This programming question will address the advantage of using iteration loops over recursive calls as well as using INSERTION-SORT() as a procedure in MERGESORT(). Your program must perform the following actions: 1. Opens the given file name and reads all double numbers. For simplicity, we assume this file only contains numbers and nothing else....
When asked to describe an algorithm you are expected to give a
clear pseudo-code description of the algorithm
1. (10 pts) Here is a new sorting algorithm NewSort Suppose the original call made is NewSort(A,0,n-1) where A is an array integers. == void NewSort(int A[], int i, int j){ \\ sorts the subarray Aſi..j] if (j i+1) \\when there are only 2 elements if (A[i] > A[j]) swap(A,i,j) \\swaps A[i] and A[j] else { int k = (j-i+1)/3; NewSort(A,i,j-k); \\...
In C++:
1. What is the difference between a deterministic algorithm and a randomized algorithm? 2. What is the difference between a Las Vegas algorithm (pattern) and a Monte Carlo algorithm? 3. Solve the following recurrences, giving the answer in terms of Big-Oh O() F (n) = 4F ( 1 ) +no F (n) = 2 F (*) +2 4. Given the string "DECEMBER", execute the mergesort algorithm by hand to sort it. Show your work to make it clear...
(a) Give the pseudo-code for a recursive algorithm called Find_Smallest(A, n) that returns the value of the smallest element in an array of n integers called A. Assume the elements in the array are at locations A[1]..A[n]. (b) Give a recurrence T(n) for the running time of your algorithm. (c) Solve the recurrence in part (b)
Mergesort3: Your friend suggests the following variation of Mergesort: instead of splitting the list into two halves, we split it into three thirds. Then we recursively sort each third and merge them. Mergesort3 (A[1...n]): If n <= 1, then return A[1..n] Let k = n/3 and m = 2n/3 Mergesort3(A[1..k]) Mergesort3(A[k+1..m]) Mergesort3(A[m+1..n) Merge3(A[1..k], A[k+1,..m], A[m+1..n]) Return A[1..m]. Merge3(L0, L1, L2): Return Merge(L0, Merge(L1,L2)). Assume that you have a function Merge that merges two sorted...