TopHat Questions - Exam 2

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

What is the output in the last cout of the main function? int function(int); int main() { int x = 10; cout << function(x) << endl; return 0; } int function(int num) { cout << "VALUE OF NUM" << num << endl; if(num <= 0) { return 0; } else { return function(num-1) + num; } } NUMERIC ANSWER

55

The linear search function requires the list to be sorted in order from least to greatest. True or False.

False

What is the largest number of comparisons that would be required to search a 36,876 array with a binary search? WORD ANSWER

16

How many AVERAGE comparisons would be required to search a 36,876 array with a linear search? WORD ANSWER

18438

On average, with an array of 20,000 elements, how many comparisons will the linear search perform? (Assume the items being searched for are consistently found in the array.) A. 10,000 B. 20,000 C. N*20,000 D. 40,000

A. 10,000

The following is the pseudocode for which type of algorithm? For maxElement = each subscript in the array, from the last to the first For index = 0 To maxElement - 1 If array[index] > array[index + 1] swap array[index] with array[index + 1] End If End For End For A. Bubble sort B. Binary sort C. Bubble search D. Selection sort

A. Bubble sort

Which list is stored in descending order? A. G, B, A B. A, C, Z C. Q, R, S

A. G, B, A

The _______ of recursion is the number of times a recursive function calls itself. A. depth B. level C. breadth D. type

A. depth

Big O Notation for Space Complexity of Merge Sort is O(?). What should replace the question mark? A. n B. n ^ 2 C. log n D. n log n E. c^n F. wn G. w + n H. 1

A. n

What is the average runtime Big-O Notation for Bubble Sort? A. O(n) B. O(n^2) C. O(log n) D. O(2^n) E. O(n log n) F. O(1)

B. O(n^2)

Which of the following sort algorithms uses the least amount of space in memory to run? A. Merge sort B. Insertion sort C. Quick sort

B. Insertion sort

Which search algorithm is more efficient? A. Flipping B. Linear C. Binary D. Quadrupleary

B. binary

A recursive function is a function that calls _________. A. another function of a similar name but with a different parameter list B. itself C. another function multiple times in a loop D. "These pretzels are making me thirsty!"

B. itself

The following is the pseudocode for which type of algorithm? Set found to false Set position to -1 Set index to 0 While found is false and index < number of elements If list[index] is equal to search value found = true position = index End If Add 1 to index End While Return position A. linear sort B. linear search C. binary search D. selection sort

B. linear search

Big O Notation for BEST Runtime for Selection Sort is O(?). What should replace the question mark? A. n B. n ^ 2 C. log n D. n log n E. c^n F. wn G. w + n H. 1

B. n^2

Big O Notation for WORST Runtime for Bubble Sort is O(?). What should replace the question mark? A. n B. n ^ 2 C. log n D. n log n E. c^n F. wn G. w + n H. 1

B. n^2

Big O Notation for WORST Runtime for Insertion Sort is O(?). What should replace the question mark? A. n B. n ^ 2 C. log n D. n log n E. c^n F. wn G. w + n H. 1

B. n^2

Big O Notation for WORST Runtime for Quick Sort is O(?). What should replace the question mark? A. n B. n ^ 2 C. log n D. n log n E. c^n F. wn G. w + n H. 1

B. n^2

Big O Notation for WORST Runtime for Selection Sort is O(?). What should replace the question mark? A. n B. n ^ 2 C. log n D. n log n E. c^n F. wn G. w + n H. 1

B. n^2

With an array of 20,000 elements, what is the maximum number of comparisons the binary search will perform? A. 10,000 B. 14 C. 15 D. 20,000

C. 15

Which algorithm is an example of Linear Time Big-O Notation? A. Bubble sort B. Binary search C. Linear search D. Tide pods

C. Linear search

The following is the pseudocode for which type of algorithm? Set first to 0 Set last to the last subscript in the array Set found to false Set position to -1 While found is not true and first is less than or equal to last Set middle to the subscript halfway between array[first] and array[last] If array[middle] equals the desired value Set found to true Set position to middle Else If array[middle] is greater than the desired value Set last to middle - 1 Else Set first to middle + 1 End If End While Return position A. linear sort B. linear search C. binary search D. selection sort

