CS323Exam

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which of the following versions of the Knapsack Problem can be solved (optimally) in polynomial time?

1. Fractional Knapsack Problem 2. 0/1 Knapsack Problem with integer knapsack capacity Fractional Knapsack Problem on n items can be solved in O(n) time, in addition to the time for the preliminary sort, with a greedy strategy. 0/1 Knapsack Problem with integer capacity W can be solved in O(nW) with a dynamic programming strategy. The 0/1 Knapsack Problem (with non-integer capacity) is an NP-Complete problem for which no deterministic polynomial-time algorithm is known.

What is the order of steps used in the greedy algorithm for the Fractional Knapsack Problem

1. Iterate through the items computing each's value per weight 2. Iterate through the quantities sorting in decreasing order 3. iterate through the items determining how much of each item to take First, we compute the ratios of value per weight, then sort by those ratios, finally using those ratios to determine how much of each to take.

Which of the following are always true of the LPS function/array as defined in class?

1. LPS​[i]​[i] = 1 2. LPS​[i]​[j]) = 0 for i > j

Which of the following are true of Dynamic Programming

1. Often used in optimization problems 2. Exhibits incremental computation

Which algorithms use the greedy strategy?

1. Prim's Minimum Spanning Tree algorithm 2. Kruskal's Minimum Spanning Tree algorithm 3. Huffman Coding 4. Dijkstra's Single-Source-Shortest-Path algorithm

What is LCS(8, 2) where X = ANALYSIS and Y = ALGORITHMS?

2 The LCS of ANALYSIS and AL is AL with length 2

As defined in class, what is the value of Fib(8)?

21 0 1 2 3 4 5 6 7 8 9 10 11 12 13 ... 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,...

Fibonacci Numbers - Recursive Implementation How many times is Fib(2) computed to arrive at Fib(5)?

3

Huffman Coding - Two Queues Assume the implementation of Huffman Coding that uses two queues, one with the original frequencies (O) and the other with the combined frequencies (C)? Where will the two minimums be found in forming the node labelled 65?

32 from O and 33 from C

Floyd's Algorithm: Example, Part IV Suppose that in a graph, there is no direct edge from vertex 1 to vertex 3. However, the following edges and weights do exist: 1 -> 2 (40); 2 -> 3 (30); 1 -> 4 (25); 4 -> 3 (35); 1 -> 5 (10); 5 -> 6 (15); 6 -> 7 (25). After the main loop is completely done, what is the value of dist​[1]​[3]?

50 After all intermediate vertices are considered, we now have our shortest path 1 to 5 (10) and 5 to 6 (15) and 6 -> 7 (25) for a total cost of dist​[1]​[3] = 50.

Floyd's Algorithm: Example, Part III Suppose that in a graph, there is no direct edge from vertex 1 to vertex 3. However, the following edges and weights do exist: 1 -> 2 (40); 2 -> 3 (30); 1 -> 4 (25); 4 -> 3 (35); 1 -> 5 (10); 5 -> 6 (15); 6 -> 7 (25). After the iteration of the main outer loop where k=2, what is the value of dist​[1]​[3]?

70 After intermediate vertex 2 is considered, we now have a shorter path from 1 to 2 (40) and 2 to 3 (30) with a total dost of dist​[1]​[3] = 70.

Floyd's Algorithm: dist[][] Which best describes the use of the array dist​[i]​[j] used in Floyd's algorithms

The cost of the path (total edge weight) from vertex i to vertex j

Time Complexity of Kruskal's Algorithm Which best describes the relative time complexities of the pre-sorting and main parts of algorithm?

The relationship depends on the sort and disjoint-set operations being used

Shortest Path Algorithms Match the algorithm name with the problem for which it is most commonly used.

Bellman-Ford <=> Single-Source Shortest Path Dijkstra <=> Single-Source Shortest Path Floyd <=> All-Pairs Shortest Path Warshall <=> Transitive Closure

Floyd's Algorithm: Example Part I Suppose that in a graph, there is no direct edge from vertex 1 to vertex 3. However, the following edges and weights do exist: 1 -> 2 (40); 2 -> 3 (30); 1 -> 4 (25); 4 -> 3 (35); 1 -> 5 (10); 5 -> 6 (15); 6 -> 7 (25). After the initialization loops but before the main loops, what is the value of dist​[1]​[3]?

INFINITY Since there is no direct edge from 1 to 3, after the Init Loop dist​[1]​[3] will be INFINITY (or some MAX-VALUE) to indicate that no direct edge exists.

Determining the degree of a vertex Which of the following degrees cannot be determined in time O(V)?

In-Degree of a vertex in a directed graph assuming an Adjacency Table

Dijkstra's Algorithm: basic implementation Using a Cost Matrix for the weighted graph and an array for Dist, with no additional data structures, which best describes the total time for Dijkstra's Algorithm

O(V^2)

Compression Rate What is the compression rate of a text? let T = original text and C = compressed text

len(T) / len(C)

What is the term for the hybrid approach which often combines top-down recursion with storing results for later reuse?

memoization

Floyd's Algorithm: pred[][] Which best describes the use of the array pred​[i]​[j] used in Floyd's algorithms

pred​[i]​[j] = pred​[k]​[j] where k is an intermediate vertex that helped achieve dist​[i]​[j]

Which function should be used to determine how many coins of denomination d should be used to make change for the remaining value v, assuming that the higher denominations of coins have already been tried and exhausted?

v // d (integer division)

Tree Graph Which is true of the relationship between the vertices and edges in a (undirected) Tree Graph

|E| = |V| - 1

Fibonacci Numbers - Recursive Implementation Time Which best approximates the time complexity of the recursive approach to computing Fibonacci numbers?

Θ(((1+√5)/2)^n)

What is the time complexity of the recursive (non Dynamic Programming) algorithm for Matrix Chain Multiplication?

Θ(3^n)

Space Complexity of Adjacency Table Which best describes the space complexity of an Adjacency Table representation of graphs.

Θ(V+E) for both undirected and directed graphs

What is the number of scalar multiplication operations required to multiply a m x n matrix A by a n x p matrix B?

Θ(m x n x p)

Fibonacci Numbers - Iterative Implementation Time Complexity Which best approximates the time complexity of the iterative approach to computing Fibonacci numbers?

Θ(n)

What is the time complexity of the aforementioned effiecient algorithm for Maximum Sum Subarray?

Θ(n)

Assuming that the values per weight can be represented with no more than three digits each before and after the decimal point, which best describes the TOTAL time complexity of our greedy algorithm for the Fractional Knapsack Problem?

Θ(n) Because of the limited precision, we can pre-sort in Θ(n) time. Coupled with the time for the main part of the algorithm it is still Θ(n) time.

What is the time complexity of the Dynamic Programming algorithm for Matrix Chain Multiplication?

Θ(n^3)

Pairs of Points 1-D How many pairs of points are there to consider in the closest points problem in one dimension?

n(n-1)/2

Pairs of Points 2-D How many pairs of points are there to consider in the closest points problem in two dimensions?

n(n-1)/2

Exponentiation - Improved Decrease and Conquer What is the solution to the recurrence T(1) = 0 and T(n) = T(n/2) + 1 arising in the second and improved decrease-and-conquer algorithm for scalar exponentiation?

Θ(log n)

Summation Which is the best approximation of the summation 1 + 1/2 + 1/3 + ... + 1/n obtained during our analysis of the average case of Quick Sort (and BST)?

Θ(log n)

E2 - Matrix Multiplication What is the number of scalar multiplication operations required to multiply a m x n matrix A by a n x p matrix B?

Θ(m x n x p)

Counting Sort - Analysis Which of the following best describes the time complexity of Counting Sort with n elements in the range 0 thru m-1?

Θ(m+n)

Super-Stooge Sort What is the time complexity of a Super-Stooge Sort which recursively sorts the first 2/3 of the elements, then the last 2/3 of the elements, then the first 2/3 of the elements, then the last 2/3 of the elements?

Θ(n ^ lg 4) where lg is "log base 3/2"

E2 - Fractional Knapsack Problem - Time Complexity Assuming that sorting by values per weight is comparison-based, what is the total time required for our greedy algorithm for the Fractional Knapsack Problem?

Θ(n log n)

Master Theorem What is the solution to the recurrence T(n) = 2T(n/2) + n?

Θ(n log n)

Creating a Permutation Review What is the time complexity of the method developed in class to create a random permutation of n elements?

Θ(n)

Exponentiation - Decrease and Conquer What is the solution to the recurrence T(1) = 0 and T(n) = T(n-1) + 1 arising in the first decrease-and-conquer algorithm for scalar exponentiation?

Θ(n)

Master Theorem What is the solution to the recurrence T(n) = 2T(n/2) + 1

Θ(n)

Master Theorem What is the solution to the recurrence T(n) = T(n/2) + n?

Θ(n)

Horner's Method - Operations What are the respective number of multiplication operations in Horner's Method and the traditional algorithm for the same purpose?

Θ(n) and Θ(n^2)

Quick Select with Median-of-Medians What is the time complexity of Quick Select, when using the Median-of-Medians subroutine to find an approximate median

Θ(n) in the average and worst cases

Bucket Sort - Analysis What is the time complexity of Bucket Sort on n elements, with m = n/k buckets, each to be respectively sorted using Insertion Sort?

Θ(n) in the average case and Θ(n^2) in the worst case

Square Matrix Multiplication: Serial Computation Review Consider this code for the serial multiplication of two square matrices A and B. What is the time complexity of the algorithm (focusing only on scalar multiplication operations)?

Θ(n^3)

Square Root - Operations What are the respective number of operations in the incrementally iterative and binary-search methods of computing the (floor of the) square toot of a positive integer n?

Θ(√n) and Θ(log n)

E2 - Breadth First Search Trace Review What is the BFS order of visited vertices if we start with 2 and choose the smaller when there is a tie between neighbors

1 E 2 2 D 1 3 A 4 4 F 3 5 C 5 6 B 6

E2 - Fractional Knapsack - Range What is the range of items that can be fractionally included in the Fractional Knapsack Problem?

1 Minimum B 0 2 Maximum C 1

Letter-K Algorithms Review Match the algorithm we learned to its (co-)inventor whose last name begins with the letter K

1 String-matching based on LPS array D Knuth 2 String-matching based on rolling hash function E Karp 3 Maximum sum subarray A Kadane 4 Long-integer multiplication B Karatsuba 5 Minimum spanning tree C Kruskal

E2 - Huffman Coding Encoding Review Match the character with its encoding

1 a I 00 2 b C 01 3 c F 10 4 d E 110 5 e G 111

Selection Sort

A It uses Θ(n^2) comparisons in the worst case B It uses Θ(n^2) comparisons in the average case C It uses Θ(n^2) comparisons in the best case

E2 - Transitive Closure Review Which are necessarily true of the transitive closure matrix TC for a Undirected Graph?

