Quiz 4

Ace your homework & exams now with Quizwiz!

In which of the following functions g(x), x^3 is NOT O (g(x))? a) g(x) = x^2 b) g(x) = x^2 + x^3 c) g(x) = x^3 d) g(x) = x^2 + x^4

a) g(x) = x^2

What is the purpose of the algorithm below? Input s, n Output outval myfunction(s, n) { outval = s1 for i= 2 to n if (si < outval) then outval = si return outval } a)The algorithm finds the smallest value in the list b) The algorithm finds the largest value in the list c)The algorithm finds the first value in the list d)The algorithm finds the last value in the list

a)The algorithm finds the smallest value in the list

Which of the following is correct to characterize the rate of growth of the function below? f( n ) = 7(log log n) + 3(log n) + 12n a)f = Θ( n ) b)f = Θ(n3) c)f = Θ(3n) d)f = Θ(2n8) e) f = Θ(n8)

a)f = Θ( n )

Simplify the recurrence relation below as much as possible. The explicit formula for the function should have the same asymptotic growth as the original recurrence relation. Which of the following answers is correct? T(n)= 3 * T (|_ n/2 _|)+18 a) T(n)=3*T(n)+Θ(n) b) T(n)=3*T(n/2)+Θ(1) c) T(n)=T(n/2)+Θ(1) d)T(n)=T(n-1)+Θ(1)

b) T(n)=3*T(n/2)+Θ(1)

A palindrome is a string that reads the same forward and backward. Which of the following algorithms can be used for determining whether a string of n characters is a palindrome? a) procedure palindromecheck (a1, a2, ...an : string) answer ≔ true for i ≔1 to n if ai ≠ an+1−i then answer ≔ false return answer b) procedure palindromecheck (a1, a2, ...an : string) answer ≔ true for i ≔1 to ⌊n/2⌋ if ai ≠ an+1−i then answer ≔ false return answer c) procedure palindromecheck (a1, a2,...an : string) answer ≔ false for i ≔1 to ⌊n/2⌋ if ai ≠ an+1−i then answer ≔ true return answer d) procedure palindromecheck (a1, a2, ...an : string) answer ≔ true for i ≔1 to ⌊n/2⌋ if ai ≠ an+1 then answer ≔ false return answer

b) procedure palindromecheck (a1, a2, ...an : string) answer ≔ true for i ≔1 to ⌊n/2⌋ if ai ≠ an+1−i then answer ≔ false return answer

Consider an algorithm that uses only assignment statements that replaces the hextuple (u, v, w, x, y, z) with(v, w, x, y, z, u). What is the minimum number of assignment statements needed? a)8 b)7 c)6 d)5

b)7

How many times is the variable count updated inside the loop in the pseudocode fragment below? count = 0 For i = 1 to 3 For j = i+1 to 4 count := count + (j - i) End-for End-for a) 0 b) 12 c) 6 d) 10

c) 6

The algorithm given below is a recursive algorithm to compute the nth Fibonacci number. Which of the following relations is correct to describe the asymptotic complexity of the algorithm as a function of n, the value of the input integer? RecursiveFibonacci(n) If (n = 0), Return( 1 ) If (n = 1), Return( 1 ) f := RecursiveFibonacci(n-1) + RecursiveFibonacci(n-2) Return( f ) a) T(n)=T(n-1)+T(n-2) b) T(n)=T(n-1)+T(n-2)+Θ(n) c) T(n)=T(n-1)+T(n-2)+Θ(1) d)T(n)=T(n-1)+Θ(1)

c) T(n)=T(n-1)+T(n-2)+Θ(1)

The pseudo-code below gives an algorithm to add two non-negative integers, m and n. Select the recurrence relation that describes the complexity of the algorithm, as a function of n, the second input variable. The running time is independent of m, the first input variable. Add(m, n) If (n = 0), Return(m) y := Add(m, n-1) Return(y + 1) a) T(n)=T(n/2)+Θ(n) b) T(n)=T(n/2)+Θ(1) c) T(n)=T(n-1)+Θ(1) d)T(n)=T(n-1)+Θ(n)

c) T(n)=T(n-1)+Θ(1)

Select the function that is not Ω(n^2) a) n! b) n log n + 3n^2 c) n log n + log log n d) 2^n

c) n log n + log log n

What is the purpose of the algorithm below? myfunction(s, n) { mynum = a mynum_pl = 1 for i= 2 to n if (si < mynum) { outval = si mynum_pl = i } return mynum_pl } a) The algorithm finds the largest element in the list. b) The algorithm finds the position of the largest element in the list. c) The algorithm finds the smallest element in the list. d) The algorithm finds the position of the smallest element in the list.

d) The algorithm finds the position of the smallest element in the list.

To establish a big-O relationship, find witnesses C and k such that | f(x) |≤ C | g(x) | whenever x>k. Find the least integer n such that f (x) is O (x^n) for the function f (x) = 3x^5 + (log x)^4. a) n = 4 with witnesses C = 4 and k = 1 b) n = 5 with witnesses C = 4 and k = 0 c) n = 4 with witnesses C = 4 and k = 0 d) n = 5 with witnesses C = 4 and k = 1

d) n = 5 with witnesses C = 4 and k = 1

Which of the following is correct to characterize the rate of growth of the function below? f( n ) = 2^n + 3^n a)f = Θ(2n^8) b) f = Θ( n ) c) f = Θ(n^3) d) f = Θ(n^8) e) f = Θ(3^n)

e) f = Θ(3^n)

What is the rate of growth of the function below? f ( n ) = n^8 + 3n - 4 a) f = Θ(n ) b) f = Θ(3^n) c) f = Θ(n^3) d) f = Θ(8^n) e) f = Θ(n^8)

e) f = Θ(n^8)


Related study sets

Quiz: Administering an Intradermal Injection

View Set

WHAPM Midterm Unit 0 and 1 Questions

View Set

Chatper 9 Physical Disorders and Health Psychology

View Set

Prep U Practice Questions (Elimination)

View Set