Analysis of Algorithms test
Use recursion tree to solve the recurrence T(n) = 3T(n-3) + 1 The value in the first-level (root) node is:
1
Use recursion tree to solve the recurrence T(n) = T(n/2) + n^2 The number of branches coming out of each internal node is:
1
Use recursion tree to solve the recurrence T(n) = T(n/2) + n^2 The number of nodes on the second level is:
1
Use recursion tree to solve the recurrence T(n) = T(n/2) + n^2 The number of nodes on the third level is:
1
Suppose that you have an array of n unique numbers in random order, and you are to find the smallest number. Order the following options from the fastest to the slowest by their worst-case running time.
1. Visit the array from beginning to end and keep track of the smallest element seen so far. 2. Build a min heap (where the smallest element is at the top) and return the first element. 3. Use merge sort to sort the array and return the first element. 4. Use RAND-SELECT to identify and report the 1-st order statistic.
Radix sort would still be able to sort correctly if the underlying sort algorithm is quick sort instead of counting sort.
False
True or False: 3^n = O(2^n)
False
True or False: log(n!) = Omega(n^2)
False
True or False: logn = Theta(loglogn)
False
True or False: n + sqrt(n) = Theta(n*sqrt(n))
False
True or False: n / logn = Theta(n)
False
True or False: n^2 + nlogn = O(nlogn)
False
True or False: n^3 = O(n)
False
True or False: nlog(n^2) = Theta(n^2 log(n))
False
True or False: counting sort is a stable and in-place sorting algorithm.
False
True or false: Quick sort runs in linear time for an already sorted array.
False
True or false: The average-case running time of the non-ranomized quick sort is worse than the average-case running time of the randomized quick sort.
False
True or false: The worst-case running time of randomized quick sort is Theta (nlogn).
False
True or false: buildHeap (8-heap.ppt) takes Theta(n logn) time.
False
True or false: finding median from an unsorted array using the RAND-SELECT algorithm (10-OS.ppt) takes Theta(n) time in the worst case.
False
True or false: the worst-case running time of heap sort is the same as the worst-case running time of counting sort.
False
BuildHeap Time complexity
O(n)
True or False: 2n + n / logn = Omega (log n)
True
True or False: log2(n) = Omega (log10 (n))
True
True or False: n + logn = Theta(n)
True
True or False: n + nlogn = O(nlogn)
True
True or False: n / logn = Omega (log n)
True
True or False: n^0.1 = Omega (log n)
True
True or False: n^2 = O(n^3)
True
True or false: using the worst-case linear-time SELECT algorithm (10-OS.ppt, page 13) to select the median as pivot for quick sort, the worst-case running time of quick sort becomes of Theta(nlogn).
True
Use recursion tree to solve the recurrence T(n) = 2T(n/2) + n The height of the tree is (including the base if it is a logarithm):
log2(n)
Use recursion tree to solve the recurrence T(n) = T(n/2) + n^2 The height of the tree is (including the base if it is a logarithm):
log2(n)
Use recursion tree to solve the recurrence T(n) = T(n/2) + T(n/3) + n The height of the tree is (including the base if it is a logarithm) <= ? and >= ?
log2(n), log3(n)
Use recursion tree to solve the recurrence T(n) = 2T(n/2) + n The sum of the values in the third-level nodes is:
n
Use recursion tree to solve the recurrence T(n) = 2T(n/2) + n The value in the first-level (root) node is:
n
Use recursion tree to solve the recurrence T(n) = T(n/2) + T(n/3) + n The sum of the values in the whole tree is in: Theta(?)
n
Use recursion tree to solve the recurrence T(n) = T(n/2) + T(n/3) + n The value in the first-level (root) node is:
n
Use recursion tree to solve the recurrence T(n) = 3T(n-3) + 1 The height of the tree is (including the base if it is a logarithm):
n/3
Use recursion tree to solve the recurrence T(n) = T(n/2) + n^2 The sum of the values in the whole tree is in: Theta(?)
n^2
Use recursion tree to solve the recurrence T(n) = T(n/2) + n^2 The value in the first-level (root) node is:
n^2
Use recursion tree to solve the recurrence T(n) = T(n/2) + n^2 The sum of the values in the third-level nodes is:
n^2/16
Use recursion tree to solve the recurrence T(n) = T(n/2) + n^2 The sum of the values in the second-level nodes is:
n^2/4
Use recursion tree to solve the recurrence T(n) = 2T(n/2) + n The sum of the values in the whole tree is in: Theta(?)
nlogn
HeapExtractMax time complexity
O(logn)
HeapInsert
O(logn)
Heapify time complexity
O(logn)
Use recursion tree to solve the recurrence T(n) = 2T(n/2) + n The number of branches coming out of each internal node is:
2
Use recursion tree to solve the recurrence T(n) = 2T(n/2) + n The number of nodes on the second level is:
2
Use recursion tree to solve the recurrence T(n) = T(n/2) + T(n/3) + n The number of branches coming out of each internal node is:
2
Use recursion tree to solve the recurrence T(n) = T(n/2) + T(n/3) + n The number of nodes on the second level is:
2
Use recursion tree to solve the recurrence T(n) = T(n/2) + T(n/3) + n The sum of the values in the third-level nodes is:
25n/36
Use recursion tree to solve the recurrence T(n) = 3T(n-3) + 1 The number of branches coming out of each internal node is:
3
Use recursion tree to solve the recurrence T(n) = 3T(n-3) + 1 The number of nodes on the second level is:
3
Use recursion tree to solve the recurrence T(n) = 3T(n-3) + 1 The sum of the values in the second-level nodes is:
3
Use recursion tree to solve the recurrence T(n) = 3T(n-3) + 1 The sum of the values in the whole tree is in: Theta(?)
3^(n/3)
Use recursion tree to solve the recurrence T(n) = 2T(n/2) + n The number of nodes on the third level is:
4
Use recursion tree to solve the recurrence T(n) = T(n/2) + T(n/3) + n The number of nodes on the third level is:
4
Use recursion tree to solve the recurrence T(n) = T(n/2) + T(n/3) + n The sum of the values in the second-level nodes is:
5n/6
Use recursion tree to solve the recurrence T(n) = 3T(n-3) + 1 The number of nodes on the third level is:
9
Use recursion tree to solve the recurrence T(n) = 3T(n-3) + 1 The sum of the values in the third-level nodes is:
9
Insertion sort
Best Case: O(n) Avg Case: (n^2) inplace: yes Stable: yes
Heapsort Time complexity
Best/Worst/Average: O(nlogn) Stable: No In place: Yes
Merge Sort Time Complexity
Best/Worst/Average: O(nlogn) Stable: Yes In place: No
Counting sort
In place: No Stable: yes
Master Method answer case1, case2, case3, or NA T(n) = .5T(n/2) + nlogn
NA
Master Method answer case1, case2, case3, or NA T(n) = 3T(n/3) - n^2 + n
NA
Master Method answer case1, case2, case3, or NA T(n) = T(n/2) + n(2 - cosn)
NA
Master Method answer case1, case2, case3, or NA T(n) = T(n/3) + logn
NA
Master Method answer case1, case2, case3, or NA T(n) = nT(n/2) + n
NA
MeapMax time complexity
O(1)
HeapChangeKey
O(logn)
Radix sort
Stable: Yes In place: No
myAlg (A[1..n]) if (n == 1) return A[1] % 7 return (n*MyAlg(A[1..n-1])) % 11
T(n) = T(n-1) + 1
myAlg (A[1..n]) if (n == 1) return A[1] % 7 if (n == 2) return (A[1] + A[2]) % 7 m = floor (n/3) if (A[m] > A[m+1]) x = MyAlg(A[1..m]) elsex = MyAlg(A[m+1..n]) return x
T(n) = T(n/2) + 1
myAlg (A[1..n]) if (n == 1) return A[1] % 7 m = floor (n/2) if (A[m] > A[m+1]) x = MyAlg(A[1..m]) else x = MyAlg(A[m+1..n]) return x
T(n) = T(n/2) + 1
Quick sort Time complexity
Worst Case: O(n^2) Best Case: O(nLogn) Average Case: O(nLogn) Stable: No In place: Yes
Which of the following arrays represent a max heap? There may be multiple correct answers. [7, 5, 6] [6, 5, 6, 5, 6, 3, 4] [6, 7, 5] [6, 5, 6, 3, 4, 5, 6] [7, 6, 5, 4, 3, 2, 1] [7, 5, 6, 4, 2, 3]
[7, 5, 6] [6, 5, 6, 3, 4, 5, 6] [7, 6, 5, 4, 3, 2, 1] [7, 5, 6, 4, 2, 3]
Master Method answer case1, case2, case3, or NA T(n) = 3T(n/2) + n
case1
Master Method answer case1, case2, case3, or NA T(n) = 2T(n/2) + n^2
case3
Master Method answer case1, case2, case3, or NA T(n) = 2T(n/3) + sqrt(n)
case3
Master Method answer case1, case2, case3, or NA T(n) = 3.5T(n/2) + n^2
case3
Master Method answer case1, case2, case3, or NA T(n) = T(n/3) + n
case3
Master Method answer case1, case2, case3, or NA T(n) = T(n/3) + nlogn
case3