A TC​[i]​[j] = TC​[j]​[i] B TC​[i]​[j] = 1 if i = j

Brute-Force String Matching Review Which of the following would likely improve (lower) the total time required by the Brute-Force String-Matching Algorithm

C Increased size of the alphabet D Increased randomization in the text E Increased randomization in the pattern

Logarithms Which of the following can be used (e.g. on a calculator) to compute the logarithm lg (log base 2) of 7 that arises in the analysis of Strassen's matrix multiplication algorithm? (Let ln denote natural logarithm, and let lt denote log base ten)

C ln 7 / ln 2 F lt 7 / lt 2

Hash Function of Sorting names Suppose we have a hash function like in the previous question - first character A yields 0, first character B yields 1, ... first character z yields 25), with the additional stipulations that (a) the hash table is of size 10 so we use mod 10, and (b) we resolve collisions using linear probing with a simple increment of 1. Assuming that the ten keys are received and inserted in the order in which they appear on the right, match it with its index in the hash table. (Note: this question has nothing to do with sorting. The names of sorts are just keys for this hashing problem.)

1 BUBBLESORT -> 1 2 BOGOSORT -> 2 3 COUNTINGSORT -> 3 4 INSERTIONSORT -> 8 5 QUICKSORT -> 6 6 MERGESORT -> 4 7 HEAPSORT -> 7 8 BSTSORT -> 5 9 RADIXSORT -> 9 10 SELECTIONSORT -> 0

Min and Max Separate How many comparisons total are required to separately find the minimum and maximum elements of an unsorted array (i.e. we will find the min and then completely independently find the max)?

1 Best case -> 2n-2 2 Average case -> 2n-2 3 Worst case -> an-2

Min and Max Combined How many comparisons are required to find the minimum and maximum elements of an unsorted array when we combine the determination as we did in class?

1 Best case -> 3(n-1)/2 2 Average case -> 3n/2 3 Worst case -> 3(n+1)/2

Sorting Example Suppose you initial array has elements 10 9 8 7 6 5 4 3 2 1 in that order. Match the sorting algorithm with the state of the array after the first iteration of the outer loop (i.e. one full completion of the inner loop)

1 Bubble Sort -> 9 8 7 6 5 4 3 2 1 10 2 Selection Sort -> 1 9 8 7 6 5 4 3 2 10 3 Insertion Sort -> 9 10 8 7 6 5 4 3 2 1

Algorithm Design Techniques Match the algorithms to the design technique typically used for implementation

1 Bubble Sort -> Decrease and Conquer 2 Greedy Strategy -> Dijkstra Single-Source Shortest Path 3 Travelling Salesman Problem -> Exhaustive Search 4 Merge Sort -> Divide and Conquer

Key-Index Counting Review When performing Key-Indexed Counting, what is the order of the four main steps?

1 D Compute frequencies of each key 2 A Transform counts to indexes 3 B Distribute the data into auxiliary array 4 C Copy the data from auxiliary array to primary array

Chomsky Hierarchy Review What is the "Chomsky Hierarchy of Languages" from highest (Type 0) to lowest (Type-3)

1 D Recursively enumerable languages 2 C Context-sensitive languages 3 B Context-free languages 4 A Regular languages

Hashing Technique Matching the hashing technique with the description

1 Direct Addressing -> place the item in the index exactly matching the key 2 Universal Hashing -> randomly choose one from a set of hash functions 3 Separate Chaining -> handle collisions by using a (linked) list from the hash index 4 Probing -> if the hash index is occupied then search for another open spot within the table 5 Cuckoo Hash -> f the hash index is occupied then take that sport and move its current occupant to another nearby locationhe table

Sorting Terminology Match the sorting-related term with its definition

1 Offline -> all data for the problem is available upfront 2 Stable -> no new inversions are introduced by the sort 3 In-place -> only O(1) auxiliary space is used 4 Sentinel -> maker not part of the data 5 Inversion -> a larger element appears before a smaller one

Quick Select with Median of Medians Match each component of the recurrence T(n) <= T(n/5) + T(7n/10) + cn

1 T(n) -> worst time for Quick Select recursion to find the median 2 T(n/5) -> time to find a true median of the n/5 medians using Quick Select 3 T(7n/10) -> time to partition the array into two parts (one subject to recursion) 4 cn -> total time for Quick Select

Algorithm Time Complexities Match the algorithm to the time complexity

1 Θ(1) -> Print"Hello World 2 Θ(log n) -> Binary Search 3 Θ(n) -> Linear Search 4 Θ(n log n) -> Heap Sort 5 Θ(n^2) -> Selection Sort 6 Θ(n^3) -> Matrix Multiplication 7 Θ(n!) -> Travelling Saleman Problem

Best Fit Approximation for Online Bin-Packing Problem: Scenario Review Suppose that bits are each of uniform capacity 1.0 and the the items received - in order - have weights .3 .6 .4. .8 .2 .7. Match each item with its bin number, assuming we are using Best Fit Approximation for Online

1 .3 A 1 2 .6 C 2 3 .4 G 2 4 .8 D 3 5 .2 E 3 6 .7 B 1

Next Fit Approximation for Online Bin-Packing Problem: Scenario Review Suppose that bits are each of uniform capacity 1.0 and the the items received - in order - have weights .4 .7 .5. .8 .3 .6. Match each item with its bin number, assuming we are using Next Fit Approximation for Online

1 .4 D 1 2 .7 F 2 3 .5 B 3 4 .8 G 4 5 .3 A 5 6 .6 H 5

First Fit (Forward) Approximation for Online Bin-Packing Problem: Scenario Review Suppose that bits are each of uniform capacity 1.0 and the the items received - in order - have weights .4 .7 .5. .8 .3 .6. Match each item with its bin number, assuming we are using First Fit Approximation for Online

1 .4 F 1 2 .7 E 2 3 .5 G 1 4 .8 A 3 5 .3 J 2 6 .6 D 4

Lempel-Ziv-Welch - Example Consider a simple alphabet ​​[A, B, C]. In LZW compression, assuming the dictionary gets prepopulated with the entire alphabet, how would you compress (represent) the string BABA?

1 0 3

Bin-Packing Problem Scenarios: Optimized Review Match the Bin-Packing Problem scenario with the required number of bins. Assume that the bins are of uniform capacity 1.

1 10 items of .5 each F 5 2 items of .6 each G 8 3 items - half of .4 and half of .6 E 3 4 9 items of 1 each D 9 5 20 items of .1 each I 2 6 16 items - 4 of .1; 4 of .2; 4 of .3; 4 of .4 H 4 7 4 items of .25 each B 1 8 10 items - .1 .2 .3 .4 .5 .6 .7 .8 .9 1.0 C 6 9 20 items of .3 each A 7

Approximation Metrics Review Suppose that a maximization problem has an optimal solution of 100, and an approximated solution of 80. What are the three types of errors in this case?

1 Absolute Error E 20 2 Ratio Error A 1.25 3 Relative Error G .2

E2 - Space Complexity for Graphs Review Match the graph representation with the space complexity

1 Adjacency Matrix for Directed Graph B Θ(V^2) 2 Adjacency Matrix for Undirected Graph H Θ(V^2) 3 Adjacency Table for Directed Graph F Θ(V + E) 4 Adjacency Table for Undirected Graph J Θ(V + E) 5 Edge Set for Directed Graph D Θ(E) 6 Edge Set for Undirected Graph I Θ(E)

Character Sets Review Match the character set with the (minimum) number of bits required to support it

1 DNA D 2 2 Decimal B 4 3 Binary H 1 4 ASCII I 7 5 English Alphabet (uppercase) F 5 6 Octal A 3 7 UTF-16 G 16 8 Base-64 J 6 9 Hexadecimal E 4 10 Extended ASCII C 8

MST for TSP: Circuit Review Consider the following original complete graph (black and red edges) and MST (red edges) found by Prim's Algorithm. Using the approximation algorithm discussed in class, what is the TSP circuit starting with the first vertex AFTER the starting point 0, visiting all other vertices once and then returning to 0. To be clear, we are not asking for the optimal TCP circuit, we are asking for the approximated one using Prim's MST algorithm followed by the Preorder walk. (In your Preorder, break ties by using lowered number vertex first.)

1 E 1 2 B 2 3 D 3 4 A 4 5 C 0

E2 - Huffman Coding - Implementation Review Match the implementation of Huffman Coding (sorting algorithm and data structure for finding minimums) with the total time complexity (n = size of character set)

1 Heap Sort + Unordered List B O(n^2) 2 Heap Sort + Binary Heap A O(n log n) 3 Heap Sort + Two Queues E O(n log n) 4 Radix Sort + Unordered List D O(n^2) 5 Radix Sort + Binary Heap F O(n log n) 6 Radix Sort + Two Queues C O(n)

E2 - Longest Common Subsequence: Example Match the value of LCS for the pair of strings STORE and TEARS

1 LCS​[0]​[0] F 0 2 LCS​[4]​[2] D 1 3 LCS​[2]​[4] I 1 4 LCS​[3]​[5] J 1 5 LCS​[5]​[3] B 2 6 LCS​[5]​[5] H 2

Knuth-Morris-Pratt: LPS Array Example Review For the text "ANALYSISOFALGORITHMS" and pattern "ANANA", match the LPS array position with its value?

1 LPS​[0] F 0 2 LPS​[1] H 0 3 LPS​[2] G 1 4 LPS​[3] B 2 5 LPS​[4] D 3

E2 - Algorithm Purpose Match the algorithm's discovered with its purpose

1 Lempel-Ziv-Welch G Dictionary-Based Compression 2 Bellman-Ford E Single-Source Shortest-Path 3 Floyd B All-Pairs Shortest Path 4 Kadane D Maximum Subarray Sum 5 Ford-Fulkerson F Maximum Flow 6 Huffman A Frequency-Based Compression 7 Prim C Minimum Spanning Tree

Bin-Packing Problem Approximation Algorithms: Time Complexity Review Using only regular iteration (and without the use of Balanced Binary Search Trees), what is the time complexity of each approximation algorithm?

1 Offline First-Fit Decreasing A O(n^2) 2 Offline Best-Fit Decreasing B O(n^2) 3 Online First-Fit D O(n^2) 4 Online Best-Fit E O(n^2) 5 Online Next-Fit C O(n)

Deterministic Finite Automaton (DFA) Review Match the components of a DFA with their description

1 Q C states 2 Σ A alphabet 3 δ E transition function 4 q0 D initial state 5 F B final states

Monte-Carlo and Las Vegas Review Match each randomized algorithm with its classification

1 Quicksort Pivot A Las Vegas 2 Bloom Filter C Monte Carlo 3 Bogo Sort B Las Vegas 4 Rabin Closest Pair D Las Vegas 5 Fermat Little Theorem Primality Testing E Monte Carlo 6 Calculating Pi From Unit Circle F Monte Carlo

