Question

Question 2 (8 marks) (From the DPU textbook, Exercise 2.5) Using the Master theorem or recursion tree methods, solve the following recurence relations and give Θ bound for each of them a) T(n) 9T(n/3) +3n2 12n - 4, where n 21 b) T(n)-T(n-1) + n, where n > 1 and c > 0 c) T(n) = T(Vn) + 1, where n > b and T(b) = 2. Question 3: 10 marks) Suppose we have a subroutine merge2 to merge two sorted arrays in linear time (kn The purpose is to design a divide and conquer algorithm (Alg2) to merge k sorted arrays using merge2 recursively. a) Write a pseudocode for Alg2. (Hint: Assume that the input is given in a (k x n) rray with the rows and columns sorted in ascending order) b) Write the running time of Alg2 as a recurence relation. T(k)-? c) Construct a recursion tree with log k levels and (kn) work per level to represent the d) Since k is a constant, is Alg2 asymptotically faster than an algorithm with running time recurance relation obtained in part (b) Θ(n log n)? why?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Question 2:

(a)

T(n) = 9T(n/3) + 3n2 + 12n-1, where n > 1

Here, f(n) - 3n2+12n -4O(n2)

Applying Master's second case method, for a=9 and b=3.

T(n)-Θ(n2 log n)

(b)

T(n) -T(n - 1)+ne, where n 2 1 and c2 0

(n-1) (n-2) (n-3) (n-l) n-2 n-3)C 1°

From above recursion tree,

  T(n)=Theta(n^c)

(c)

T(n)=T(sqrt(n))+1, where n>b and T(b)=2.

Substituting, n=2m=>log n=m in above recursion.

T(2m)=T(2m/2)+1.

Now, substituting, T(2m)=S(m).

S(m)=S(m/2)+1.

Now, applying case 1 of Master's Method,(a=1, b=2) solution is:

S(m)=Theta(log m)=Theta(log log n).

Add a comment
Know the answer?
Add Answer to:
Question 2 (8 marks) (From the DPU textbook, Exercise 2.5) Using the Master theorem or recursion...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Weird recursion tree analysis. Suppose we have an algorithm that on problems of size n, recursively...

    Weird recursion tree analysis. Suppose we have an algorithm that on problems of size n, recursively solves two problems of size n/2, with a “local running time” bounded by t(n) for some function t(n). That is, the algorithm’s total running time T(n) satisfies the recurrence relation T(n) ≤ 2T(n/2) + t(n). For simplicity, assume that n is a power of 2. Prove the following using a recursion tree analysis (a) If t(n) = O(n log n), then T(n) = O(n(log...

  • Insertion sort on small arrays in merge sort Although merge-sort runs in Θ(n log n) worst-case...

    Insertion sort on small arrays in merge sort Although merge-sort runs in Θ(n log n) worst-case time and insertion sort runs in Θ(n 2 ) worst-case time, the constant factors in insertion sort can make it faster in practice for small problem sizes on many machines. Thus, it makes sense to coarsen the leaves of the recursion by using insertion sort within merge sort when subproblems become sufficiently small. Consider a modification to merge sort in which n/k sublists of...

  • Please answer this in python pseudocode. It's an algorithm question. 1. [10 marks] Consider the function...

    Please answer this in python pseudocode. It's an algorithm question. 1. [10 marks] Consider the function SumKSmallest(A[0..n – 1), k) that returns the sum of the k smallest elements in an unsorted integer array A of size n. For example, given the array A=[6,-6,3,2,1,2,0,4,3,5] and k=3, the function should return -5. a. [3 marks) Write an algorithm in pseudocode for SumKSmallest using the brute force paradigm. Indicate and justify (within a few sentences) the time complexity of your algorithm. b....

  • Suppose the following is a divide-and-conquer algorithm for some problem. "Make the input of size n...

    Suppose the following is a divide-and-conquer algorithm for some problem. "Make the input of size n into 3 subproblems of sizes n/2 , n/4 , n/8 , respectively with O(n) time; Recursively call on these subproblems; and then combine the results in O(n) time. The recursive call returns when the problems become of size 1 and the time in this case is constant." (a) Let T(n) denote the worst-case running time of this approach on the problem of size n....

  • Problem 5: Recurrence relations and detailed analysis of recursive algorithm efficiency                 g(n: non-negative integer)        &nbsp

    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;...

  • Mergesort3: Your friend suggests the following variation of Mergesort: instead of splitting the list into two...

    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...

  • [2 marks]Describe how to multiply two n-degree polynomials together in O(n logn) time, using the Fast...

    [2 marks]Describe how to multiply two n-degree polynomials together in O(n logn) time, using the Fast Fourier Transform (FFT). You do not need to explain how FFT works – you may treat it as a black box. In this part we will use the Fast Fourier Transform (FFT) algorithm described in class to multiply multiple polynomials together (not just two). Suppose you have K polynomials P1, . . . , Pk so that degree(P1) +···+ degree(PK) =S (i)[6 marks]Show that...

  • problem 2 can use Det-Selection(A, p, q, r) as a sub-routine (i.e, you don't need to...

    problem 2 can use Det-Selection(A, p, q, r) as a sub-routine (i.e, you don't need to write its pseudo-code). To sort an array A, you will then call Det-QuickSort(A, 1, n). You also need to provide the worst case time complexity analysis of your algorithm. 2. (20 points) Given a set of n distinct numbers, we wish to find the k largest in sorted order using a comparison-based algorithm. Give an algorithm that implements each of the following methods, and...

  • Puodace a char showing the number of moves required to solve the Towers of Hanoi puzle using t 30...

    Puodace a char showing the number of moves required to solve the Towers of Hanoi puzle using t 30. What is an execution frame? What is an activation record? What is contained in it? 31. Write a recursive Java method that computes the factorial of a number 2. Linear search may require up to comparisons while binary search will only require roughly comparisons 33. Sort sorts a list of values by repetitively putting a particular value into its final, sorted,...

  • 1. [5 marks Show the following hold using the definition of Big Oh: a) 2 mark...

    1. [5 marks Show the following hold using the definition of Big Oh: a) 2 mark 1729 is O(1) b) 3 marks 2n2-4n -3 is O(n2) 2. [3 marks] Using the definition of Big-Oh, prove that 2n2(n 1) is not O(n2) 3. 6 marks Let f(n),g(n), h(n) be complexity functions. Using the definition of Big-Oh, prove the following two claims a) 3 marks Let k be a positive real constant and f(n) is O(g(n)), then k f(n) is O(g(n)) b)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT