M5
Select the best answer. Consider the pseudocode of InsertSort. For each value of j, the while loop in lines 5-7 runs always _______ time(s) assuming that A.length is n.
None
Select the best answer. Consider the pseudocode of InsertSort. This algorithm is used to sort the sequence A = (21, 11, 13, 9, 7, 3, 5, 16). When the for loop completes for j = _____, the sequence A will be (11, 9, 13, 21, 7, 3, 5, 16).
None
Select the best answer. Consider the pseudocode of InsertSort. This algorithm is used to sort the sequence A = (21, 11, 13, 9, 7, 3, 5, 16). When the for loop completes for j = _____, the sequence A will be (5, 7, 9, 11, 13, 21, 3, 16).
None
Select the best answer. We plan to use the Master Theorem to solve this recurrence relation: T(n) = 0.5T(n/2) + 1 / n. Using the Master theorem below, select the solution for the above recurrence relation. a.Θ(nlog2n)b.Θ(nlogn)c.Θ(n2)d.Θ(n)
None of these
Select the best answer. Consider the pseudocode of InsertSort. This algorithm is used to sort the sequence A = (21, 11, 13, 9, 7, 3, 5, 16). When the for loop completes for j = _____, the sequence A will be (3, 5, 7, 9, 11, 16, 21, 13). Insert Sort Code
None of these answers
Select the best answer. We plan to use the Master Theorem to solve this recurrence relation: T(n) = 7T(n/3) - n^2 . Using the Master theorem below, select the solution for the above recurrence relation. a.Θ(log2n)b.Θ(n2)c.Θ(nlog2n)d.Θ(n2log2n)
None of these answers
True or False. QuickSort is an in place algorithm.
T
Select the best answer. Consider the pseudocode of QuickSort. In the best case, the recurrence relation would be ____________.
T(n) = 2T(n/2) + Θ(n)
Check all that apply. This question is about the correctness of the Partition procedure that is at the heart of QuickSort. Below is the pseudocode of Partition. When the for loop (Lines 3-6) terminates, check all true statements that are true before Line 7 is executed.
The pivot is still at Index r.
Check all that apply. This question is about the correctness of the Partition procedure that is at the heart of QuickSort. Below is the pseudocode of Partition. When the Partition terminates, check all true statements that are true. QuickSort Code
The pivot x is placed between the two sets of smaller and greater elements.
True or False. InsertSort is an in place algorithm.
True
Check all that apply. The QuickSort algorithm is _______________.
a divide-and-conquer algorithm recursive
Select the best answer. Each letter is associated with a bound. a.Θ(n) b.Θ(n2 c.Θ(nlogn) d.Θ(log2n) The running time of InsertSort in the average case is the bound associated with the letter _______.
b
Check all that apply. Each letter is associated with a bound. a. Theta(n^2) b. Omega(n^2) c. Theta(n log n) d. O(n^2) The worst case running time of InsertSort belongs to the bound associated with the letter _______.
b,a,d
Select the best answer. Each letter is associated with a bound. a.Θ(n)b.Θ(n2)c.Θ(nlogn)d.Θ(log2n) The running time of QuickSort in the best case belongs the bound associated with the letter _______.
c
Check all that apply. Each letter is associated with a bound. a.Θ(n2) b.Θ(n) c.Ω(n) d.O(n) The best case running time of InsertSort belongs to the bound associated with the letter _______.
d,b,c
Check all that apply. This question is about the correctness of the Partition procedure that is at the heart of QuickSort. Below is the pseudocode of Partition. Check all loop invariants of the for loop (Lines 3-6).
if k = r, then A[k] = x if p ≤ k ≤ i, then A[k] ≤ x
Select the best answer. log (x/2) = _________________. Unless specified otherwise, log(n) is log base 2.
log x - log 2
Select the best answer. Consider the pseudocode of InsertSort. In the best case, the for loop statement (Line 1) executes ___________ comparisons.
n
Select the best answer. Consider the pseudocode of InsertSort. The for loopstatement (Line 1) executes always ___________ comparisons.
n
Select the best answer. Consider the pseudocode of Partition. The body of the for loop (Lines 3-6) is executed ___________ time(s) assuming that n is the input size (n= r - p + 1). QuickSort Code
n-1
Select the best answer. Consider the pseudocode of Partition. For each value of j from p to (r-1), the comparison (if A[j] ≤ x) is executed _____ time(s). QuickSort Code
one
Select the best answer. This question is about the correctness of the Partition procedure that is at the heart of QuickSort. Below is the pseudocode of Partition. Before the first iteration of the for loop (Lines 3-6), there are _____ items between Index (i+1) [included] and Index r [included].
r - p + 1
Select the best answer. Consider the pseudocode of QuickSort. The best case running time occurs when _______________.
the input is such that each recursive call produces equal subsequences.
Check all that apply. This question is about the correctness of the Partition procedure that is at the heart of QuickSort. Below is the pseudocode of Partition. Check all consequences in the for loop (Lines 3-6) when A[j] ≤ x.
the set of items less than or equal to x expands
Select the best answer. The space complexity of QuickSort is _______.
theta(n)
Select the best answer. Consider the pseudocode of Partition. This algorithm is used to partition the sequence A = (2,8,7,1,3,5,6,4). Partition will partition A into these three sets _____________________.
{2, 1, 3}, {4}, {5, 6, 7, 8}
Select the best answer. Consider the pseudocode of Partition. This algorithm is used to partition the sequence A = (2,8,7,1,3,5,6,4). Partition will partition A into these three sets _____________________. QuickSort Code
{2, 1, 3}, {4}, {5, 6, 7, 8}
Select the best answer. Consider the pseudocode of Partition. This algorithm is used to partition the sequence A = (2,8,7,1,4,5,6,3). Partition will partition A into these three sets _____________________.
{2, 1}, {3}, {8, 4, 5, 6, 7}
Select the best answer. Consider the pseudocode of Partition. This algorithm is used to partition the sequence A = (15, 2, 6, 4, 3, 7). Partition will partition A into these three sets _____________________. QuickSort Code
{2, 6, 4, 3}, {7}, {15}
Select the best answer. Consider the pseudocode of Partition. This algorithm is used to partition the sequence A = (5,15,7,3,8,10,12,6). Partition will partition A into these three sets _____________________. QuickSort Code
{5, 3}, {6}, {15, 8, 10, 12, 7}
Select the best answer. Consider the pseudocode of InsertSort. This algorithm is used to sort the sequence A = (15, 2, 6, 4, 3, 1, 5, 7). When the for loop completes for j = 7, the sequence A will be _________________.
(1, 2, 3, 4, 5, 6, 15, 7)
Select the best answer. Consider the pseudocode of InsertSort. This algorithm is used to sort the sequence A = (15, 2, 6, 4, 3, 1, 5, 7). When the for loop completes for j = 2, the sequence A will be _________________.
(2, 15, 6, 4, 3, 1, 5, 7)
Select the best answer. Consider the pseudocode of InsertSort. This algorithm is used to sort the sequence A = (15, 2, 6, 4, 3, 1, 5, 7). When the for loop completes for j = 5, the sequence A will be _________________. Insert Sort Code
(2, 3, 4, 6, 15, 1, 5, 7)
Select the best answer. Consider the pseudocode of InsertSort. In the best case, the body of the while loop (Lines 6-7) is executed ___________ time(s).
0
Fill in multiple blanks. We plan to use the Master Theorem to solve this recurrence relation: T(n) = T(n/2) + 2^n. Using the Master theorem below, identify/match the parameters a, b, f(n), and the case that applies. Based on the Master Theorem, a = , b= , f(n) = , and the case that applies is (Provide only the case number 1, 2, or 3. If no case applies, provide the number 7). If a number is a fraction x/y, enter "x/y". Do not try to compute x/y.
1, 2, 2^n, 3
Check all that apply. Consider the for loop (Lines 1-8) in the pseudocode of InsertSort. Check all loop invariants. InsortSort Code
1. i < j 2. the subarray A[1..j-1] consists of the elements originally in A[1..j-1], but in sorted order
Check all that apply. This question is about the correctness of the Partition procedure that is at the heart of QuickSort. Below is the pseudocode of Partition. Check the helpful loop invariants of the for loop (Lines 3-6). Helpful loop invariants are the invariants that help proving that Partition produces the desired result.
1. if p ≤ k ≤ i, then A[k] ≤ x 2. if i+1 ≤ k ≤ j-1, then A[k] > x
Check all that apply. Consider the pseudocode of QuickSort. The worst case running time occurs when _______________.
1. the input is already sorted in the desired order 2. the input is already sorted in the inverse of the desired order
Provide a numerical answer. Consider the Merge procedure. If we call Merge(A, 10, 19,25), the left subsequence L has __________ elements.
11
Select the best answer. log2 2^15= __________
15
Fill in multiple blanks. Consider the pseudocode of Partition. This algorithm is used to partition the sequence A = (15,7,3,8,10,20). After executing Partition , the sequence A will become: Index: 1, 2, 3, 4, 5, 6 Value:
15,7,3,8,10,20
Fill in multiple blanks. We plan to use the Master Theorem to solve this recurrence relation: T(n) = 16T(n/4) + n. Using the Master theorem below, identify/match the parameters a, b, f(n), and the case that applies. Based on the Master Theorem, a = , b= , f(n) = , and the case that applies is (Provide only the case number 1, 2, or 3. If no case applies, provide the number 7). If a number is a fraction x/y, enter "x/y". Do not try to compute x/y.
16,4,n,1
Select the best answer. At each call, Merge-Sort divides the sequence in _______ sequences.
2
Select the best answer. Consider the pseudocode of InsertSort. This algorithm is used to sort the sequence A = (21, 11, 13, 9, 7, 3, 5, 16). When the for loop completes for j = _____, the sequence A will be (11, 21, 13, 9, 7, 3, 5, 16).
2
Fill in multiple blanks. Consider the pseudocode of Partition. This algorithm is used to partition the sequence A = (15,7,3,8,10,2). After executing Partition , the sequence A will become: Index: 1, 2, 3, 4, 5, 6 Value:
2, 7, 3, 8, 10, 15
Fill in multiple blanks. Consider the pseudocode of Partition. This algorithm is used to partition the sequence A = (2,8,7,1,3,5). After executing Partition , the sequence A will become: Index
2,1,3,5,7,8
Fill in multiple blanks. Consider the pseudocode of Partition. This algorithm is used to partition the sequence A = (15, 2, 6, 4, 3, 7). After executing Partition , the sequence A will become:
2,6,3, 7, 15
Fill in multiple blanks. Consider the pseudocode of Partition. This algorithm is used to partition the sequence A = (15, 2, 6, 4, 3, 7). After executing Partition , the sequence A will become: Index: 1, 2, 3, 4, 5, 6 Value:
2,6,4,3,7,15
Fill in the blank. log10 1000= __________
3
Select the best answer. Consider the pseudocode of Partition. This algorithm is used to partition the sequence A = (2,8,7,1,4,5,6,3). Partition will return the index _______ (the index for the pivot). QuickSort Code
3
Select the best answer. Consider the following recurrence relation: Let c be 4, then T(1) = _____
4
Select the best answer. Consider the pseudocode of Partition. This algorithm is used to partition the sequence A = (2,8,7,1,3,5,6,4). Partition will take ___ as the pivot value.
4
Select the best answer. Consider the recurrence relation: T(n) = 2.T(n/2) + 4.n. John guesses that T(n) = 4.n.log(n). Substituting T(n/2) by the guess in the recurrence relation will yield T(n) = ______________. Unless specified otherwise, log(n) is log base 2.
4.n.log(n/2)+4.n
Select the best answer. Consider the pseudocode of Partition. This algorithm is used to partition the sequence A = (15, 2, 6, 4, 3, 7). Partition will return the index _______ (the index for the pivot).
5
Fill in multiple blanks. Consider the pseudocode of Partition. This algorithm is used to partition the sequence A = (5,15,7,3,8,10). After executing Partition , the sequence A will become: Index: 1, 2, 3, 4, 5, 6 Value:
5,7,3,8,10,15
Select the best answer. Consider the following recurrence relation: When developing the recurrence tree, the sum of the costs of all nodes at the third level ("third call") is ____________ when c = 5
5.n
Select the best answer. Consider the pseudocode of InsertSort. This algorithm is used to sort the sequence A = (21, 11, 13, 9, 7, 3, 5, 16). When the for loop completes for j = _____, the sequence A will be (3, 7, 9, 11, 13, 21, 5, 16).
6
Select the best answer. Consider the pseudocode of Partition. This algorithm is used to partition the sequence A = (5,15,7,3,8,10,12,6). Partition will take ___ as the pivot value.
6
Select the best answer. Consider the pseudocode of InsertSort. This algorithm is used to sort the sequence A = (21, 11, 13, 9, 7, 3, 5, 16). When the for loop completes for j = _____, the sequence A will be (3, 5, 7, 9, 11, 13, 21, 16). Insert Sort Code
7
Select the best answer. Consider the pseudocode of Partition. This algorithm is used to partition the sequence A = (15, 2, 6, 4, 3, 7). Partition will take ___ as the pivot value
7
True or False. The running time of QuickSort depends only on the input size.
False