Algorithms Exam 1 MC

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Pick the word or phrase below that best describes the class of algorithms that insertion sort belongs to. (a) incremental (b) divide and conquer (c) dynamic programming (d) branch and bound (e) backtracking (f) probabilistic (g) genetic (h) None of the options above apply

a

The running time of the Partition algorithm explained in the second video, where N is the size of the input array, is: https://tinyurl.com/yc567s3e (a) ϴ(N) (b) ϴ(N log N) (c) ϴ(N^2) (d) ϴ(N^2 log N) (e) ϴ(N^3) (f) None of the options above

a

[True/False] A recurrence does NOT have to be an equation (i.e., an equality). (a) True (b) False

a

[True/False] Any exponential function with a base strictly greater than 1 grows faster than any polynomial function. (a) True (b) False

a

[True/False] Dynamic-programming algorithms trade off running time for memory consumption. (a) True (b) False

a

[True/False] If counting sort assumes that each one of the n input elements is an integer in the range 0 to k for some integer k = O(log n), then counting sort runs in linear time. (a) True (b) False

a

[True/False] In the Volatile Chemical Corporation example, it is possible to maximize one's profit even when not buying at the lowest price and not selling at the highest price. (a) True (b) False

a

[True/False] In the aggregate analysis method, all operations in a sequence, regardless of their type, are assigned the same amortized cost. (a) True (b) False

a

[True/False] In the divide-and-conquer algorithm for the inversion-counting problem, the combine step must count the number of split inversions. https://bit.ly/2OLgQkz (a) True (b) False

a

[True/False] In the stack example, the value of the potential function is the number of objects currently in the stack. (a) True (b) False

a

[True/False] Proving the partial correctness of an iterative algorithm using a loop invariant relies on induction. (a) True (b) False

a

[True/False] The Partition algorithm that takes up the bulk of the second video is iterative and works in place. https://tinyurl.com/yc567s3e (a) True (b) False

a

[True/False] The quicksort algorithm described in our textbook has two base cases, namely when N=0 and N=1. (a) True (b) False

a

Select all (and only) the names of the algorithms below (if any) that are comparison sorts. (a) insertion sort (b) heapsort (c) merge sort (d) counting sort (e) bucket sort (f) quicksort

abcf

Select all (and only) the true statements below. (a) Both divide-and-conquer and dynamic-programming algorithms solve smaller versions of the original problem. (b) Both divide-and-conquer and dynamic-programming algorithms compute their answer by combining the answers to smaller subproblems. (c) Both divide-and-conquer and dynamic-programming algorithms are always implemented using recursion. (d) Both divide-and-conquer and dynamic-programming algorithms (efficiently) solve disjoint subproblems. (e) Both divide-and-conquer and dynamic-programming algorithms (efficiently) solve overlapping subproblems. (f) Only dynamic-programming algorithms (efficiently) solve overlapping subproblems. (g) Only divide-and-conquer algorithms (efficiently) solve overlapping subproblems.

abf

Select all (and only) the names of the parts that we must prove, according to Section 2.1, when using a loop invariant to prove the correctness of an algorithm. (a) Maintenance (b) Invariance (c) Termination (d) Determinism (e) Finiteness (f) Initialization

acf

Select all (and only) the names of the recurrence-solving methods that are listed in the introduction to today's reading assignment. (a) the recursion-tree method (b) the simplex method (c) the inductive-graph method (d) the master method (e) the associative method (f) the asymptotic method (g) the substitution method

adg

Select all (and only) the recurrences below whose structure matches the structural requirements for the master theorem. (a) T(N) = N LOG N + 8T(N/2) (b) T(N) = T(N-1) + T(N-2) (c) T(N) = T(N/2) + 4T(N/4) (d) T(N) = 4T(N-1) + N (e) T(N) = T(N/4) + N^2

ae

[Fill-in-the-blank question] In the recurrence characterizing the running time of the implemented algorithm below, the value of b is __________________. Requirement: Your answer MUST be a numerical value written as a decimal with EXACTLY two digits after the period (e.g., 1.00 or 0.50), not as an integer or fraction (e.g., 1 or 1/2). static int f(int n) { if (n == 0) { return 1; } int j = 0; for (int i = 1; i < n; i++) { j += 2 * i; } int result = f(5 * n / 4) + f(5 * n / 4); return j + result; }

0.80

Determine the recurrence for the implemented algorithm shown below. Which case of the master theorem does it fall under? static int f(int n) { if (n == 0) { return 1; } int j = 0; for (int i = 1; i < n; i++) { j += i; } int result = f(n / 2) + f(n / 2); return j + result; } (a) case 1 (b) case 2 (c) case 3 (d) The recurrence falls in the gap between cases 1 and 2. (e) The recurrence falls in the gap between cases 2 and 3. (f) The recurrence would fall into case 3 except that the regularity condition is not satisfied by this recurrence. (g) The recurrence does not have the required structure for the master theorem to apply.

b

How many cases is the master theorem broken into? (a) 2 cases (b) 3 cases (c) 4 cases (d) 5 cases (e) more than 5 cases (f) The master theorem is NOT broken down into multiple cases.

b

In counting sort, once n and k are fixed, then, just before the last loop starts (that is, just when the input elements are about to be copied into the output array B), the value of the last element of the C array is always equal to ... (a) k (b) n (c) the largest value in the input array (d) the smallest value in the input array (e) the last value in the input array (f) none of the options above

b

The running time of the divide-and-conquer approach to the maximum-subarray problem, where N is the size of the input array, is: (a) ϴ(N) (b) ϴ(N log N) (c) ϴ(N^2) (d) ϴ(N^2 log N) (e) ϴ(N^3) (f) None of the options above

b

[True/False] Any positive polynomial function grows slower than any polylogarithmic function. (a) True (b) False

b