E2 - Fibonacci Number: Recursive and Iterative How many times is F(2) computed when trying to compute F(4) in the recursive and iterative implementations of Fibonacci numbers respectively?

1 Recursive A 2 2 Iterative B 1

E2 - Edges in Special Graphs Review Match the type of graph to the number of edges

1 Star C V-1 2 Cycle D V 3 Complete B V(V-1)/2 4 Complete Bipartite A V1xV2 5 Regular E deg(v)xV/2

Classification of Problems Review Assuming that P != NP, and PSPACE != P, match each problem with its (generally assumed) complexity class

1 True Quantified Boolean Formula A Decidable NP-Hard but not NP-Complete 2 Diophantine Equation C Undecidable 3 Sorting Strings D P 4 Factoring Integers E NP but not P 5 Integer Programming B NP-Complete

Regular Expression Shortcuts Review Match the shortcut symbol with its description

1 ^ I complement 2 * C closure 3 . H single character wildcard 4 - F range 5 + B positive closure 6 ? D 0 or 1 copy 7 {n} G specified number of copies 8 \ A escape sequence 9 U E union

Rabin-Karp String-Matching: Fingerprint Review Match each component of the "fingerprint" (hash function) used in the Rabin-Karp string-matching algorithm with its description: ​[(s​[0] x d^(n-1)) + (s​[1] x d^(n-2)) + ... + (s​[n-2] x d^1) + (s​[n-1] x d^0)] % q

1 s A string being encoded 2 n B length of the pattern 3 d E size of the character set 4 q G large prime number 5 % F modulus operator 6 x D multiplication operator 7 ^ C exponentiation operator

E2 - Floyd's Algorithm: Loop Structure Suppose that the nesting order of the main loops in Floyd's Algorithm is: for x = 1 to n / for y = 1 t o n / for z = 1 to n. Match the vertex with the index variable that tracks it

1 source vertex C y 2 intermediate vertex B x 3 destination vertex A z

Bogo Sort Which of the following are true of Bogo Sort?

1. Bogo Sort uses Θ(n*n!) comparisons in the average case 2. Bogo Sort uses Ω(n) comparisons in the worst case 3. Bogo Sort uses Ω(n) comparisons in the average case 4. Bogo Sort uses Ω(n) comparisons in the best case

Number of minimum spanning trees Review How many minimum spanning trees has a star graph of size 6 with edge weights numbered 1 thru 5

1.0

Linear Congruential Generator: Example 2 Review What is the period-length of the Linear Congruential Generator with seed ?

13.0

Estimation of Pi Using Random Numbers Review What estimate of pi would our randomized algorithm compute if our source of random numbers gives the following 10 pairs of points (x,y):-0.8322,-0.4899-0.5224,0.51170.7583,0.87560.7782,-0.82600.2597,0.6354-0.0072,-0.6112-0.5218,-0.3444-0.9582,0.9481-0.0192,-0.26600.9353,-0.4829

2.4

E2 - Huffman Coding Compressed Review What is the total length of the string in bits of the string whose Huffman Coding Tree appears below?

22

Rabin-Karp: Rolling Hash Review Assuming a text "ALGORITHM" and a pattern "EXAM", how would we compute the "rolling hash" for the second comparison from the hash for the first?

26(hash(ALGO) - ord(A)*26^3) + ord(R)

MST for TSP Review Consider the following original complete graph (black and red edges) and MST (red edges) found by Prim's Algorithm. Using the approximation algorithm discussed in class, what is the cost of the TSP circuit starting at 0, visiting all other vertices once, and returning to 0. To be clear, we are not asking for the optimal TCP circuit, we are asking for the approximated one using Prim's MST algorithm followed by the preorder walk. (In your Preorder, break ties by using lowered number vertex first.)

28 Explanation 0 -> 1 (1) then 1 -> 2 (5) then 2 -> 3 (8) then 3 -> 4 (10) then 4 -> 0 (4) = 28

E2 - Dijkstra's Algorithm: Choosing the next vertex Review Dijkstra's Algorithm works by gradually moving vertices from an unused set to a used set. After vertex 3 (the source), what is the next vertex that will be moved to the used set?

4

What is LCS(8, 10) where X = ANALYSIS and Y = ALGORITHMS?

4 The LCS of ANALYSIS and ALGORITHMS is ALIS with length 4

Telescoping What is the solution to the recurrence T(1) = 5, T(n) = T(n-1) + 2

5 + 2(n-1)

Match the array (sequence) with the "maximum sum subarray"

5 -4 2 = 5 -7 -3 -2 = 0 5 -4 7 = 8 7 3 -4 = 10 -3 2 1 = 3

E2 - Longest Palindromic Subsequence (LPS) - Example Assuming indexing begins with 0, what is the value of LPS​[1]​[6] for the string ABCADCBABCABCABC?

5.0

MST for TSP: Edges Review How many edges are in the TSP Cicruit (including returning to source) when using the approximation algorithm based on MST described in some previous questions? The graph has been duplicated here for reference.

5.0

Hash Table - Load Factor Suppose you have 10000 keys from the range of integers 0...999, a hash function h(k) = (k + 20) mod 200, and collision-resolution by chaining? What is the "load factor" of the hash table?

50

Closest Points - How Many Per the previous question, what is that upper bound on the constant number of points that can be on the mid-point line or just on the other side of it, such that they are closer to a given point than the minimum distance detected so far on either side of the mid-line?

6.0

E2 - Floyd's Algorithm: Example, Part IV Suppose that in a graph, there is no direct edge from vertex 1 to vertex 3. However, the following edges and weights do exist: 1 -> 2 (40); 2 -> 3 (30); 1 -> 4 (25); 4 -> 3 (35); 1 -> 5 (10); 5 -> 6 (15); 6 -> 7 (25). After the main loop is completely done, what is the value of dist​[1]​[3]?

60

BST Key Comparisons - Worst Case Consider a BST containing 65536 words, of which 85 begin with the character sequence EX. The BST's alphabet is limited to the 26 upper-case letters A-Z, and the longest word in the BST is 42 letters. What is the worst case of the number of key-comparisons to search for the word EXAMINATION?

65536

Birthday Paradox: Take 2 Review At the end of April, a bunch of customers all having birthdays in May enter a bakery to order cakes for their May birthday celebrations. How many such customers must there be so that there is at least a 50% chance (>= .5 probability) that at least two of them were born on the same day in May (ignore the year). Assume that there are no other customers in the store and that there are no concerns about social distancing etc.

7

E2 - Character Set Review What fixed-length bit-size should be used to support a character set with only the ten decimal digits, lowercase letters, uppercase letters, and the four mathematical symbols {+, -, *, /}

7.0

E 2 - Floyd's Algorithm: Example, Part III Review Suppose that in a graph, there is no direct edge from vertex 1 to vertex 3. However, the following edges and weights do exist: 1 -> 2 (40); 2 -> 3 (30); 1 -> 4 (25); 4 -> 3 (35); 1 -> 5 (10); 5 -> 6 (15); 6 -> 7 (25). After the iteration of the main outer loop where k=2, what is the value of dist​[1]​[3]?

70

Huffman Coding Compressed Size What is the total length of the string in bits of the string whose Huffman Coding Tree appears below?

785

Ttraveling Salesman Problem: Optimal Solution Review What is the total cost of the optimal TSP circuit starting at 1, visiting all other vertices once, and returning to 1?

8

Knapsack Problem: P = NP Review If P=NP, which of the following knapsack problems are in NP-Complete

A 0-1 Knapsack Problem B 0-1 Knapsack with Integer capacity C Fractional Knapsack

Closure of Polynomial Operations Review For which operations are the polynomials closed (i.e. if the operands are polynomials, the result will also be polynomial)

A Addition B Subtraction C Multiplication F Composition

Solvable Problems Review Which of the following solvable problems appeared in the video we watched "Proof That Computers Can't Do Everything"

A Arithmetic C Checkers E Photocopy

E2 - Directed Graph Example - Adjacency Matrix Review Which of the following are true of the Adjacency Matrix A for the following weighted directed graph?

A A​[0]​[0] = 0 C A​[0]​[1] = 0 E A​[0]​[3] = 1

Tree Time Complexities Which are true about the time complexity of the BST, AVL Tree, and B-Tree for search?

A BST has average case of Θ(log n) B AVL Tree has average case of Θ(log n) C B-Tree has average case of Θ(log n) D BST has worst case of Θ(n)

Tree Space Complexity Which are true of the space complexity of BST, AVL Tree, and B-Tree?

A BST has space Θ(n) B AVL Tree has space Θ(n) C B-Tree has space space Θ(n)

Stable Sort Which of the following, as implemented in class, are "stable" sorts

A Bubble Sort C Insertion Sort

Clique Review Suppose an undirected graph of n vertices has has a clique C of m > 2 vertices? Which must be true of C?

A C is connected B C is complete F C has a cycle

Languages Review Which are valid languages over a finite alphabet Σ?

A Empty B Singleton (one word) C Finite D Infinite

Unsolvable Problems Review Which of the following problems are unsolvable?

A Halting Problem B Diophantine Equation Problem E Blank-Tape Problem

Polynomial-Time Reductions Review Which best describes the two "reductions" we did in Lecture #21

A Hamiltonian Circuit to Travelling Salesman F Vertex Cover to Set Cover

E2 - Longest Common Subsequence: Objective Function Which are true of the LCS objective function defined for the Longest Common Subsequence Problem on two strings X and Y with respective lengths m and n?

A If X​[m] = Y​[n] then LCS​[m-1]​[n-1] = 1 + LCS​[m-2]​[n-2] F If X​[m] != Y​[n] then LCS​[m-1]​[n-1] = max(LCS​[m-2]​[n-1] LCS​[m-1]​[n-2])

E2 - Undirected Graph: Adjacency Matrix Which are true about the Adjacency Matrix representation of undirected graphs?

A It is symmetric about the diagonal C The diagonal is all zeros

E2 - Bellman-Ford Review Which of the following are true about the Bellman-Ford Algorithm as presented in class?

A It uses Dynamic Programming B It is intended to solve the Single-Source-Shortest-Path Problem C It finds an optimal solution when there are negative-weight edges

Randomized Binary Search Review Which are true of the randomized Binary Search algorithm?

A It uses a Variable-Size Decrease-and-Conquer design technique B Its average case time complexity is Θ(log n) C Its worst case time complexity is Θ(n) D It can be implemented iteratively or recursively

Insertion Sort with Binary Search Which are true of Insertion Sort, using Binary Search instead of Linear Search to find the points of insertion?

A It uses Θ(n log n) comparisons in the worst case B It uses Θ(n log n) comparisons in the average case

Bubble Sort Which are true of Bubble Sort (basic implementation, without optimizations)?

