Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Throughout this assignment, adopt the following notation: - AB denotes the concatenation of lists A and B (in this order), and is assumed to take

image text in transcribed

image text in transcribed

image text in transcribed

Throughout this assignment, adopt the following notation: - AB denotes the concatenation of lists A and B (in this order), and is assumed to take O(1) time to execute; - denotes the empty string; - len (s)0 denotes the length (number of characters) on string s, and is assumed to take O(1 ) time to obtain; - minpx(A[ab]) denotes the index (in range [ab]) of the smallest prime element from list A[ab], and is assumed to take linear time (i.e. O(n) where n=ba+1 ) to execute; - t1=a+(ba)/3 and t2=b(ba)/3 denote the indices at one third and two thirds the way from a to b, respectively; - pairsort (X,Y) denotes YX if integers X and Y are both prime and X>Y, otherwise it denotes XY. - is_prime (X) is a Boolean function that determines whether or not X is prime (that is, is_prime (X) is true if, and only if, the only positive integers divisors of X are 1 and X itself. - is_sqr(n) is a Boolean function that determines whether or not n is a perfect square (that is, is_sqr(n) is true if, and only if, n is an integer of form n=r2 for some integer r ). Consider the problem of sorting only the prime elements in a list of integers while keeping the composite ones unchanged in their original places: Sorttheprimeelementsonalist(SORTPRIMES)Input:Output:A[1n],alistofpositiveintegers.ListA[1n]suchthatA[i]=A[i]ifA[i]iscomposite,andA[i]A[j]forall1ijnsuchthatA[i]andA[j]arebothprime. APS(A[ab])=A,pairsort(A[a],A[b]),A,withA:=APS(A[at2])A[t2+1b],A:=A[at1]APS(A[t1+1b])A:=APS(A[at2])ifab;ifb=a+1ifb>a+1A[t2+1b] 4. (2+2 points) Using the same reduction as in the previous question, state a recurrence T(n) that expresses the worst case running time of the recursive algorithm corresponding to that reduction. From this recurrence, find a tight (Big-Theta) expression for T(n). Hint \#1: the Master Theorem may be the easiest solution here. Hint \#2: how many recursive calls are made, and how many elements are passed to them

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

What is conservative approach ?

Answered: 1 week ago

Question

What are the basic financial decisions ?

Answered: 1 week ago