Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Big-O analysis (worst case time complexity) I have the question and the answer, I just need an explanation on how they got the answers. .

Big-O analysis (worst case time complexity)
I have the question and the answer, I just need an explanation on how they got the answers.
.
.
the question (it has 3 parts: a,b, and c)
image text in transcribed
image text in transcribed
.
.
the answers:
image text in transcribed
a. Find the worst case runtime (big-O notation) for the following pseudo code which returns true if an integer n is prime, false if it is not prime. procedure isPrime(n) if n A[maxIndex] maxIndex=1 swap(Ali), A[maxIndex]) c. Find the worst case runtime (big-O notation) for BogoSort, pseudocode is given below: procedure BogoSort(array A) while not isinOrder(A): shuffle(A) shuffle() randomly reorders A. isinOrder() returns true if the list is in order, false otherwise. It has the following pseudocode: procedure isInOrder/array A. length(A) = n) for i in 0 to n-1 if Ali > Ali+11 return false a. Pseudocode which returns true if an integer n is prime, false if it is not prime: procedure is.Primern) if not takes a constant time so (1) return false takes a constant time so (1) else ifn 3 takes a constant time so I) return true takes a constant tinteso OVD) else takes a constant time se ONI) for i in 2 to sqrt() has a runtime of O(Vm) ifn%i- takes a constant time so O(1) return false takes a constant time so O(1) return true takes a constant time so (1) the worst case time complexity is o n of length: b. Pseudocode for SelectionSort algorithm. This algorithm sorts an array procedure Selection Sort(array a, length(A) - n) for i in Oton-2 takes a linear time so O(n) maxIndex takes a constant time so (1) forj in (i+1) to (n-1) takes a linear time so O(n) ifall > A[max Index) takes a constant time so (1) maxIndex - takes a constant time so (1) swap(Ali). A max Index takes a constant time so (1) The worst case time complexity is Oinn - O2) c. Pseudocode for BogoSort: procedure BogoSort (array A) while not isinOrder(A) takes a linear time so O(n) shuttleA) shuttles randomly and has many variations, there are nt variations for a numbers. shuffle randomly reorders A. isinOrder) returns true if the list is in order, false otherwise. It has the following pudocode procedure isinOrder(array A, length )n) for i in to n takes a linear time soon) if A[i]>Ai+1] takes a constant time so O(1) return false takes a constant time so (1) The worst case time complexity is On !)

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

Transactions On Large Scale Data And Knowledge Centered Systems X Special Issue On Database And Expert Systems Applications Lncs 8220

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2013th Edition

3642412203, 978-3642412202

More Books

Students also viewed these Databases questions

Question

3. An initial value (anchoring).

Answered: 1 week ago