A It uses Θ(n^2) comparisons in the worst case B It uses Θ(n^2) comparisons in the average case C It uses Θ(n^2) comparisons in the best case D It uses Θ(n^2) swaps in the worst case E It uses Θ(n^2) swaps in the average case

Insertion Sort Which are true of Insertion Sort (traditional implementation, without optimizations)?

A It uses Θ(n^2) comparisons in the worst case B It uses Θ(n^2) comparisons in the average case D It uses Θ(n^2) movements of elements in the worst case E It uses Θ(n^2) movements of elements in the average case

Treap: Time and Space Compelxity Review Which are true of the time and space complexity of a Treap (Randomized BST)?

A Its average case time for Search is O(log n) B Its average case time for Insert is O(log n) C Its average case time for Delete is O(log n) E Its worst case time for Search is O(n) F Its worst case time for Insert is O(n) G Its worst case time for Delete is O(n) H Its worst case space is O(n)

NP-Complete (P=NP) Review If P=NP, to which of the following classes of problems do NP-Complete problems also belong?

A P B NP C NP-Hard D Solvable

BST Traversals Which of the following BST traversals require Θ(n) operations?

A Pre-Order B Post-Order C In-Order D Reverse-Order E Level-Order

Quick Sort, Heap Sort, BST Sort Which of the following sorts take Θ(n log n) comparisons?

A Quick Sort in the average case C Heap Sort in the average case D Heap Sort in the worst case E BST Sort in the average case

Secure Hash Algorithms (SHA) Which of the following are true of SHA?

A SHA represents a family of hash functions used for cryptography and other applications D SHA-256 and SHA-512 are similar hash functions with 32- and 64-byte words respectively E SHA can be used to produce large globally unique numbers

Most Significant Digit (MSD) String Sorting Review Which of the following are generally true of Most Significant Digit (MSD) string sorting?

A Sorts on one character at a time D Has high space complexity compared to LSD string sorts

E2 - Max-Flow Principles Review In the Max-Flow, what should be true about the incoming flow (IF) and outgoing flow (OF) of a node?

A Source node: IF < OF E Sink node: IF > OF I All other nodes: IF = OF

Boolean Satisfiability - NP Complete Review Which two scientists are credited with proving that the Boolean Satisfiability Problem is NP-Complete?

A Stephen Cook D Leonid Levin

E2 - Tree Review Which are true of an (undirected) tree T = (V, E)?

A T is acyclic B Adding any edge to E creates a cycle C T is connected D Removing any edge from E disconnects the graph E |V| = |E| + 1

Balance Factor The "balance factor" of a node in binary tree is defined as the height of the right sub-tree of the node minus (-) the height of the left sub-tree of the node. Which are true about balance factors in AVL Tree

A The balance factor of an internal node can be 1 B The balance factor of an internal node can be 0 C The balance factor of an internal node can be -1 E The balance factor of an external node can be 0

Hamiltonian Circuit Review Which of the following are true of the Hamiltonian Circuits

A The beginning and end vertex are the same B Every vertex in the graph - except the source - must appear exactly once D Between any two successive vertices there must exist an edge from the original graph

Treap Concepts Review Which of the following are true of the data structure Treap (randomized BST)?

A The word Treap is a hybrid of Tree and Heap B Each node in a Treap has a KEY used for searching E The Inorder Traversal (familiar from BST) yields a sorted order of the KEYS when applied to a Treap

Long-Integer Multiplication (Karatsuba) Which are the sub-problems that get computed in Karatsuba's improved version of the divide-and-conquer algorithm for long-integer multiplication?

A XL x YL D XR x YR E (XL+XR)(YL+YR)

Asymptotic Definition - Ratios If the limit (as n goes to infinity) of f(n) / g(n) is 0, then which of the following are true?

A f(n) = Ο(g(n)) B f(n) = o(g(n))

Asymptotic Notation Example Consider two functions f(n) = 100n^2 + 200n + 300 and g(n) = n^2 + 2n + 3. Which of the following are true?

A f(n) = Ο(g(n)) C f(n) = Θ(g(n)) D f(n) = Ω(g(n))

Asymptotic Notation Equivalents If f(n) = Θ(g(n)), which if any of the following are also true?

A f(n) = Ο(g(n)) C f(n) = Ω(g(n))

E2 - Dijkstra's Algorithm: Main Line Review In Dijkstra's Algorithm, when the following if-condition is satisfied, "if dist​[u] + C​[u,v] < dist​[v]", which of the following are true?

A u will currently be the immediate predecessor of the best known path from source to v C dist​[u] + C​[u]​[v] will currently be the cost of the best known path from source to v

Fermat's Little Theorem Review Which are true of Fermat's Little Theorem?

A when p is prime then a^(p-1) = 1 mod p B when p is prime then a^p = a mod p

Distance Formula 1-D Which distance formulas will work equally well for the closest points problem in one dimension where the y-coordinate is always zero? Let a pair of points be denoted by (xi, yi) and (xj, yj). Assume that we just need the closest pair and not necessarily the actual distance.

A |xi - xj| C sqrt((xi-xj)^2 + (yi-yj)^2) D ((xi-xj)^2 + (yi-yj)^2)

Merge - all calls Which of the following are true about the number of comparisons in all calls to Mergesort's Merge method (over the entire course of the Mergesort algorithm)?

A Θ(n log n) in the best case B Θ(n log n) in the average case C Θ(n log n) in the worst case

Merge - one call Which of the following are true about the number of comparisons in one call to Mergesort's Merge method?

A Θ(n) in the best case B Θ(n) in the average case C Θ(n) in the worst case

Boolean Satisfiability Review Which of the following variations of Boolean Satisfiability Problem (SAT) are in NP-Complete?

B 3-SAT C 4-SAT D k-SAT (k > 4)

Optimization vs. Decision Problem Review Which of the following decision problems have a corresponding optimization problem

B Clique C Vertex Cover D Graph Coloring F Knapsack

E2 - Directed Graph Example - Cost Matrix Review Which of the following are true of the Cost Matrix C for the following weighted directed graph?

B C​[1]​[0] = 5 D C​[3]​[0] = 3 E C​[0]​[3] = 1

E2 - Ford-Fulkerson Algorithm for Max-Flow: Residual Graph Review Which are true of the Residual Graph (RG) in the Ford-Fulkerson Algorithm for the Max-Flow Problem on a graph with n vertices? (Let C denote the capacity matrix of the graph)

B Initially RG​[u]​[v] = C​[u]​[v] J Finally - none of the above

Radix Sort Which are true of the Radix Sort algorithm as discussed in class?

B It has time complexity of Θ(dn) where n = elements and d = digits per element D It requires a stable sort per digit

Boolean Satisfiability Problem Review Which of the following are true of the instance of the Boolean Satisfiability Problem: (x1 ∨ x2 ∨ x4) ∧ (x2 ∨ x3 ∨ x5) ∧ (x1 ∨ x4 ∨ x6) ∧ (¬x2 ∨ x3 ∨ ¬x4)

B It is Conjunctive Normal Form (CNF) E A solution can be verified in (deterministic) polynomial time

E2 - 0/1 Knapsack Problem: K[][] We defined a 2-D matrix K​[i]​[w] for our dynamic programming implementation of the 0/1 Knapsack Problem with Integer Capacity? What does it mean if K​[i]​[w] = X. (The focus here is on the words MUST, CAN, and CANNOT.)

B Item i CAN be used in achieving knapsack value X E All of capacity w CAN be used in achieving knapsack value X

Traditional Binary Search Review Which are true of the traditional Binary Search algorithm?

B Its average case time complexity is Θ(log n) D It can be implemented iteratively or recursively

E2 - Greedy Algorithms Which of the following named algorithms from the current test material employ a greedy strategy?

B Kruskal C Ford-Fulkerson E Dijkstra F Huffman

NP-Complete (P!=NP) Review If P!=NP, to which of the following classes of problems do NP-Complete problems also belong?

B NP C NP-Hard D Solvable

Max-Heap Which are true of a Min-Heap?

B The key of the left child can be more than the key of the parent D The key of the right child can be more than the key of the parent

E2 - Dijkstra's Algorithm with Adjacency Table and Binary Heap? Review Using an Adjacency Table and Binary Heap which best describes the process and cost of Extract-Min (including heapifying)?

B There are V Extract-Min operations, each at a cost of O(log V)

Hash Functions - Time Complexity Which steps should be considered to help yield an expected constant-time lookup in a hash table?

B Use a hash function that is uniformly distributed C Make the size of the table proportional - by ia constant factor - to the number of elements in the table D Occasionally expand the hash table as the number of elements it contains grows

Closest Points - Rabin's Algorithm Which are true of Rabin's randomized algorithm for the closest points problem on n points in two dimensions?

B We begin by randomly select a sample of sqrt(n) points C We use brute force to find the closest pair in that sample D If d is the distance in the sample we create a grid of all the points with each cell d x d?

Linear Congruential Generator Review Which of the following criteria are necessary and sufficient for a Linear Congruential Generator - with non-zero b - to have a full period m (i.e. all m numbers in 0 ... m-1 are obtained before the cycle repeats itself)?

B a-1 is divisible by 4 if m is divisible by 4 C a-1 is divisible by all prime factors of m

Multiplicative Congruential Generator Review A Multiplicative Congruential Generator is like a Linear Congruential Modifier except that the increment b = 0, i.e . Depending on the values of a and m, which periods (cycles before returning to beginning) are possible?

B all numbers 1 thru m-1 C period of maximum length m/4

Regular Expression Operations Review Which three of the following are the fundamental operations of a regular expression

B concatenation D Kleene star E union

Randomized Estimation of Pi Review Which inequality should be used to determine if points fall within the circle of diameter 2 centered at the origin?

B x^2 + y^2 < 1

Regular Expression: Color Encoding Review In web programming, color is indicated by using two hexadecimal digits representing the red component, two hexadecimal digits representing the green component, and two hexadecimal digits representing the blue component. Which of the following regular expression shortcuts accurately described the required format for an RGB color?

B ​[0-9A-F]{6} C ​[A-F0-9]{6} D ​[0123456789ABCDEF]{6} E (​[0-9A-F]{2}){3}

Non-deterministic Model of Computation Review If a non-deterministic finite automaton with n states, which of the following are possible number of edges labelled x from a state q, where x is an input symbol in the alphabet for the machine?

C 0 thru n

Rabin-Karp: Calculating the Hash-Fingerprint Review Assuming an alphabet A-Z with corresponding ordinal values 0-25, and a modulus of 1000 (admittedly not prime), what is hash-fingerprint of "HASH"?

C 507

Doomsday Algorithm #2 Which of the following are true when applying the Doomsday Algorithm to determine the day of the week of October 11, 1937 (the first day of classes in the history of Queens College)?

