Exam 1 - 2 review
Which statement is true for a B-tree? All nodes contain the exact same number of entries. All entries of a node are greater than or equal to the entries in the node's children. All leaves are at the exact same depth. All non-leaf nodes have the exact same number of children. All of these provided statements are true.
All leaves are at the exact same depth.
How many comparisons (both successful and unsuccessful) will be made by the brute-force string-matching algorithm in searching for the pattern 01010 in the binary text of one-thousand zeros? 5 1995 2000 1992 1000 995
1992
Assume T is the binary tree provided below. Assume TL and TR are the left and right subtrees respectively of T. What value does the following pseudocoded algorithm compute and return? Algorithm Mystery (T) if (T is not Ø) // Ø implies null or empty return 1 + Mystery(TL) + Mystery(TR) else return 0 6 4 0 1 14
14
Consider the following brute-force algorithm for evaluating a polynomial of degree 5: Algorithm BruteForcePolynomialEvaluation(P[0..5], x) // The algorithm computes the value of polynomial P at a given // point x by "highest to lowest term" brute-force algorithm // Input: An array P[0..5] of the coefficients of a polynomial // of degree 5, stored from lowest to highest and a number x // Output: The value of the polynomial at the point x p = 0.0 for i = 5 downto 0 do power = 1 for j = 1 to i do power = power * x p = p + P[i] * power return p Find the total number of multiplications made by this algorithm. 42 28 36 25 21 6
21
Consider the following Java method: public static int Mystery( int x, int y ) { int answer; if ( y > x ) answer = Mystery( y , x ); else if ( y == 0 ) answer = x; else if ( y > 0 ) answer = Mystery( y , x % y ); // % is int remainder upon division of x by y return answer ; } What is returned by this method if the initial values of x and y are 120 and 48 respectively? 1 48 4 2 24 120
24
Compute the following sum: 1 + 3 + 5 + 7 + ... + 999 Summation formulas you might need: ∑i=1n1=1+1+...+1=n−1+1=n ∑i=1ni=1+2+...+n=n(n+1)2 ∑i=lucai=c∑i=luai ∑2i -1 for i = 1 to 999 12750 250000 245000 ∑2i + 1 for i = 1 to 999 1015 ∑ i for i = 1 to 999
250000
A B-tree of order 4 and of height 3 will have a maximum of _______ keys. 127 255 188 63
255
Consider the following array definition: int array[8] = {44, 36, 46, 32, 38, 52, 30, 26} Suppose this list was to be sorted by the selection sort algorithm discussed in class. What would be the arrangement of the list after the fourth pass through the array? 26 30 32 36 38 44 46 52 26 30 32 36 38 44 52 46 26 30 32 36 52 44 38 46 26 30 32 46 38 52 46 44 26 30 32 36 38 52 46 44
26 30 32 36 38 52 46 44
Given the following array of values to be sorted, which of the following indicates the contents of the Count array after the final pass of the Comparison Counting sorting algorithm? 51 12 96 78 48 33 3 0 5 4 2 1 12 33 48 51 78 96 4 1 6 5 3 2 0 1 2 3 4 5
3 0 5 4 2 1
Consider sorting the array below whose values are known to come from the set {60,61,62,63,64,65} and should not be overwritten in the process of sorting. For the Distribution Counting algorithm, which of the following indicates the values of the distribution array D? 65 60 63 60 64 61 63 61 62 63 60 62 65 64 62 60 61 62 63 64 65 3 2 3 3 2 2 2 4 7 10 12 14 3 5 8 11 13 15
3 5 8 11 13 15
Construct a max heap for the following input list: 6, 34, 26, 22, 14, 30, 18 34, 22, 30, 6, 14, 26, 18 34, 30, 22, 14, 6, 18, 26 6, 14, 18, 22, 26, 30, 34 34, 30, 26, 22, 18, 14, 6
34, 22, 30, 6, 14, 26, 18
Consider the problem of searching for genes in DNA sequences using Horspool's algorithm. A DNA sequence consists of a text on the alphabet {A, C, G, T}. Determine the number of character comparisons using Horspool's algorithm needed to locate the gene sequence TCCTATTCTT on chromosome 11: 47 42 38 11 10 29
38
Consider the following array definition: int array[9] = {18, 22, 28, 34, 42, 44, 58, 64, 86}; How many iterations would be required to locate the value 34 if the binary search algorithm as discussed in class was used? Assume the left and right subscript boundaries are exclusive in the search algorithm's determination of middle i.e. left gets reset to middle + 1 or right gets reset to middle - 1 for the next iteration after no match. 4 3 9 1 2
4
What is the height of the following binary tree? 4 6 3 5
4
Given the following array of values, determine the arrangement of the array after the fourth pass of the insertion sort as discussed in class: 17 4 32 25 16 10 4 10 16 17 25 32 4 16 17 25 32 10 4 10 17 16 25 32 4 16 10 17 32 25
4 16 17 25 32 10
In what input order should we insert the elements {1, 2, 3, 4, 5, 6, 7} into an empty AVL tree so that we don't have to perform any rotations on it? 2, 6, 1, 4, 3, 5, 7 1, 2, 3, 4, 5, 6, 7 4, 2, 6, 1, 3, 5, 7 7, 6, 5, 4, 3, 2, 1 none of the provided input sequences will result in an AVL tree without having to perform rotations
4, 2, 6, 1, 3, 5, 7
A hash function h defined h(key)=key mod 7, with linear probing, is used to insert the keys 44, 45, 79, 55, 91, 18, 63 into a table indexed from 0 to 6. What will be the location of key 18? 2 3 4 5 6
5
Consider the following array definition: int array[8] = {44, 26, 46, 30, 38, 32, 52, 36}; Suppose this array was to be sorted with an enhanced bubble sort algorithm -- i.e. assume the algorithm terminates if no exchanges are made on a pass through the unsorted part of the array. How many passes through the array would be required to arrange these data into ascending order? 5 6 8 7 4
5
Construct a B-Tree of order 4 by inserting the following input keys successively. 10, 20, 30, 40, 25, 15, 5, 2, 7, 1 What is the number of node splitting operations that takes place? 5 3 6 4 7
5
Using Horner's rule, which of the following is the value of the polynomial function for x= −2: f(x) = 3x4 - x3 + 2x + 5 2 -26 25 57 -7 53
57
Given the following initial heap, what is the array representation after the first pass of the heapsort when the heap is reconstructed after the initial maximum value (97) has been swapped with the last leaf (31). 58 53 59 26 41 31 31 53 58 26 41 31 59 53 31 26 41 58 26 31 41 53 58 59 59 53 58 26 41 31 59 58 53 41 31 26
59 53 58 26 41 31
Solve the following recurrence relation using backward substitutions: T(n) = T(n - 1) + 5 for n > 1, T(1) = 0 n(n - 1)/2 n(n + 1)/2 n2 n - 4 5 n- 1 5n - 5
5n - 5
Assume T is the binary tree provided below. Assume TL and TR are the left and right subtrees respectively of T. What value does the following pseudocoded algorithm compute and return? Algorithm Mystery (T) if T = Ø return 0 // Ø implies null or empty else if TL = Ø and TR = Ø return 1 else return Mystery(TL) + Mystery(TR) 0 1 6 4 14
6
Consider the following array definition: int array[10] = {44, 34, 28, 63, 56, 86, 38, 42, 22, 64}; How many comparisons would be required to locate the value 38 if the brute force sequential search algorithm was used? 7 2 6 10 8
7
Consider the following array definition: int array[4] = {22,18,23,16}; Suppose this list was to be sorted with the recursive mergeSort algorithm as demonstrated in class. How many times would mergeSort be called to successfully sort the given array? Recall that the algorithm is called for sublists of size 1. 6 15 7 8 5 4
7
Given a hash table T with 25 slots that stores 2000 elements, the load factor α for T is __________. 80 800 1.25 0.0125 8000
80
Consider the following array definition: int array[6] = {38, 67, 21, 12, 44, 47}; Suppose this list was to be sorted with the recursive quickSort algorithm as demonstrated in class. How many times would quickSort be called to successfully sort the given array? Recall that the algorithm is also called for subarrays with one or no elements (base case). 5 6 7 13 9
9
Consider the problem of searching for genes in DNA sequences using Horspool's algorithm. A DNA sequence consists of a text on the nucleobase alphabet {A, C, G, T} and the gene or gene sequence is the pattern. Which of the following is the shift table for the following gene sequence: TCCTATTCTT A C G T 6 3 10 1 A C G T 5 7 4 0 A C G T 5 2 10 1 A C G T 4 1 10 3
A C G T 5 2 10 1
Which of the following is an AVL tree. Look at question 16, Exam 2 Only C None of these A, B, and C A and C B and C Only A
A and C
For the directed graph below, which answer is a topological ordering of the vertices. A, D, E, F, C, G, B A, B, E, D, C, F, G A, B, E, F, C, G, D A, B, E, F, D, G, C A, E, B, F, C, G, D
A, B, E, F, C, G, D
For the graph provided below and starting at vertex A, which of the following lists the nodes in the order in which they are first visited using the Breadth-First Search (BFS) algorithm: A, J, L, K, B, D, C, E, F, G, H, I A, B, C, D, E, F, G, H, I, J, K, L A, J, K, L, B, D, C, E, F, G, H, I B, D, C, E, F, G, H, I, A, J, L, K
A, J, K, L, B, D, C, E, F, G, H, I
For the graph provided below and starting at vertex A, which of the following lists the nodes in the order in which they are first visited using the Depth-First Search (DFS) algorithm: A, B, C, D, E, F, G, H, I, J, K, L A, J, K, L, B, C, D, E, F, G, H, I B, D, C, E, F, G, H, I, A, J, L, K A, J, L, K, B, D, C, E, F, G, H, I A, J, K, L, B, D, C, E, F, G, H, I
A, J, L, K, B, D, C, E, F, G, H, I
A forest of trees is equivalent to a single connected graph. True False
False
Assume the following statements: Algorithm A requires time proportional to log2 n Algorithm B requires time proportional to n Algorithm A's time requirement (as function of problem size n) increases faster than Algorithm B's time requirement. True False
False
Building an initial heap with n input elements can always be done in O(n log n) time. True False
False
Consider the following pseudocode: int avl( binarySearchTree root ) if( not root ) // empty tree/subtree? return 0 leftTreeHeight = avl( leftOfRoot ) if( leftTreeHeight == -1 ) return leftTreeHeight rightTreeHeight = avl( rightOfRoot ) if( rightTreeHeight == -1 ) return rightTreeHeight This pseudocode correctly checks if a binary search tree is an AVL tree. True False
False
Given a hash table of size n with n key elements and using linear probing (closed hashing), any element can be found by one comparison for locating any given key. True False
False
In the Distribution Counting algorithm, if all distinct n values from the set of possible values to be sorted occur exactly once, then the Frequency array contains the values 1, 2, 3, ..., n in sequence respectively. True False
False
Inserting a key into a binary search tree with n keys takes O(log n) time. True False
False
The analysis of an algorithm must take into consideration the sequential computer that will be used to run a program that implements the algorithm. True False
False
The best case efficiency for the quickSort is when the input data are already sorted. True False
False
The height of any binary search tree with n nodes is O(log n). True False
False
Match the following algorithms with their order of growth for inputs of size n. Note that '^' indicates exponentiation. Heap Sort B-Tree Search Quicksort Average Case Binary Tree Traversal Distribution Counting Sort Match Options: O(n!), O(1), O(n^2), O(2^n), O(log n), O(n), O(n log n)
Heap Sort -> O(n log n) B-Tree Search -> O(log n) Quicksort Average Case -> O(n log n) Binary Tree Traversal -> O(n) Distribution Counting Sort -> O(n)
What value does the following recursive algorithm compute and return, assuming the initial value of the integer parameter N is 61? Algorithm Mystery(N) if (N > 0) return 1 + Mystery(N / 2) // note integer division of N by 2 else return 0 correct answer not provided It computes and returns 0. It computes and returns 61. It computes and returns 7. It computes and returns 6.
It computes and returns 6.
What value does the following recursive algorithm compute and return, assuming that the initial values of the parameters X and Y are 5 and 3 respectively? Algorithm Mystery(X, Y) if (X == 0) return Y else return 1 + Mystery(X - 1, Y) It computes and returns 4. It computes and returns 8. It computes and returns 15. correct answer not provided It computes and returns 5. It computes and returns 3.
It computes and returns 8.
Consider the following algorithm: Algorithm Range( A[0..n - 1] ) //Input: An array A[0..n - 1] of n positive integers //Output: The range of n positive integers in array A minval ⟵ ∞ maxval ⟵ 0 for i ⟵ 0 to n - 1 do if A[i] > maxval maxval ⟵ A[i] if A[i] < minval minval ⟵ A[i] return maxval - minval What is the efficiency class of this algorithm? O(n - 1) O(2n - 2) O(2) O(n) O(n2)term-14
O(n)
Any comparison-based algorithm for finding the largest (or smallest) among n given numbers must make n - 1 comparisons in the worst case. True False
True
Closed hashing using linear probing can only store as many unique keys as the size of the table. True False
True
Euclid's algorithm does not require the calculation of prime factors using the Sieve of Eratosthenes. True False
True
For large arrays, the traditional bubble sort is prohibitively inefficient. True False
True
Low-order terms in a polynomial function representing the count of a basic operation can generally be ignored in an algorithm's growth-rate function classifying its efficiency. True False
True
The efficiency of the insertion sort can depend on the initial arrangement of the data. True False
True
The following is an AVL tree: True False
True
The worst case, average case and best case of Merge Sort are all O(nlog2n). True False
True
Consider the problem of finding the smallest and largest elements in an array of n elements. For a presorting-based algorithm for solving this problem, how does this algorithm compare with the brute-force approach? brute-force is more efficient both algorithms are equivalent in time efficiency presorting-based is more efficient not enough information to compare the two algorithms
brute-force is more efficient
For the given binary tree below, what is the order of nodes visited using post-order traversal algorithm? a, b, d, g, e, c, f g, d, e, b, f, c, a d, g, e, b, f, c, a g, d, b, e, c, f, a d, g, b, e, a, f, c
g, d, e, b, f, c, a
Match the following algorithms with their order of growth for inputs of size n. Note that '^' indicates exponentiation. merge sort knapsack problem by exhaustive search binary tree search (worst case) insertion sort (average case) number of bits in a decimal number Answer Options(reusable): O(1), O(n!), O(n), O(n^2), O(2^n), O(log n), O(nlog n)
merge sort -> O(n log n) knapsack problem by exhaustive search -> O(2^n) binary tree search (worst case) -> O(n) insertion sort (average case) -> O(n^2) number of bits in a decimal number -> O(log n)
Using Horner's rule to evaluate a polynomial function of degree n. The number of multiplications is ____. n/2 n^2 n logn
n
Consider the following brute-force algorithm for evaluating a polynomial of degree n: Algorithm BruteForcePolynomialEvaluation(P[0..n], x) // The algorithm computes the value of polynomial P at a given // point x by "highest to lowest term" brute-force algorithm // Input: An array P[0..n] of the coefficients of a polynomial // of degree n, stored from lowest to highest and a number x // Output: The value of the polynomial at the point x p = 0.0 for i = n downto 0 do power = 1 for j = 1 to i do power = power * x p = p + P[i] * power return p Find the total number of multiplications made by this algorithm. Summation formula:1 + 2 + ...+ n = n(n+1)/2 n(n−1)/2 + (n+1) n(n+1) n(n+1)/2 + n n(n+1)/2 + (n+1) n(n−1)/2 + (n−1)
n(n+1)/2 + (n+1)
Order the following functions by growth rate from smallest (1) to largest (5). Note that '^' indicates exponentiation. n^5 log n n! - n ¼n^2 - ¼n - ¼ 3^(n-1) n^(7.0/2.0)
n^5 log n 3 -> 3 n! - n 5 -> 5 ¼n^2 - ¼n - ¼ 1 -> 1 3^(n-1) 4 -> 4 n^(7.0/2.0) -> 2
Given the following set of items, their weights, costs, and a knapsack capacity of 10. Which of the following represents the most valuable subset of items that will fit into the knapsack: ITEM WEIGHT COST 1 7 $42 2 3 $12 3 4 $40 4 5 $25 {3, 4} {1, 3} exactly two of the possible answers yield same most valuable subsets {2, 3, 4} {2, 4} {1, 2, 3} {2, 3} {1, 2}
{3, 4}
Consider the problem of finding the smallest and largest elements in an array of n elements. For a presorting-based algorithm for solving this problem, which of the following represents its efficiency class? Θ(n2) Θ(1) Θ(log n) Θ(n log n) Θ(n)
Θ(n log n)
Using the Master Theorem, which of the following is the order of growth for solutions of the recurrence relation: T(n) = 4T(n/2) + n, T(1) = 1 Use Master Theorem θ(n) θ(n/2) θ(nlog2n) θ(log2n) θ(2n) θ(n^2)
θ(n^2)