C. binary search

Big O Notation for Space Complexity of Quick Sort is O(?). What should replace the question mark? A. n B. n ^ 2 C. log n D. n log n E. c^n F. wn G. w + n H. 1

C. log n

A linear search algorithm is also called a _________ search algorithm. A. sequin B. array-based C. sequential D. vector-based E. linked-list

C. sequential

Which algorithm is this? while (index < size && !found) { if (arr[index] == value) { found = true; position = index; } index++; } return position; A. Bubble sort B. Selection sort C. Binary search D. Linear search E. Radix sort F. Quick sort G. Merge sort H. Insertion sort

D. Linear search

Which of the following sort algorithms is the fastest in practice for most arrays/vectors/linked-lists? A. Bubble sort B. Quick sort C. Insertion sort D. Merge sort E. Selection sort

D. Merge sort

Determine Simplified Big-O 284 + 8N + 2N^2 A. O(284 + 8N + 2N^2) B. O(8N + 2N^2) C. O(2N^2) D. O(N^2) E. O(N)

D. O(N^2)

The following is the pseudocode for which type of algorithm? For start = each array subscript, from the first to the next-to-last minIndex = start minValue = array[start] For index = start + 1 To size - 1 If array[index] < minValue minValue = array[index] minIndex = index End If End For swap array[minIndex] with array[start] End For A. Bubble sort B. Binary sort C. Bubble search D. Selection sort

D. Selection Sort

A recursive function is designed to terminate when it reaches its ________. A. return statement B. closing curly brace C. last parameter D. base case

D. base case

Big O Notation for BEST Runtime for Merge Sort is O(?). What should replace the question mark? A. n B. n ^ 2 C. log n D. n log n E. c^n F. wn G. w + n H. 1

D. n log n

What is the average runtime Big-O Notation for Quick Sort? A. O(n) B. O(n^2) C. O(log n) D. O(2^n) E. O(n log n) F. O(1)

E. O(n log n)

Determine Simplified Big-O 8N^2 + 2N^3 A. O(8N^2 + 2N^3) B. O(10N^5) C. O(8N^2) D. O(N^2) E. O(2N^3) F. O(N^3)

F. O(N^3)

What is the average runtime Big-O Notation for Merge Sort? A. O(n) B. O(n^2) C. O(log n) D. O(2^n) E. O(n log n) F. O(1)

F. O(n log n)

Big O Notation for Space Complexity of Insertion Sort is O(?). What should replace the question mark? A. n B. n ^ 2 C. log n D. n log n E. c^n F. wn G. w + n H. 1

H. 1

Big O Notation for Space Complexity of Selection Sort is O(?). What should replace the question mark? A. n B. n ^ 2 C. log n D. n log n E. c^n F. wn G. w + n H. 1

H. 1

An _______ algorithm is one that finds a best combination of items by looking at ALL the possible combinations. WORD ANSWER

exhaustive

What is the expected output of the program below? int main() { string mystr = "Hello"; function(mystr, 0, mystr.size()); return 0; } void function(string str, int pos, int size) { if(pos < size) { function(str, pos+1, size); cout << str[pos]; } } WORD ANSWER

olleH

What is the average runtime Big-O Notation for Insertion Sort? A. O(n) B. O(n^2) C. O(log n) D. O(2^n) E. O(n log n) F. O(1)

B. O(n^2)

What is the average runtime Big-O Notation for Selection Sort? A. O(n) B. O(n^2) C. O(log n) D. O(2^n) E. O(n log n) F. O(1)

B. O(n^2)

The bubble sort is an easy way to arrange data in ascending order but it cannot arrange data in descending order. True or false

False

If you are using the bubble sort algorithm to sort an array in descending order, the smaller values move toward the end. True or False

True

Using recursive functions for math problems is common. TRUE OR FALSE

True


Conjuntos de estudio relacionados

Ch 24 - Urinary and Acid Base Balance

View Set

CIS463 (Chapter 9 and 10) and Quiz 2

View Set

Managerial Accounting SMartbook chapter 2

View Set

AP Chemistry Semester 1 Exam Review

View Set