C Doomsday in 1937 was a Sunday D October 10 falls on the same day as Doomsday E October 11 1937 was a Monday

E2 - Kruskal's Algorithm: Disjoint Set Operations Review What are the number of calls to the respective disjoint set operations in Kruskal's Algorithm?

C MAKE-SET O(V), FIND O(E), UNION (V)

Bloom Filter Consider a simple Bloom Filter with just two hash functions h1 and h2 and three keys k1, k2, and k3. The output of the hash functions is as follows:h1(k1) = 1, h2(k1) = 1h1(k2) = 1, h2(k2) = 0h1(k3) = 0, h2(k3) = 0Which three conclusions can be respectively reached about the entities represented by k1, k2, and k3 (one each per k1, k2, and k3)

C k1 may be in the data set E k2 is definitely not in the data set H k3 is definitely not in the data set

Distance Formula 2-D Which distance formulas will work equally well for the closest points problem in two dimensions? Let a pair of points be denoted by (xi, yi) and (xj, yj). Assume that we just need the closest pair and not necessarily the actual distance.

C sqrt((xi-xj)^2 + (yi-yj)^2) D ((xi-xj)^2 + (yi-yj)^2)

E2 - Prim's Algorithm: More Analysis Review Assuming that the graph is implemented with an Adjacency Table and Prim's Algorithm uses a BInary Heap to store the key, what are the respective costs of a single Extract-Min and Update-Key (each including any required restoration)

Extract-Min takes O(log V) and Update-Key takes O(log V)

E2 - Dijkstra's Algorithm: Initialization Review Assuming that Dijsktra's SSSP algorithm is implemented as it appears in the slides , and assuming that the source is vertex 3, what is dist​[2] after the first part (initialization phase) of the algorithm?

G 6 J INFINITY

Separate Chaining - Deletion What is a recommended practice when a single element is no longer needed in a hash table that resolves collisions using Separate Chaining?

Just delete the data

E2 - Disjoint Set Operations: Weighted Union Review Which best describes the disjoint set operation Weighted Union?

Make the root of the smaller tree point directly to the root of the larger tree

Transitive Closure using DFS (Directed Graph) What best represents the the time complexity of computing the Transitive Closure of a Directed Graph, assuming representation by an Adjacency Table

O(VE)

DFA Transition Function Review Which best describes the definition (mapping) of a transition function for a DFA?

Q x Σ → Q

E2 - Run-Length Encoding - Example I Review Decompress the string "R9R6D2" that was decoded via Run Length Encoding

RRRRRRRRRRRRRRRDD

Pre-Sorting Suppose you wish to sort (before an algorithm such as for Closest Points) have 100 points with x-coordinates in the range 0 to 9999.9999 (maximum four digits of precision before and after the decimal place), and the y-coordinate is always 0. Which sort is most appropriate?

Radix Sort

Dijkstra's Algorithm: Fibonacci Heap Which best describes the purpose of using a Fibonacci Heap over an ordinary Binary Heap in implementing Dijkstra's Algorithm?

Reduce the cost of each Update-Key operation

E2 - Dijkstra's Algorithm: Fibonacci Heap Review Which best describes the purpose of using a Fibonacci Heap over an ordinary Binary Heap in implementing Dijkstra's Algorithm?

Reduce the cost of each Update-Key operation

Merge Sort: Serial vs. Parallel Algorithms Review What are the respective recurrences of the time complexities for the serial and parallel (v.1) algorithms for Merge Sort?

S: T(n) = 2T(n/2) + n-1, P: T(n) = T(n/2) + n-1

E2 - Breadth First Search (BFS) Code Review Which best describes the use of a queue in the BFS code provided?

Stores all visited neighboring vertices in the graph

Fibonacci Numbers: Parallel Computation Review Which recurrence best describes the time complexity for the parallel version of a recursive computation of Fibonacci numbers?

T(n) = T(n-1) + 1

Recursive Formula II: Serial Computation Review Which recurrence best describes the time complexity T(n) for the serial version of a recursive computation of f(n) = nf(n-1)?

T(n) = T(n-1) + 1

Quicksort: Parallel Computation Review Suppose we were to parallelize Quicksort by leaving the Partition line as is (serial) and adding the SPAWN keyword before the second recursive call to Quicksort? What would be the recurrence for the time complexity of the worst-case of Parallel-Quicksort?

T(n) = T(n-1) + O(n)

Quicksort: Serial Computation Review What is the recurrence for the time complexity of the worst-case of Quicksort?

T(n) = T(n-1) + O(n)

Fibonacci Numbers: Serial Computation Review Which recurrence best describes the time complexity for the serial version of a recursive computation of Fibonacci numbers?

T(n) = T(n-1) + T(n-2) + 1

Recursive Formula: Parallel Computation Review Which recurrence best describes the time complexity T(n) for the parallel version of a recursive computation of f(n) = f(n-1) + f(n-1) + f(n-1) + ... + f(n-1), with n copies of f(n-1) on the right side, where we SPAWN each computation of f(n-1) into its own process and then SYNC before adding the n results together

T(n) = T(n-1) + n-1

Recursive Formula: Serial Computation Review Which recurrence best describes the time complexity T(n) for the serial version of a recursive computation of f(n) = f(n-1) + f(n-1) + f(n-1) + ... + f(n-1), with n copies of f(n-1) on the right side?

T(n) = nT(n-1) + n-1

Square Matrix Multiplication: Speedup Review What is the speedup achieved by the parallelization of Square Matrix Multiplication. (Let TCS be the time complexity of the serial version - two questions up - and TCP be the time complexity of the parallel version - one question up.)

TCS / TCP

E2 - Warshall's Algorithm: Primary Line In our implementation of Warshall's Algorithm, our main line was "if (TC​[i]​[j] == 0 && ((TC​[i]​[k] == 1 && TC​[k]​[j] == 1)), then TC​[i]​[j] = 1". Suppose that TC​[i]​[j] is not 0 so that at least the first part of the if-condition is not satisfied, what is true about TC​[i]​[j]

TC​[i]​[j] is already 1

E2 - Warshall's Algorithm: Primary Line Review In our implementation of Warshall's Algorithm, our main line was "if (TC​[i]​[j] == 0 && ((TC​[i]​[k] == 1 && TC​[k]​[j] == 1)), then TC​[i]​[j] = 1". Suppose that TC​[i]​[j] is not 0 so that at least the first part of the if-condition is not satisfied, what is true about TC​[i]​[j]

TC​[i]​[j] is already 1

Next-Fit Approximation for Online Bin-Packing Problem Review What does it mean that the Next-Fit Approximation for Online Bin-Packing Problem is "2-Approximate"

The approximate number of bins will be at most two times the optimal number

E2 - Directed Graph: Adjacency Matrix Which are true about the Adjacency Matrix representation of directed graphs?

The diagonal is all zeros

Karp's 21 NP-Complete Problems Review Which was not one of Karp's original 21 NP-Complete Problems?

Travelling Salesman

E2 - Graph Definition Review Which best describes the definition of a graph where V denotes a set of vertices (aka nodes). A graph G is define as a tuple (Y, Z) where...

Y = V and Z = a proper subset of V x V

E2 - MST Example - Kruskal Review What is the first edge chosen by Kruskal's MST algorithm?

1-2

E2 - Max Flow Example Review What is the maximum flow of the network (graph) shown below (from a to z)?

15.0

Counting Sort - Non-integers Which best describes the likely use of Counting Sort on currency (dollars and cents)?

Multiply each element by 100 before using Counting Sort

E2 - Run-Length Encoding: Code Review What instruction should replace the X and Y in this implementation of run-length encoding?

X: r += 1, Y: r = 1

Inverse of Ackermann's Function Which best describes the rate of growth of α(n), the inverse of Ackermann's function

iterated logarithm

Quick Select - algorithm In the Quick Select algorithm modeled after Quick Sort, which is true if we are looking for the i-th order statistic and the pivot is in position k?

we recursively call Quick Select on either left or right depending on whether i < k or i > k

Random Numbers for Estimating Pi Review Suppose that the function rand() returns a random decimal between 0 and 1. What composite function should be used to generate pairs of random numbers all inside the square around the circle of diameter 2 centered at the origin (like in the picture in the slides)

x = 2rand() - 1, y = 2rand() - 1

Quick Select - Analysis What is the time complexity of Quick Select, modelled after Quick Sort, to calculate the median?

Θ(n) in the average case and Θ(n^2) in the worst case

E2 - Longest Palindromic Subsequence - Dynamic Programming - Time Complexity What is the time complexity of the dynamic programming approach to Longest Palindromic Subsequence?

Θ(n^2)

Master Theorem What is the solution to the recurrence T(n) = 4T(n/2) + n?

Θ(n^2)

What is the time complexity of the dynamic programming approach to Longest Palindromic Subsequence?

Θ(n^2)

Long-Integer Multiplication (Brute Force) Which best describes the respective number of addition and multiplication operations in the brute-force (grade school) algorithm for long-integer multiplication?

Θ(n^2) additions and Θ(n^2) multiplications

Matrix Exponentiation Which best describes the time to compute A^m where A is an n x n matrix and m is an integer > 2 combining the traditional algorithm for the product of two matrices but using "binary decomposition" decrease-and-conquer to compute exponentiation for higher powers?

Θ(n^3 log m)

E2 - Matrix Chain Multiplication - Dynamic Programming - Time Complexity What is the time complexity of the Dynamic Programming algorithm for Matrix Chain Multiplication?

Θ(n^3)

Matrix Multiplication (Divide and Conquer) What is the form of the solution to the recurrence T(n) = 8T(n/2) + Θ(n^2) that arose in the original divide and conquer algorithm for matrix multiplication?

Θ(n^3)

Farthest Points 1-D (Pre-Sorted) What is the time complexity required to find the FARTHEST pair of points in one dimension (y-coordinate is zero), where the points have ALREADY been sorted by their x-coordinate?

θ(1)

Farthest Points 1-D (Not Pre-Sorted) What is the time complexity required to find the FARTHEST pair of points in one dimension (y-coordinate is zero), where the points have NOT already been sorted by their x-coordinate and the points have arbitrarily large precision (counting-type sorts not applicable)?

θ(n)

Matrix Product Which is the correct formula for C​[i,j] in product of n x n matrices A and B

(A​[1,1] x B​[1,1]) + (A​[2,2] x B​[2,2]) + ... + (A​[n,n]) x B​[n,n])

E2 - Lempel-Ziv-Welch - Example Review Consider a simple alphabet ​​[A, B, C]. In LZW compression, assuming the dictionary gets prepopulated with the entire alphabet, how would you compress (represent) the string ACAC?

0 2 3

E2 - MST Example - Prim Review Assuming we start with vertex 0, what is the first edge chosen by Prim's MST algorithm?

0-1

E2 - Knapsack Problems Which knapsack problems cannot be solved in polynomial time?

