comp 285 final exam practice questions

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

Consider numbers from 0 to 100. If the number being searched for is 99, then write each value of variables passed through find() that would occur while searching for the number. The first is (51,100).

(76,100) (89,100) (95,100) (98,100)

What is the number of children that a leaf node in a 2-3-4 B-tree must have? a. 0 b. 1 c. 2 d. 3

0

As per Dijkstra's shortest path algorithm, what are the predecessor and distance of vertex Y? a. W & 7 b. 0 & infinity c. X and 8 d. T and 10

0 & infinity

How many base cases are required to print the Fibonacci series?#include <iostream>using namespace std;int Fibo(int n) { if(n == 0 || n == 1) { return n; } return Fibo(n - 1) + Fibo(n - 2);}int main() { int n = 10; for(int i = 0; i <= n; ++i) cout << Fibo(i) << " "; return 0;} a. 0 b. 1 c 2 d 3

2

What is the maximum number of loop iterations when searching for "S" in the BST below? a. 6 b. 5 c.4 d. 3

4

How many times is the function GCD() called for the input values 24 and 20 in the below program? #include <iostream>using namespace std; int GCD(int num1, int num2) { int val; if(num1 == num2) { val = num1; } else { if (num1 > num2) val = GCD (num1 - num2, num2); else val = GCD (num1, num2 - num1); } return val; } int main() { int input1 = 24; int input2 = 20; int output; output = GCD(input1, input2); cout << output; return 0; } a. 4 b. 5 c. 6 d. 7

6

Consider a hash table named idTable that uses linear probing and a hash function of key % 10. What is printed after the following operations?HashInsert(idTable, item 45)HashInsert(idTable, item 67)HashInsert(idTable, item 76)HashInsert(idTable, item 78)HashInsert(idTable, item 79)HashInsert(idTable, item 92)HashInsert(idTable, item 87)Print HashSearch(idTable, 67)Print HashSearch(idTable, 77)Print HashSearch(idTable, 87) a. 67, 87 b. 67, null, 87 c. 67, false, 87 d. true, false, true

67, null, 87

Identify the correct statement. a. All hash values can help reconstruct original data b. MD5 produces a 256-bit hash value for any input data c. A hash value can help identify corrupted data d. A hash value cannot help verifying data integrity

A hash value can help identify corrupted data

Which statement is true about the insertion of a new node in an AVL tree? AVLTreeInsert updates heights on all child nodes before inserting the node AVLTreeInsert updates heights on all child nodes after inserting the node AVLTreeInsert updates heights on all ancestors before inserting the node AVLTreeInsert updates heights on all ancestors after inserting the node

AVLTreeInsert updates heights on all ancestors after inserting the node

A(n) _____ is a sequence of steps for solving a problem. recursion algorithm base case subproblem

Algorithm

Identify the correct sequence of operations after inserting 35 in the tree.

NOT Step 1. Insert 35 as node 40's left childStep 2. Color the parent, node 40, blackStep 3. Color the grandparent, node 45, redStep 4. Rotate right at node 45

Which XXX is the recursive base case used to find the factorial of a number?int Factorial(int n) { if (XXX) { return 1; } return n * Factorial(n - 1);}

NOT n<=1

