CSI Quiz 1

¡Supera tus tareas y exámenes ahora con Quizwiz!

The upper bound of an algorithm with best case runtime T(N)=3N+16 and worst case runtime T(N)=4N2+10N+5 is _____.

19N2

If the Java linearSearch() method is called to search an array of 32 numbers, then at most _____ array numbers are compared against the search key.

32

Given a list (0, 1, 1, 2, 3, 5, 8, 13, 17), the binary search algorithm calls BinarySearch(list, 0, 8, 3). What is the index of the middle element?

4

Which is an abstract data type (ADT)?

A list

Which of the following statements is true with reference to an algorithm's runtime?

A single algorithm can execute more quickly on a faster processor.

Which of the following is an example of constant time O(1)?

Accessing an element of an array

Which of the following is correct for a list ADT?

An element can be found and removed from the end of the list.

Which explanation matches the following runtime complexity? T(N)=k+T(N−1)

Every time the function is called, k operations are done, and the recursive call lowers N by 1.

Which of the following is a constant time operation?

Finding the sum of two numbers input by the user

Which of the following statements is true with reference to searching?

Linear search will compare all elements if the search key is not present

Which of the following is an example of a recursive function?

MySalaryCalulator(tempSal) { if (tempSal <= 500) return -1 else MySalaryCalculator(tempSal - 500) }

The Big O notation of the algorithm 7+12N+3N2 is _____.

N2

The Big O notation for an algorithm with exactly 50 constant time operations is _____.

O(1)

The best case runtime complexity of an algorithm that searches an array of size N is _____.

O(1)

What is the runtime complexity notation for the following algorithm? LowNum(listOfAgeGroups, listSize, myAge) { for (ctr = 0; ctr < listSize; ++ctr) { if (listOfAgeGroups[ctr] == myAge) return ctr } } }

O(N)

What is the Big O notation for a recursive function with a runtime complexity of T(N)=5N+T(N−1)?

O(N2)

What is the Big O notation for the following algorithm? ctr = 0 while (ctr < N) { myAge = ctr val = ctr + 1 while (val < N) { if (ageOfPeople[val] < ageOfPeople[myAge]) myAge = val ++val } tempList = ageOfPeople[ctr] ageOfPeople [ctr] = ageOfPeople [myAge] ageOfPeople [myAge] = tempList ++ctr }

O(N2)

The Big O notation of the composite function 5N3+O(N2) is _____.

O(N3+N2) O(N3) O(N5)

The best case runtime complexity of an algorithm that searches an array of size N is _____.

O(N−1) O(N/2) O(1)

What is the space complexity of the algorithm? ArithmeticSeries(list, listSize) { i = 0 arithmeticSum = 0 while (i < listSize) { arithmeticSum = arithmeticSum + list[i] i = i + 1 } return arithmeticSum }

S(N) = N S(N) = N + k S(N) = N * k

Identify the notation for algorithm complexity that has a positive constant c for all T(N)≥c*f(N).

T(N)=Ω(f(N))

Which of the following statements is correct?

The queue ADT supports the insertion and deletion of items at the front and the back. The list ADT supports the printing of the list contents but the queue ADT does not. The queue ADT supports the printing of the list contents but the list ADT does not.

The process of providing only the essentials and hiding the details is known as _____.

abstraction

The following algorithm is an example of _____. def MyMath(num) if num <= 1 return num return MyMath(num - 2) + MyMath(num - 1)

an exponential runtime complexity

Which function best represents the number of operations in the worst-case? for (i = 0; i < N; ++i) { if (numbers[i] % 2 == 1) factor = 2.5 }

f(N)=5N+2

Which function best represents the number of operations in the worst-case? for (i = 0; i < N; ++i) { if (numbers[i] % 2 == 1) factor = 2.5 }

f(N)=5N+2 f(N)=6N2 f(N)=8N2+4

ADTs allow programmers to _____

focus on higher-level operations as per a program's needs

Complexity analysis helps in avoiding algorithms with _____.

high memory usage

Given the following code for generating the Fibonacci series for N numbers, which XXX would replace the missing statement? FibonacciNumber(N) { XXX return 0 else if (N == 1) return 1 else return FibonacciNumber(N - 1) + FibonacciNumber(N - 2) }

if (N == 0)

Which XXX base case completes the algorithm to count the number of occurrences of a value in a list of numbers? CountOccurrences(numbers, numbersLength, value, startIndex) { XXX if (numbers[startIndex] == value) return 1 + CountOccurrences(numbers, numbersLength, value, startIndex + 1) else return CountOccurrences(numbers, numbersLength, value, startIndex + 1)

if (startIndex >= numbersLength) return 0

Given a list (0, 1, 1, 2, 3, 5, 8, 13, 17) the binary search algorithm calls BinarySearch(list, 0, 8, 5). What will the low and high argument values be for the second recursive call?

low = 5, high = 8

Which XXX completes the Java linearSearch method? int linearSearch(int[] numbers, int key) { for (int i = 0; i < numbers.length; i++) { if (numbers[i] == key) { XXX } } return -1; // not found }

return i;

In a recursive function, the base case _____ the function.

terminates

The worst-case runtime of an algorithm is _____ number of steps taken to execute a program.

the maximum

Which XXX completes the binary search algorithm? BinarySearch(numbers, numbersSize, key) { mid = 0 low = 0 high = numbersSize - 1 XXX { mid = (high + low) / 2 if (numbers[mid] < key) { low = mid + 1 } else if (numbers[mid] > key) { high = mid - 1 } else { return mid } } return -1 }

while (high >= low)


Conjuntos de estudio relacionados

psyc quiz practice history and methodology

View Set

What effect does the food we eat have on our health?

View Set

NSCI 225 exam #1 poll everywhere

View Set

Chapter 2 - Conceptual Framework for Financial Reporting

View Set

Chapter 16 Business Law (Third Parties to Contracts)

View Set

CORRECT Social Psych Final Multiple Choice

View Set

Ch. 1: What is Health Psychology?

View Set