0/1 Knapsack with general real capacity

E2 - Maximum Sum Subarray Match the array (sequence) with the "maximum sum subarray"

1 6 -4 2 B 6 2 -8 -3 -2 C 0 3 6 -4 7 D 9 4 8 3 -4 E 11 5 -4 2 3 A 5

Data Compression Categories Match the data compression technique with the category?

1. Run Length Encoding <=> Sequence 2. Huffman <=> Frequency 3. Lempel-Ziv-Welch <=> Dictionary

Recurrence T(n) = 2T(n/2) + n In solving the recurrence T(n) = 2T(n/2) + n, what was the sequence of major steps that we took?

1. Substitute 2^k for n 2. Domain Transformation S(k) = T(n) 3. Range Transformation R(k) = S(k)/2^k 4. Telescoping

Which are true of the objective function two-dimensional array m​[i]​[j] for Matrix Chain Multiplication?

1. The diagonal is all zeros 2. The lower triangle is all zeros

Linear Congruential Generator: Example 1 Review What is the period-length of the Linear Congruential Generator with seed ?

1.0

Trie Operations Consider a trie data structure containing 65536 words, of which 85 begin with the character sequence EX. The trie's alphabet is limited to the 26 upper-case letters A-Z, and the longest word in the trie is 42 letters. How many character comparisons are required to search for the word EXAMINATION?

11

Huffman Coding - Encode In the example below, what is the encoding of the letter Z?

111100

Randomized Binary Search: Example Review Assume you have an array, indexed from 0 to 9, with the numbers 1 4 9 16 25 36 49 64 81 100. You are searching for the key 100. Your random number generator gives the following numbers in range ​[0,9] to be used as indexes: 6 3 1 5 7 9 0 0 5 2 8 1 9 6 4 2 7. You consider those random numbers in order, ignoring those that have already been used or are outside the currently relevant range. How many key comparisons (i.e. comparing the search key of 100 against data in the array) will be required until you find the key 100? (Assume that <, =, or > can be determined with with a single key comparison.)

3

Estimations If a sorting algorithm takes n^2 operations, and the computer can perform 10 billion operations per second, what is a reasonable estimate of how long it will take to sort 1 billion elements (assuming there is ample memory, the computer doesn't crash, etc.)?

3 years

E2 - Fixed-Length Encoding Review Assuming a characters set limited only to those characters in the five leaves of this Huffman Coding Tree, what would be the total number of bits for a fixed-length representation?

30

Summations What is the value of the summation 1 + 2 + 3 + ... + 99

4950.0

E2 - Huffman Coding - Two Queues Review Assume the implementation of Huffman Coding that uses two queues, one with the original frequencies (OF) and the other with the joined frequencies (JF)? Where will the two minimums be found in forming the node labelled 10?

6 from JF and 4 from JF

Median-of-Five What is the minimum number of comparisons required to find the median of five integers?

6.0

What is the length of the Longest Palindromic Subsequence of QUEENSCOLLEGEOFCUNY?

9

E2 - MST Example - Result Review What is the total weight of the MST for this graph?

9.0

Algorithm What is the origin of the term algorithm?

9th century mathematician Muḥammad ibn Mūsā al-Khwārizmī

Knapsack Problem: P != NP Review If P!=NP, which of the following knapsack problems are in NP-Complete

A 0-1 Knapsack Problem

Lossless vs. Lossy Which of the following are considered lossless data compression techniques?

A. Huffman C. LZW E. RLE

E2 - Depth First Search Review Which best describes the time complexity for Depth First Search, assuming Adjacency Matrix (AM) and Adjacency Table (AT) representations of the graph respectively?

AM uses O(V^2) and AT uses (V + E)

E2 - Powers of Adjacency Matrix Review Which is true of an Adjacency Matrix of a directed graph raised to the k-th power (A^k)

A^k ​[i]​[j] = 1 if there is an path of length k from vertex i to vertex j

Match the graph representation with the space complexity

Adjacency Matrix <=> Θ(V^2) Adjacency Table <=> Θ(V+E) Edge Set <=> Θ(E) Hash Map (with probing) <=> Ω(E)

Which best describes the tightest range of the number of items with only fractional inclusion (i.e. not entirely included or excluded) in the knapsack? (Let n denote the number of items for possible inclusion.)

At least 0 items and at most 1 items There can be one fractional item, but once we use that, we will necessarily fill the remainder of the knapsack with it.

Binary Search For which case(s) does Binary Search use Θ(log n) comparisons

Average Case Worst Case

Closest Points - Time for Rabin's Algorithm What are the average and worst case times for Rabin's randomized algorithm for Closest Points

Average is θ(n) and the worst case is θ(n^2)

E2 - Longest Palindromic Subsequence - Function Which of the following can at least sometimes be true of the LPS function/array as defined in class?

B LPS​[i]​[i] = 1 D LPS​[i]​[i+1] = 1 E LPS​[i]​[i+1] = 2 F LPS​[i]​[j]) = 1 + max(LPS​[i]​[j-1]; LPS​[i+1]​[j]) for j > i+1 G LPS​[i]​[j]) = 2 + LPS​[i+1]​[j-1] for j > i+1

Balanced Binary Search Tree (BBST) for BPP Approximations Review Which best describes the keys in the Balanced Binary Search Trees (BBST) that we used for BPP approximation algorithms?

BBST stores the remaining capacity of each bin

Name that Sort Which sorting algorithm discussed in class appears below?

Cocktail Sort

E2 - Transitive Closure by Matrix Operations Review Which best describes how to determine the Transitive Closure by arithmetic operations on the Adjacency Matrix?

Compute A^0 + A^1 + ... + A^(n-1) where + is boolean addition (true/false)

Transitive Closure by Matrix Operations Which best describes how to determine the Transitive Closure by arithmetic operations on the Adjacency Matrix?

Compute A^0 + A^1 + ... + A^(n-1) where + is boolean addition (true/false)

E2 - Run-Length Encoding - Example II Review Using the second method of run-length encoding (tracking just runs of zeroes, and assuming intermittent single ones), what is the decoding of "3210"?

Correct Answer 0001001011 Correct Answer 000100101

Random Number From Phone Number Review A programmer decides to use the seventh and eighth digits of ten-digit phone numbers as a source of random numbers in the range 0 thru 99. (That is, she uses the YY portion of a phone number N = XXXXXXYYXX as a two-digit number.) Which TWO arithmetic expressions below can be used to accomplish this? Let / denote integer-division and % denote modulo.

D (N % 10000) / 100 F (N / 100) % 100

Universally Unique Identifier (UUID) Review Which are true of the Universally Unique Identifier (UUID), sometimes used as a source of random numbers?

D All of the above

E2 - Coin Change Problem Which function should be used to determine how many coins of denomination d should be used to make change for the remaining value v, assuming that the higher denominations of coins have already been tried and exhausted?

D v // d (integer division)

Open Addressing - Deletion What is a recommended practice when a single element is no longer needed in a hash table that resolves collisions using Open Addressing?

Delete the element data but leave a marker to indicate that the element was deleted

Doomsday Algorithm #1 Which of the following are true when applying the Doomsday Algorithm to determine the day of the week of September 23, 1845 (founding of the baseball team NY Knickerbockers)?

Doomsday in the anchor year of that century was a Friday

Warshall's Algorithm Which algorithm design technique best describes the one used by Warshall's algorithm for computing Transitive Closure?

Dynamic Programming This is a classic example of Dynamic Programming, gradually introducing one more potential intermediate vertex at a time.

B-Tree Which are true of an m-ary B-Tree?

Every node has at most m children

Data Compression - Greedy? Which of the following data compression techniques use a greedy algorithm?

Huffman Coding

E2 - Floyd's Algorithm: Example, Part I Suppose that in a graph, there is no direct edge from vertex 1 to vertex 3. However, the following edges and weights do exist: 1 -> 2 (40); 2 -> 3 (30); 1 -> 4 (25); 4 -> 3 (35); 1 -> 5 (10); 5 -> 6 (15); 6 -> 7 (25). After the initialization loops but before the main loops, what is the value of dist​[1]​[3]?

INFINITY

E2 - Floyd's Algorithm: Example, Part II viewSuppose that in a graph, there is no direct edge from vertex 1 to vertex 3. However, the following edges and weights do exist: 1 -> 2 (40); 2 -> 3 (30); 1 -> 4 (25); 4 -> 3 (35); 1 -> 5 (10); 5 -> 6 (15); 6 -> 7 (25). After the iteration of the main outer loop where k=1, what is the value of dist​[1]​[3]?

INFINITY

Floyd's Algorithm: Example, Part II Suppose that in a graph, there is no direct edge from vertex 1 to vertex 3. However, the following edges and weights do exist: 1 -> 2 (40); 2 -> 3 (30); 1 -> 4 (25); 4 -> 3 (35); 1 -> 5 (10); 5 -> 6 (15); 6 -> 7 (25). After the iteration of the main outer loop where k=1, what is the value of dist​[1]​[3]?

INFINITY Adding intermediate vertex 1 does not help create a path from 1 to 3 so dist​[1]​[3] will remain at INFINITY.

E2 - Determining the degree of a vertex Review Which of the following degrees cannot be determined in time O(V)?

In-Degree of a vertex in a directed graph assuming an Adjacency Table

Who discovered the efficient algorithm for finding the maximum sum subarray?

Kadane

Linear Congruential Generator: Example 2 Review What is the period-length of the Linear Congruential Generator with seed ?

Linear Congruential Generator: Example 2 Review What is the period-length of the Linear Congruential Generator with seed ?

Square Matrix Multiplication: Parallel Computation Review Consider this code for the serial multiplication of two square matrices A and B. In which line(s) of code can we safely add the keyword PARALLEL to execute all iterations of the loop in parallel?

Lines 3, 4

Kruskal's Algorithm: Disjoint Set Operations What are the number of calls to the respective disjoint set operations in Kruskal's Algorithm?

MAKE-SET O(V), FIND O(E), UNION (V)

Disjoint Set Operations: Compressing Find Which best describes the disjoint set operation Compressing Find

Make each node along the path from given node to root point to the root

E2 - Disjoint Set Operations: Compressing Find Review Which best describes the disjoint set operation Compressing Find

Make each node along the path from given node to root point to the root

Merge Sort: Parallel Merge Review Suppose we have two sorted subarrays as follows which we wish to merge:0 1 1 2 3 5 8 13 21 34 55 89 (12 numbers)4 8 12 16 20 24 28 32 (8 numbers)Which best describes how we will conduct the parallel merge?

Merge 0 1 1 2 3 5 with 4, and 8 13 21 34 55 89 with 8 12 16 20 24 28 32

Binary-Tree Traversals Which of the following binary-tree traversals does not take Θ(n) operations?

None of the above