What is the Big O notation for the following algorithm?ctr = 0while (ctr < N) { myAge = ctr val = ctr + 1 while (val < N) { if (ageOfPeople[val] < ageOfPeople[myAge]) myAge = val ++val } tempList = ageOfPeople[ctr] ageOfPeople [ctr] = ageOfPeople [myAge] ageOfPeople [myAge] = tempList ++ctr

O(N^2)

What is the merge sort algorithm's runtime?

O(NlogN)

Which statement would replace XXX in the given depth-first search traversal algorithm?DFS(startV) {Push startV to stackwhile ( stack is not empty ) {currentV = Pop stackif ( currentV is not in visitedSet ) { "Visit" currentV Add currentV to visitedSet for each vertex adjV adjacent to currentV XXX}}}

Push adjV to stack

Which statement would replace XXX if the following loop is used to initialize all vertices' distances to infinity (∞) using Dijkstra's algorithm?for each vertex currentV in graph { currentV⇢distance = Infinity currentV⇢predV = 0 XXX}

Push currentV to unvisitedQueue

Which of the following statements is not true for a recursive function? When a new local variable is declared, a recursive function is pushed onto the stack. All the variables associated with a function are deleted and memory they use is freed up, after the function finishes running. The user has to free up stack space manually. The stack has a Last-In-First-Out data structure.

The user has to free up stack space manually.

Which statement would replace XXX in the FloydWarshallReconstructPath algorithm?FloydWarshallReconstructPath(graph, startVertex, endVertex, distMatrix) { path = new, empty path currentV = endVertex while (currentV != startVertex) { incomingEdges = all edges in the graph incoming to current vertex XXX { expected = distMatrix[startVertex][currentV] - currentE⇢weight actual = distMatrix[startVertex][currentE⇢fromVertex] if (expected == actual) { currentV = currentE⇢fromVertex Prepend currentE to path break } } } return path}

for each edge currentE in incomingEdges

Which of the following cannot be included in a stack frame? Argument variables passed on the stack Local variables The return address Global variables

global variables

Which statement would replace XXX in the given algorithm to get the count of incoming edges?GraphGetIncomingEdgeCount(edgeList, vertex) { count = 0 for each edge currentE in edgeList { XXX count = count + 1 } return count}

if (edge⇢toVertex == vertex)

Which XXX would replace the missing statement in the given algorithm for finding the uncle of a node in an RBT?RBTreeGetUncle(node) { grandparent = null if (node⇢parent != null) grandparent = node⇢parent⇢parent if (grandparent == null) return null XXX return grandparent⇢right else return grandparent⇢left}

if (grandparent⇢left == node⇢parent)

Which XXX base case completes the algorithm to count the number of occurrences of a value in a list of numbers? CountOccurrences(numbers, numbersLength, value, startIndex) { XXX if (numbers[startIndex] == value) return 1 + CountOccurrences(numbers, numbersLength, value, startIndex + 1) else return CountOccurrences(numbers, numbersLength, value, startIndex + 1)}

if (startIndex >= numbersLength)return 0

Which XXX will replace the missing conditional statement in the following code for quicksort?Quicksort(numbers, i, k) { int j = 0 XXX { return } j = Partition(numbers, i, k) Quicksort(numbers, i, j) Quicksort(numbers, j + 1, k)} if(i >= k) if(k > 0) if(i > 0) if(i <= k)

if(i >= k)

Assuming Fact(0) is 1 and Fact(n) returns n*n-1*n-2*..., which XXX is the base condition for the factorial function?int Fact(int n) { XXX return 1; else return n * Fact(n - 1);}

if(n <= 1)

A node in an order 4 B-tree that contains no children is called a(n) _____. a. 3-node b. empty node c. leaf node d. null node

leaf node

Identify the base case for the Fibonacci series. if (n <= 1) // Line 1 return 1; // Line 2 else // Line 3 return fib(n - 1) + fib(n - 2); // Line 4

line 1

Sort the following list of video extensions using selection sort: mpg, mp4, mov, mkv, m4v. What is the order of the elements after the second swap? (m4v, mp4, mov, mkv, mpg) (m4v, mkv, mov, mp4, mpg) (m4v, mkv, mov, mp4, mpg) (m4v, mkv, mov, mp4, mpg)

m4v, mkv, mov, mp4, mpg

Which XXX would replace the missing statement in the following algorithm for updating the height of an AVL tree?AVLTreeUpdateHeight(node) { leftHeight = -1 if (node⇢left != null) leftHeight = node⇢left⇢height rightHeight = -1 if (node⇢right != null) rightHeight = node⇢right⇢height XXX}

node⇢height = max(leftHeight, rightHeight) + 1

The Bellman-Ford shortest path algorithm works _____.

on graphs with negative edge weights, but not negative edge weight cycles

Which abstract data type (ADT) is most suitable to store a list of perishable products such that the product with the nearest expiry date is removed first? a. A deque b. A linked list c. A queue d. A priority queue

priority queue

Which XXX completes the following algorithm? HashSearch(hashTable, key) { bucket = Hash(key) bucketsProbed = 0 while ((hashTable[bucket] is not EmptySinceStart) and (bucketsProbed < N)) { if ((hashTable[bucket] is not Empty) and (hashTable[bucket].key == key)) { XXX } bucket = (bucket + 1) % N ++bucketsProbed }return null a. return hashTable[key] b. return hashTable[bucket] c. return bucket d. return key

return hashTable[bucket]

Errors like segmentation fault, access violation or bad access are caused due to _____. stack overflow stack frame excess memory linker error

stack overflow

Which of the following is best represented by a graph? a. A file system on a computer b. The Undo command in a word processor c. A work scheduling operation d. A telephone network

telephone network

Identify the shortest path between vertices B and D.

x1, x5

Given the list (-45, 35, -32, 67, -89, 23, -11), what will be the final sorted list?

(-89, -45, -32, -11, 23, 35, 67)

identify the error in the recursive function that finds the sum of the digits.int DigitSum(int number) { static int sum = 0; if(number >= 0) { sum += (number % 10); DigitSum(number / 10); } else { return sum; } }

Error: Incorrect base case condition. The recursive calls do not reach the base case leading to infinite recursion.

Which explanation matches the following runtime complexity? T(N) = k + T(N-1)

Every time the function is called, k operations are done, and the recursive call lowers N by 1.

The cycle length for A, C, D, A is _____.

-2

Insertion sort requires at most _____ swaps to sort a list of 20 elements.

190

What values are stored in the list numList? numberList() { for (i = 0; i < 10; i++) { if (i % 2 == 0) { numList[i] = i } }}

[0, 2, 4, 6, 8]

Identify the sequence of nodes that are visited to search for 150. a. 250, 200, 190 b. 250, 200, 190, 210 c. 200, 190 d. 190, 210, 290, 310

a. 250, 200, 190

When using the functionBTreeRemoveKey(node, keyIndex)to remove a key from a 2-3-4 tree node, which is NOT a valid value for keyIndex?

any number outside [0,2]


Set pelajaran terkait

ACCT 3210: Review Chapter 11: PP&E and Intangible Assets-Utilization and Disposition

View Set

Biology - Chapter 5: Cell Division

View Set

Biochem Chapter 6 (Dont think any are from here)

View Set

Section 4 - Transfer and Recording of Title

View Set

Ch. 21 OSPF Network Types and Neighbors

View Set

Accounting 201 - Chapter 12 Quiz

View Set