CS 201 Final Exam Test 1
What is the time complexity of the following program? Assume S1 is a statement that will be executed by the program. for (i = 1; i < N; i = i*2) for (j = 0; j < N; j++) S1;
O(NlogN)
Which of the following input gives the best performance with insertion sort? random array sorted array reverse sorted array none of the option
sorted array
Correct MergeSort algorithm:
MergeSort(myList, i, k) { j = 0; if (i < k) { j = (i + k) / 2; MergeSort(myList, i, j); MergeSort(myList, j+1, k); Merge(myList, i, j, k); } }
Which of the following is a stable sort? Mergesort Quicksort Heapsort None of the options
Mergesort
Which of the following sorts are asymptotically optimal comparison sorts? Quicksort and Insertion Heapsort and Quicksort Mergesort and Heapsort Mergesort and Quicksort
Mergesort and heapsort
The Big O notation of the algorithm that has a time complexity of 7 + 12N + 3N^2 is
N^2
The best case runtime complexity of an algorithm that searches an array of size N is
O(1)
Time complexity in increasing order of complexity?
O(1), (logN), O(N), O(NlogN), O(N^2)
What is the worst case time complexity for the search operation using a doubly linked list?
O(N)
What is the worst case time complexity of deleting a node from a singly linked list?
O(N)
What is the Big O notation for a recursive function with a runtime complexity of T(N) = 5N + T(N - 1)?
O(N^2)
The Big O notation of the composite function 5N^3 + O(N^2) is
O(N^3)
Given an array (27, 40, 15, 25, 10, 19, 30), what are the new partitioned array if the pivot is 25?
(10, 15, 19) and (27, 30, 40)
Given an array (62, 45, 29, 32, 25, 10, 75), what is the list after sorting by the unit digit (least significant digit)?
(10, 62, 32, 45, 25, 75, 29)
Identify the binary tree that satisfies the max-heap property.
a.
Which of the following input gives the best performance with merge sort? sorted array all of the options reverse sorted array none of the options
all of the options
Identify the constant time operation.
b.
Identify the new binary max-heap after inserting 60 in the following max heap. Binary tree with root node 96. 96's left child is 78 and right child is 68. 78's left child is 46 and right child is 55
b.
If you are given an array of strings of fixed length which of the following algorithms would you choose to sort the array in the shortest amount of time? a. counting sort b. radix sort c. bucket sort d. mergesort
b.
Turn the following array into a binary max-heap using the BUILD_HEAP operation. Array containing 7 elements: 21, 36, 85, 54, 60, 13, 90
b.
Identify the new array created after the BUILD_HEAP operation to create a max heap. Array containing 5 elements: 47, 25, 36, 60, 54 a. array containing 25, 36, 47, 54, 60 b. array containing 25, 47, 36, 60, 54 c. array containing 60, 54, 36, 25, 47 d. array containing 60, 54, 47, 36, 25
c.
Identify the non-constant time operation
d.
If you have a sorted array and you pick the middle element as the pivot element, then the time complexity of quicksort is: a. O(N) b. O(N^2) c. O(logN) d. O(NlogN)
d.
In order to use counting sort, which of the following input conditions must be true? a. numbers to be sorted are integers with d digits b. numbers to be sorted are values uniformly distributed over the interval [0,1) c. none of the options d. numbers to be sorted are integers in the range 0 to k
d.