[True/False] Consider the following implemented algorithm: static int f(int n) { if (n == 0) { return 1; } int j = 0; for (int i = 1; i < n; i++) { j += i; } int result = f(n / 2) + f(n / 2); // line A return j + result; } If ONLY line A above were replaced with the line: int result = 2 * f(n / 2); // modified line A then the recurrence characterizing the actual work of this modified program and the recurrence characterizing the actual work of the original program (shown above) would fall under the SAME case of the master theorem. (a) True (b) False

b

[True/False] If computers were infinitely fast and computer memory were free, you would not have any reason to study algorithms. (a) True (b) False

b

[True/False] If the partition function always produces a 99-to-1 proportional split, then the running time of quicksort is Θ(N^2). (a) True (b) False

b

[True/False] In the decision tree model of sorting algorithms, leaf nodes correspond to arrays with 0 or 1 element. (a) True (b) False

b

[True/False] In the quicksort algorithm, the running time of the third step (i.e., the combine step) is Θ(N) if N is the length of the input array. (a) True (b) False

b

[True/False] In the worst case, the quicksort algorithm has a running time of Θ(N^2log N). (a) True (b) False

b

[True/False] The formal definition of o(g(n)) (i.e., little-o notation) is: { f(n) : there exist positive constants c and n_0 such that 0 ≤ f(n) < c*g(n) for all n ≥ n_0 } (a) True (b) False

b

[True/False] The master theorem is a general method that applies to all divide-and-conquer algorithms. (a) True (b) False

b

[True/False] The proof by induction given in the third video for the correctness of Quicksort may not work if the pivot is chosen using another method than the one described in these videos. https://tinyurl.com/yc567s3e (a) True (b) False

b

[True/False] When applying the potential method to a data structure (e.g., a stack), the potential function applies to each individual element of the data structure (e.g., to each individual object in the stack), not to the entire data structure. (a) True (b) False

b

[True/False] When performing a sequence of different operations with varying costs, an amortized analysis computes the average performance of each operation in the worst case based on the cost and the probability of each type of operation. (a) True (b) False

b

[True/False] When talking about the asymptotic efficiency of algorithms, the term asymptotic means that our analysis is approximate in that it only takes into account the dominant term. (a) True (b) False

b

Select all (and only) the true statements below, if any. (a) If f(n) = O(g(n)) (big-O notation), then g(n) is an asymptotically tight upper bound for f(n). (b) If f(n) = ϴ(g(n)) (big-theta notation), then g(n) is an asymptotically tight upper bound for f(n). (c) If f(n) = ϴ(g(n)) (big-theta notation), then g(n) is an asymptotically tight lower bound for f(n). (d) If f(n) = O(g(n)) (big-O notation), then g(n) = o(f(n)) (little-o notation). (e) If f(n) = o(g(n)) (little-o notation), then g(n) = ω(f(n)) (little-omega notation). (f) If f(n) = ϴ(g(n)) (big-theta notation), then f(n) = O(g(n)) (big-O notation).

bcef

Counting sort is ... (a) neither in-place nor stable. (b) in-place but not stable. (c) stable but not in-place. (d) both stable and in-place.

c

Pick the option below that best describes the motivation for using a loop invariant. (a) to estimate the running time of an algorithm (b) to estimate the average-case running time of an algorithm (c) to analyze the correctness of an algorithm (d) to estimate the memory usage of an algorithm (e) to estimate the memory usage of an algorithm in the worst case (f) None of the options above apply

c

The running time of the brute-force approach to the maximum-subarray problem, where N is the size of the input array, is: (a) ϴ(N) (b) o(N^2) [note: this is a lowercase o] (c) Ω(N^2) (d) ω(N^3) (e) None of the options above

c

[True/False] The statement Q(n): j_n = i_n + y is a loop invariant for the WHILE loop in the pseudocode for the definition of function f shown below. f(nonnegative integer x, nonnegative integer y) // Local variables: integers i and j i = 0 j = 0 while i != x do j = j + y i = i + 1 end while return j end function f (a) True (b) False because in should not appear on the right-hand side of the invariant's equality (c) False for another reason

c

_______________ is the name of the third step in the divide-and-conquer algorithmic paradigm.

combine

How many inversions are there in the following array? 1 3 5 2 4 6 https://bit.ly/2OLgQkz (a) 0 (b) 1 (c) 2 (d) 3 (e) 4 (f) 5 (g) 15 (h) none of the options above

d

The running time of MULTIPOP(S,k) on a stack S containing s objects is ... (a) k (b) s (c) sk (d) min(s,k) (e) max(s,k) (f) s+k (g) none of the options above

d

What is the running time of the brute-force algorithm for the inversion-counting problem? https://bit.ly/2OLgQkz (a) ϴ(log N) (b) ϴ(N) (c) ϴ(N log N) (d) ϴ(N^2) (e) ϴ(N^3) (f) none of the options above

d

What is the value of the potential function in the binary counter example? (a) the number of bits in (i.e, the width of) the counter (b) the current value of the counter (c) the number of 0s in the counter (d) the number of 1s in the counter (e) the number of 0s to the left of the rightmost 1 in the counter (f) the number of 1s to the left of the rightmost 0 in the counter (g) none of the options above

d

Which one of the following collections of inequalities hold for all real numbers x? (a) x - 1 < ⌊x⌋ < x < ⌈x⌉ < x + 1 (b) x - 1 < ⌈x⌉ ≤ x ≤ ⌊x⌋ < x + 1 (c) x - 1 ≤ ⌊x⌋ < x < ⌈x⌉ ≤ x + 1 (d) x - 1 < ⌊x⌋ ≤ x ≤ ⌈x⌉ < x + 1 (e) x - 1 < ⌊x⌋ - 1 ≤ x ≤ ⌈x⌉ + 1 < x + 1 (f) None of the options above is true

d

How many iterations of its loop does the partition function perform when its input array has size N = r - p + 1? (a) 1 (b) 2 (c) N/2 (approximately) (d) log N (approximately) (e) N-1 (f) N (g) the answer varies based on the actual elements in the input array

e

If N is the total number of nodes in the decision tree for a comparison sort with a 4-element input array, then ... (a) N < 4 (b) N = 4 (c) 4 < N < 16 (d) N = 16 (e) 16 < N < 25 (f) 24 < N

f

In the randomized version of quicksort described in section 7.3 of our textbook, randomization is achieved by ... (a) ... randomly permuting the entire input array. (b) ... swapping two randomly selected elements in the input array. (c) ... swapping the first and last elements in the input array. (d) ... randomly permuting the left half of the input array. (e) ... randomly permuting the right half of the input array. (f) ... none of the techniques listed above.

f

[Fill-in-the-blank question] A problem with several possible solutions of different values for which a correct solution has the minimum or maximum value is called a(n) _________________________________ problem.

optimization


Set pelajaran terkait

PERS1301 Ch. 7: Performance Management

View Set

A&P Lecture Test 1 (Chapter 2: Chemistry)

View Set

CLU HS323 - Chp 7 Quiz (Variable Life & Variable Universal Insurance)

View Set

ABG, R/F, ARDS, Mechanical Ventilation test prep

View Set