Decision-Tree Model Leaves Which best describes the decision tree model for comparison-based sorts on an unsorted array of n elements?

Number of leaves ≥ n!

Bin-Packing Problem: Optimal Solution Review What best describes the time complexity of currently known algorithms for an optimal solution to the general Bin-Packing Problem?

O(2^n)

E2 - Lempel-Ziv-Welch: Time Complexity Review Which best describes the time complexity of LZW encoding, assuming each lookup in the dictionary used to store the mapping takes L, the length of the text is T, and the size of character set is C?

O(LT)

Lempel-Ziv-Welch: Time Complexity Which best describes the time complexity of LZW encoding, assuming constant time lookups in the dictionary used to store the mapping? Let T = length of text, A = alphabet / character set

O(T)

E2 - Prim's Algorithm: Analysis Review Which best describes the number of calls to Extract-Min and Update-Key operations in Prim's algorithm (ignoring the cost of each operation)?

O(V) Extract-Min and O(E) Update-Key

Prim's Algorithm: Analysis Which best describes the number of calls to Extract-Min and Update-Key operations in Prim's algorithm (ignoring the cost of each operation)?

O(V) Extract-Min and O(E) Update-Key

E2 - Transitive Closure using DFS (Directed Graph) Review What best represents the the time complexity of computing the Transitive Closure of a Directed Graph, assuming representation by an Adjacency Table

O(VE)

E2 - Dijkstra's Algorithm: basic implementation Review Using a Cost Matrix for the weighted graph and an array for Dist, with no additional data structures, which best describes the total time for Dijkstra's Algorithm

O(V^2)

E2 - Coin Change Algorithm - Time Complexity Which best describes the worst case time complexity of the Coin Change Algorithm as originally implemented and after the suggested improvement? Let n be the amount for which we are trying to make change, and let d be the number of denominations of coins.

O(n x d) reducing to O(d)

Which best describes the worst case time complexity of the Coin Change Algorithm as originally implemented and after the suggested improvement? Let n be the amount for which we are trying to make change, and let d be the number of denominations of coins.

O(n x d) reducing to O(d) Initially, we need to potentially consider all denominations for all amounts, but with the improvement, we can compute the number of each denomination at once, for a complexity proportionate to the number of denominations

Knuth-Morris-Pratt: Time for LPS Array Review Assume t is the length of the text T and p is the length of the pattern P, what is the time required for pre-processing, i.e. to compute the LPS array?

O(p)

Rabin-Karp String-Matching: Time Complexity Review Let t be the length of the text T, and p be the length of the pattern P. Assuming that the only rolling hash function being used has modulus 50 (and thus 2% chance of collision). Which best describes the expected time complexity? You may assume that p is much less than t.

O(t)

Bin-Packing Problem Algorithm Review Which approximation algorithm for BPP is shown here?

Online Next-Fit

P and NP Review Which best describes what is known today about the relationship between the classes P and NP

P ⊆ NP (subset)

Millenium Problems Review Which of the following "Millenium Problems" is now considered solved?

Poincaré Conjecture

Brute-Force String Matching Review Let P denote the pattern and T denote the text, and suppose that P​[0] = T​[0], P​[1] = T​[1], but P​[2] != T​[2]. What is the next character comparison that will be performed by the brute-force string-matching algorithm?

P​[0] == T​[1]?

Techniques for Recurrence-Solving Which recurrence-solving technique is utilized in setting R(n) = T(n) / (n+1) during our average-case analysis of Quick Sort?

Range Transformation

Recurrence T(n) = 3T(n-1) + 1 Which transformation(s) should be made to solve the recurrence T(n) = 3T(n-1) + 1?

Range transformation

Reverse-Order Binary Tree Traversal What is the correct sequence of Reverse-Order binary tree traversal?

Rev(right), root, Rev(left)

Counting Sort - Design Which of the following is not part of the customary implementation of Counting Sort

Sort elements by removing inversions between adjacent elements

Closest-Points Problem 2-D Which recurrence best describes the work in the divide-and-conquer algorithm for closest points AFTER realizing that there are at most a constant number of points on or near the dividing line that could be closer than the minim distance detected so far?

T(n) = 2T(n/2) + θ(n)

Closest-Points Problem 2-D Which recurrence best describes the work in the divide-and-conquer algorithm for closest points BEFORE realizing that there are at most a constant number of points on or near the dividing line that could be closer than the minim distance detected so far?

T(n) = 2T(n/2) + θ(n^2)

Long-Integer Multiplication (Divide-and-Conquer) Which recurrence best describes the Divide-and-Conquer approach to long-integer multiplication, WITHOUT Karatsuba's optimization?

T(n) = 4T(n/2) + Θ(n)

Quick Sort Which is not true of Quick Sort?

The Partition method is guaranteed to be Stable

Convex Hull: Quick Hull Which are true of the Quick Hull algorithm used to compute the Convex Hull of a set of n points?

The average case is θ(n log n) and the worst case is θ(n^2)

E2 - Floyd's Algorithm: dist[][] Which best describes the use of the array dist​[i]​[j] used in Floyd's algorithms

The cost of the path (total edge weight) from vertex i to vertex j

Which of the following best describes the role of the greedy approach in minimization (min) and maximization (max) optimization problems?

The greedy approach may work for min and max problems We saw variations of making-change (min problem) and knapsack (max problem) that work optimally with the greedy strategy, and variations that did not work optimally.

Trie - Space Complexity Which best describes the space requirements of a single (internal) node in a traditional trie data structure?

The number of pointers depends on the size of the alphabet

Counting Frequencies: Time and Space Complexity Review Given an alphabet A and data set D chosen over that alphabet, which best describes the respective time and (auxiliary) space complexities for counting the frequencies

Time is O(A+D); Space is O(A)

E2 - Longest Common Subsequence: Time and Space Complexity Which are true of the time and space complexity of our dynamic programming solution to Longest Common Subsequence on two strings each of length n

Time is Θ(n^2) and Space is Θ(n^2)

Which are true of the time and space complexity of our dynamic programming solution to Longest Common Subsequence on two strings each of length n

Time is Θ(n^2) and Space is Θ(n^2)

Which are true of the time and space complexity of Floyd's Algorithm?

Time is Θ(n^3) and Space is Θ(n^2) where n = number of vertices

Which are true of the time and space complexity of Warshall's Algorithm?

Time is Θ(n^3) and Space is Θ(n^2) where n = number of vertices

E2 - Transitive Closure: Transitive Property Review Which of the following are true of the transitive nature of Transitive Closure for Directed Graphs?

T​[i]​[k] = 1 and T​[k]​[j] = 1 --> T​[i]​[j] = 1

Transitive Closure: Transitive Property Which of the following are true of the transitive nature of Transitive Closure for Directed Graphs?

T​[i]​[k] = 1 and T​[k]​[j] = 1 --> T​[i]​[j] = 1 The only statement that is necessarily true is the first one because if there is a path from i to k and from k to j, there is a path from i to j. In the other cases, just because there isn't a direct path between i and j and/or j and k, there may be other paths available.

Unsolvable: Definition Review In the theory of computation and analysis of algorithms, which of the following are equivalent to / synonymous with "unsolvable"?

Undecidable

Strassen's Matrix Multiplication Algorithm - Usage Which describes the best usage of Strassen's matrix multiplication algorithms relative to the traditional algorithm (e.g. taught in Linear Algebra) where the matrices to be multiplied are n x n?

Use Strassen's algorithm for large n but when the sub-problems get small switch to the traditional algorithm

Space-Time Tradeoff in Graphs What is the relationship of space and time complexities in graph representations and algorithms

Variable correlation: the relationship depends on the specific algorithm

E2 - Warshall's Algorithm What is the purpose of the TC​[i]​[j] in the 2-D array computed by Warshall's Algorithm?

Whether there is a path from vertex i to vertex j

Horner's Method Which best describes Horner's Method discussed in class?

an efficient algorithm for evaluating a polynomial with one variable

Random Numbers for Rolling a Pair of Dice Review Suppose that the function rand() returns a random decimal in the interval ​[0, 1). Which composite function should be used to simulate the total of a pair of dice?

ceil(6 rand()) + ceil(6 rand())

E2 - Matrix Chain - Rows and Columns Which are true of the respective number of rows r and columns c in a matrix chain, where i represents the index of the matrix in the chain?

c​[i] = r​[i+1]

E2 - Fractional Knapsack Algorithm - Fractional Case In the greedy algorithm for the Fractional Knapsack Problem, which determines the fraction to be used of the current item? Let IC = initial capacity and RC = remaining capacity

fraction = RC / weight​[i]

Hash Function on Phone Number Which hash function would be best appropriate where the keys (k) are 10-digit phone numbers and the hash table is of size 10000?

k MOD 10000

E2 -= Prim's Algorithm: key array Review In Prim's Algorithm as implemented in the slides shown in class, and assuming an initial vertex 1, what is the meaning of the key array

key​[v] = the minimum cost of an edge from the visited subset of vertices to v

Prim's Algorithm: key array In Prim's Algorithm as implemented in the slides shown in class, and assuming an initial vertex 1, what is the meaning of the key array

key​[v] = the minimum cost of an edge from the visited subset of vertices to v

Matrix Multiplication: Serial Computation Review How many (scalar) multiplications are required to multiply the m x n matrix A by the n x p matrix B to get the m x p matrix C?

m x n x p

Matrix Product Dimensions What are the dimensions of the product of a m x n matrix and a n x p matrix?

m x p

E2 - Min-Cut Property Review Which best describes the "Min-Cut Property" which forms the basis of MST algorithms: If we divide the vertices V of a graph G into two disjoint sets V1 and V2, then the edge of minimum length between V1 and V2

must be part of some MST of G

Min-Cut Property Which best describes the "Min-Cut Property" which forms the basis of MST algorithms: If we divide the vertices V of a graph G into two disjoint sets V1 and V2, then the edge of minimum length between V1 and V2

must be part of some MST of G

E2 - Matrix Chain Multiplication - Objective Function When the algorithm is complete, where would we find the maximum entry in the two-dimensional array m​[i]​[j] representing the objective function for the Matrix Chain Multiplication Problem?

m​[0]​[n-1]

Recurrence T(n) = 4T(2n/3) + 5 Which substitution should best be used in solving the recurrence T(n) = 4T(2n/3) + 1?

n = (3/2)^k

Recurrence T(n) = T(√n) + 1 Which substitution should be made such that the recurrence above will then be naturally ready for a domain transformation and telescoping? (Hint: we did not directly learn this in class, but by trying them , you should be able to see which one works.)

n = 2^(2^k)

Hash Function - First Character Which hash function should be used to map the first letter of a string s​[0] such that A yields 0, B yields 1, ... Z yields 25

ord(s​[0].upper()) - ord('A')

E2 - Floyd's Algorithm: pred[][] Which best describes the use of the array pred​[i]​[j] used in Floyd's algorithms

pred​[i]​[j] = pred​[k]​[j] where k is an intermediate vertex that helped achieve dist​[i]​[j]

Brute-Force String Matching: Time Complexity Review Let a^n denote n copies of the character a. Suppose that the text T = a^(x-1) b - for a total length x, and P = a^(y-1) b (for a total length y) . Which best describes the number of characters comparisons required by the brute-force string matching algorithm for this input.

y(x-y+1)

Deterministic Model of Computation Review In a deterministic finite automaton with an alphabet Σ and states Q, how many edges are there?

|Σ| x |Q|

E2 - Matrix Chain Multiplication - Recursive - Time Complexity What is the time complexity of the recursive (non Dynamic Programming) algorithm for Matrix Chain Multiplication?

Θ(3^n)

Which are true of the respective number of rows r and columns c in a matrix chain, where i represents the index of the matrix in the chain?

r​[i+1] = c​[i]

Fibonacci Numbers - Iterative Implementation How many times is Fib(2) computed to arrive at Fib(5)?

1

What is LCS(3, 10) where X = ANALYSIS and Y = ALGORITHMS?

1 The LCS of ANA and ALGORITHMS is A with length 1.

What is LCS(8, 0) where X = ANALYSIS and Y = ALGORITHMS?

0 The LCS of "ANALYSIS" and "" (empty string) is "" with length 0

Run-Length Encoding - Example II Using the second method of run-length encoding (tracking just runs of zeroes, and assuming intermittent single ones), what is the decoding of "2020"?

00110011

Which are true about the time complexity of the BST, AVL Tree, and B-Tree for search?

1. BST has Average case of Θ(log n) 2. AVL Tree has average case of Θ(log n) 3. B-Tree has average case of Θ(log n) 4. BST has worst case of Θ(n) All three data structures have Θ(log n) search time on average, but your typical (unbalanced) binary search tree can take Θ(n) in the worst case due to the possibility of long paths to the leaves.

Character Set What fixed-length bit-size should be used to support a character set with only space, ten digits, lowercase letters, and uppercase letters?

6 1 + 11 + 26 + 26 = 2 ^ 6

Fixed-Length Encoding Assuming a characters set limited only to those characters in the eight leaves of this Huffman Coding Tree, what would be the total number of bits for a fixed-length representation?

918

Which knapsack problems can be solved in polynomial time?

A Fractional Knapsack with integer capacity B Fractional Knapsack with numeric (2 decimal places) capacity C Fractional Knapsack with general real capacity D 0/1 Knapsack with integer capacity E 0/1 Knapsack with numeric (2 decimal places) capacity The time complexity of the Fractional Knapsack Problem depends on the number of items, whereas the time complexity of the DP approach to 0/1 Knapsack Problem depends on the number of increments to reach the capacity, so it should not be arbitrarily large. ​[Caveat: any data with truly infinite precision will be hard to represent in finite space and compute on in finite time.]

Longest Common Subsequence: Objective Function Which are true of the LCS objective function defined for the Longest Common Subsequence Problem on two strings X and Y with respective lengths m and n?

A. If X​[m] = Y​[n] then LCS​[m-1]​[n-1] = 1 + LCS​[m-2]​[n-2] B. If X​[m] != Y​[n] then LCS​[m-1]​[n-1] = max(LCS​[m-2]​[n-1] LCS​[m-1]​[n-2])

Bellman-Ford Which of the following are true about the Bellman-Ford Algorithm as presented in class?

A. It uses Dynamic Programming B. It finds an optimal solution when there are negative-weight edges C.It has a time complexity of O(VE)

0/1 Knapsack Problem: K[][] We defined a 2-D matrix K​[i]​[w] for our dynamic programming implementation of the 0/1 Knapsack Problem with Integer Capacity? What does it mean if K​[i]​[w] = X. (The focus here is on the words MUST, CAN, and CANNOT.)

A. Item i CAN be used in achieving knapsack value X B. All of capacity w CAN be used in achieving knapsack value X

Match the implementation of Huffman Coding with the total time complexity (n = size of character set) 1. Merge Sort + Unordered List 2. Merge Sort + Binary Heap 3. Merge Sort + Two Queues 4. Radix Sort + Unordered List 5. Radix Sort + Binary Heap 6. Radix Sort + Two Queues

A. O(n^2) B. O(n log n) E. O(n log n) C. O(n^2) F. O(n log n) D. O(n)

Which are greedy algorithms?

A. Prim's MST Algorithm B. Kruskal's MST Algorithm C. Ford-Fulkerson's Max-Flow Algorithm

Max-Flow Principles In the Max-Flow, what should be true about the incoming flow (IF) and outgoing flow (OF) of a node?

A. Source node: IF < OF B. Sink node: IF > OF C. All other nodes: IF = OF

Which are true of an (undirected) tree T = (V, E)?

A. T is acyclic B. Adding any edge to E creates a cycle C. T is connected D. Removing any edge from E disconnects the graph

Undirected Graph: Adjacency Matrix Which are true about the Adjacency Matrix representation of undirected graphs?

A. The space complexity is Θ(V^2) B. It is symmetric about the diagonal C. The diagonal is all zeros

Directed Graph: Adjacency Matrix Which are true about the Adjacency Matrix representation of directed graphs?

A. The space complexity is Θ(V^2) B. The diagonal is all zeros

Dijkstra's Algorithm: Main Line In Dijkstra's Algorithm, when the following if-condition is satisfied, "if dist​[u] + C​[u,v] < dist​[v]", which of the following are true?

A. u will currently be the immediate predecessor of the best known path from source to v B. dist​[u] + C​[u]​[v] will currently be the cost of the best known path from source to v

Run-Length Encoding - Example Decompress the string "A3B4C5" that was decoded via Run Length Encoding

AAABBBBCCCCC

Breadth First Search Which best describes the time complexity for BFS search, assuming Adjacency Matrix (AM) and Adjacency Table (AT) representations of the graph respectively?

AM uses O(V^2) and AT uses (V + E)

Powers of Adjacency Matrix Which is true of an Adjacency Matrix of a directed graph raised to the k-th power (A^k)

A^k ​[i]​[j] = 1 if there is an path of length k from vertex i to vertex j A^k ​[i]​[j] = 1 is there is an path of length k from vertex i to vertex j, i.e. comprised of k edges

Prim's Algorithm: More Analysis Assuming that the graph is implemented with an Adjacency Table and Prim's Algorithm uses a BInary Heap to store the key, what are the respective costs of a single Extract-Min and Update-Key (each including any required restoration)

Extract-Min takes O(log V) and Update-Key takes O(log V)

Warshall's Algorithm To which other algorithms from our course is Wasrhall's Transitive Closure algorithm most structurally similar?

Floyd Floyd's APSP algorithm is structurally similar to Warshall's Transtive Closure algorithm, and have the same time and space complexity. Both also use Dynamic Programming.

Dijkstra: Strategy Which algorithm design technique best describes Dijkstra's SSSP algorithm?

Greedy

Ford-Fulkerson Algorithm for Max-Flow: Residual Graph Which are true of the Residual Graph (RG) in the Ford-Fulkerson Algorithm for the Max-Flow Problem? (Let C denote the capaicty matrix of the graph)

Initially RG​[u]​[v] = C​[u]​[v] At end, RG​[u]​[v] may not be zero if there is remaining capacity for that edge, but not enough flow from earlier vertices to fill it.

Disjoint Set Operations: Weighted Union Which best describes the disjoint set operation Weighted Union?

Make the root of the smaller tree point directly to the root of the larger tree

Edges in Special Graphs Match the type of graph to the number of edges

Star <=> V-1 Cycle <=> V Complete <=> V(V-1)/2 Complete Bipartite <=> V1*V2 Regular <=> deg(v)*v/2

Breadth First Search (BFS) Code Which best describes the use of a queue in the BFS code provided?

Stores all visited neighboring vertices in the graph

Transitive Closure Which are necessarily true of the transitive closure matrix TC for a Directed Graph?

TC​[i]​[j] = TC​[j]​[i] XXXX wrong TC​[i]​[j] = 0 if i = j XXXX wrong TC​[i]​[j] > 0 if i > j XXXX wrong TC​[i]​[j] < 0 if i < j XXXX wrong E None of the above <=== right The first isn't necessarily true because TC is not guaranteed to be symmetric. The second is always false because TC​[i]​[i] = 1 -- a vertex is connected (but not adjacent) to itself. The third may not be true because there isn't always a path from i to j. The fourth is never true because TC cannot be negative.

Warshall's Algorithm: Primary Line In our implementation of Warshall's Algorithm, our main line was "if (TC​[i]​[j] == 0 && ((TC​[i]​[k] == 1 && TC​[k]​[j] == 1)), then TC​[i]​[j] = 1". Suppose that TC​[i]​[j] is not 0 so that at least the first part of the if-condition is not satisfied, what is true about TC​[i]​[j]

TC​[i]​[j] is already 1 The only two possible values for an arbitrary TC​[i]​[j] are 1 (path exists) and 0 (path does not exist). If TC​[i]​[j] is not zero, then it must be one, i.e. a path from i to j has already been found.

Dijkstra's Algorithm with Adjacency Table and Binary Heap? Using an Adjacency Table and Binary Heap which best describes the process and cost of Extract-Min (including heapifying)?

There are V Extract-Min operations, each at a cost of O(log V)

Which are true of the time and space complexity of Warshall's Algorithm?

Time is Θ(n^3) and Space is Θ(n^2) where n = number of vertices TC is a 2-D matrix. We have three nested loops used to compute it.

Warshall's Algorithm What is the purpose of the TC​[i]​[i] array computed by Warshall's Algorithm?

Whether there is a path from vertex i to vertex j The transitive closure is about the existence of a path, i.e. connectivity/reachability. It is based on the transitive property, that is A is related to B, and B is related to C, then A is also related to C.

Which best describes the definition of a graph where V denotes a set of vertices (aka nodes). A graph G is define as a tuple (Y, Z) where...

Y = V and Z = a proper subset of V x V

In the greedy algorithm for the Fractional Knapsack Problem, what should go in the blank to determine the fraction being used?

fraction = remainingCapacity / weight​[i] We want to know what fraction of the total wight of the current item can be contained by the remaining capacity.

Floyd's Algorithm: Loop Structure Suppose that the nesting order of the main loops in Floyd's Algorithm is: for i = 1 to n / for j = 1 t o n / for k = 1 to n. Match the index variable to its purpose.

i = Intermediate vertex j = source vertex k = destination vertex For the algorithm to work properly, the intermediate vertex index must be in the outer loop. In class we called it k, but those are just arbitrary labels.


Kaugnay na mga set ng pag-aaral

Nursing Fundamentals: Module 2(Hygiene, Moving and Positioning, Activity and Exercise)

View Set