dsa midterm review

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Which of the following container(s) is/are List ADT implementation(s) in C++? [Select all that apply]

-Array -Forward List -Vector

Which of the following statements about linked lists and arrays are TRUE?

-Both data structures can use iterators -Both are linear data types

Which of the following are FALSE? Select all that apply.

-The best case time complexity of linear search is O(1) and occurs when there is just one element in an array -If the growth rate for algorithm A can be represented by T(n) = n and the growth rate for algorithm B can be represented by U(n) = log(n) we can say that algorithm A is faster than algorithm B.

We are given the following Splay Tree: 5 / \ 3 11 / 1 What will be the root->data after we insert for 0 in the splay tree?

0

Given the following ternary tree, which of the following are valid permutations of the orders in which the nodes were accessed using the breadth first search algorithm? 1 /. | \ 2 3 4 /. /\ \ 5. 6. 7. 8 | 9

1 4 3 2 8 7 6 5 9 1 2 3 4 5 6 7 8 9 1 3 4 2 6 7 8 5 9

Given the following ternary tree, which of the following are valid orderings of nodes accessed using the depth first search algorithm? ( 1 /. | \ 2 3 4 /. /\ \ 5. 6. 7. 8 | 9

1 4 8 2 5 9 3 7 6 1 2 5 9 3 6 7 4 8 1 4 8 3 7 6 2 5 9

Consider the following B tree which has the attributes N=3 and L=2. Its height is 2 (Level 0, 1). What is the level order traversal of this tree using the standard approach(left to right by levels), after inserting 17 and 3 in this tree? 10|20 /. | \ 1 | 6 15. 24 | 31

10, 3, 20, 1, 6, 15, 17, 24, 31

Insert the following keys into an initially empty AVL Tree and then perform a standard (left to right by levels) level order traversal: Insert 25, Insert 19, Insert 15, Insert 16, Insert 17, Insert 29, Insert 27

19 16 27 15 17 25 29

Consider the following operations on a queue enqueue(9); dequeue(); enqueue(7); enqueue(2); dequeue(); enqueue(11); enqueue(6); After completing all of the operations, what value is at the front of the queue?

2

Consider the following operations on a stack push(10); push(5); pop(); push(7); pop(); pop(); push(24); push(3); After the completion of all operations, what will size() operation result in? (Note: C++ stacks have a size() method).

2

What is the postorder traversal of the below Binary Tree? Input each node in one box only 25 / .\ 12 51 / .\ / 55 65 45 / 2

2 55 65 12 45 51 25

Which of these functions is omega(n^5log2(n)) ?

2n^6 n^5log4(n)

What node is at an imbalance in this tree? 5 / .\ 4 9 / \ 1 13 \ 2

4

State the output of the following C++ program. If the program has a compiler or runtime error, write error in the box; if the program demonstrates undefined behavior, write undefined in the box).

54321

A B+ tree has N=4 and L=4. It's height is 3 (Level 0, 1, 2). What is the maximum number of unique keys that it can hold? (Assumption: We have inserted unique keys into this tree) N = maximum children a node can have L = maximum keys a node can have

64

A B tree has N=4 and L=4. It's height is 3 (Level 0, 1, 2). What is the maximum number of keys that it can hold? (Assumption: We have inserted unique keys into this tree) N = maximum children a node can have L = maximum keys a node can have

79

State the level-order traversal of the Binary Search Tree (BST) that results after insertingthe following sequence of keys into an initially empty BST: 91 97 64 17 16 47 24 87 93 63

91 64 97 17 87 93 16 47 24 63

Which will be faster? for(i = 1; i < n; i *= 2) for(i = 1; i < n; i *= 3)

B will be faster in terms of execution time/simulation

7a. Which of the following algorithms grows faster (higher big Oh complexity)? A. log(log(x)) B. log(x) C. Grow @ same rate

B. log(x)

Which of the following functions F(n), belongs to the family of O (n²) ? I.E. F(n) ϵ O(g(n))

B. nlog(n) D. log(n) E. 5,000,000

What type of iterator does the container in the following C++ code implement [Select the broadest category]: #include <iostream> #include <list> int main(){ std::list<int> list_container {1, 2, 3, 4, 5}; return 0; }

Bidirectional

7b. Which of the following algorithms grows faster (higher big Oh complexity)? A. log3(x) B. log2(x) C. Grow @ same rate

C. Grow @ same rate

Which of the following are true for the depth first search algorithm?

Commonly implemented using recursion O(n) worst case time complexity, where n is the number of nodes in the tree Commonly implemented using a stack

Doubly linked lists allow random access in the container in constant time.

False

Which of the following assumptions about this binary search tree are correct? 15 /. \ 3 25 /.\ / 51 8. 23

If you added a right child, 30, to Node 25, this tree would be perfect, full, and complete This tree is not full as 25 has 1 child This tree is a complete binary tree

Big O: for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { print("Hi"); } }

O (n * m)

Big O: for(int i = 100; i > -1; i--) { for(int j = i; j > 1; j /= 2) { print("Apple pie"); } }

O(1)

What is the computational complexity of adding an item to a Queue in the worst case in terms of Big O notation?

O(1)

What is the computational complexity of adding an item to a Stack using a Linked List based implementation in the worst case in terms of Big O notation?

O(1)

What is the computational complexity of right rotating a binary search tree at a given node in the worst case?

O(1)

What is the worst case computational complexity of the following code snippet in terms of Big O notation? result = 0 for (i=0; i<10; i++) for (j=0; j<i; j++) result += i*j;

O(1)

What is the worst case computational complexity of the following code snippet in terms of Big O notation? int x = 1 while (x < n) x *= 2

O(log n)

An algorithm's runtime is given by T(n, m) = 3m^3+4m^3*log2⁡m+3n^2+n+100.

O(m^3*log2(m)+n^2)

What is the worst case computational complexity of the following code snippet in terms of Big O notation? result = 0 for (int i = 0; i < n; i++) result += i; for (int j = 1; j < m; j *= 2) result *= j;

O(n + log m)

Big O for: void func1(int n) { for (int i = 0; i < n; i++) cout << i; for (int j = 0; j < n j++) cout << j; }

O(n)

Big O for: if similar growth rates void func1(int n, int m) { for (int i = 0; i < n; i++) cout << i; for (int j = 0; j < m; j*=2) cout << j; }

O(n)

What is the computational complexity of adding an item to a binary search tree in the worst case in terms of Big O notation? Assume n is the total number of nodes in the tree.

O(n)

What is the computational complexity of deleting an element, e from a doubly linked list with tail in the worst case in terms of Big O notation? Assume the list has n items.

O(n)

big o for (int i = n; i > 0; i /= 2) for (int j = 1; j < i; j++) sum +=1; }

O(n)

Big O: for(int i = 0; i < n; i++) { for(int j = n; j > 0; j /= 2) { print("I like pie"); } }

O(n*log(n))

Big O for: void func1(int n, int m) { for (int i = 0; i < n; i++) cout << i; for (int j = 0; j < m; j++) cout << j; }

O(n+m)

An algorithm's total run time is given by the expression, T(n, p) = 10n + p. What is the representation of this program's execution time in Big O?

O(n+p)

What is the computational complexity of the following code snippet? int result = 0 for (int i = 0; i < n; i++) for (int j = i; j > 0; j--) result += 1;

O(n^2)

What is the worst case computational complexity of the following code snippet in terms of Big O notation? int sum = 0 for (int i=0; i<n; i++) for (int j=0; j<i; j++) sum = sum+j;

O(n^2) (n squared)

Given the following binary tree, pick the correct traversal output: 40 / . \ 20 75 / .\ / .\ 15 35 51 83 / .\ / .\ / .\ / .\ 10 17 21 38 47 63. 77. 89

Preorder: 40, 20, 15, 10, 17, 35, 21, 38, 75, 51, 47, 63, 83, 77, 89

Examine the following code snippets below and determine which has a slower growth rate. Consider "c" to be a positive integer constant (c > 1) : Snippet A: for(int i = 0; i < n; i++){ for(int j = n; j > 0; j /= c){ print("Hello");}} Snippet B: for(int i = 0; i < n; i++){ for(int j = n; j >= 100; j--){ print("Hello");}}

Snippet A has a slower growth rate than Snippet B Answer: Snippet A will grow at f(n) = n*logcnSnippet B will grow at g(n) = n*n = n2. So, A will have a slower growth rate

Which of the following statements about binary search trees are true?

The computational complexity of removing a node from a complete binary search tree is O(log n)

for(i = 1; i <= n; i *= 2) for(i = n; i >= 1; i /= 2)

log growth

Which of the following functions T(n), belongs to the family of O(n^3*(log2n))

n^3*(log2(log2n)) n^2+n+5000 1000000 n^3 n^3*(log3n)

Big O: for(i = 1; i < n; i *= 2) for(i = 1; i < n; i *= 3)

will be the same

Is every BST an n-ary Tree?

yes

Which family/families does the following function T(n) = n^5*log2(n) belong to? Check all that apply.

Ω(10000) O(2000n^5+2000^n) O(n^5log3(n))


Ensembles d'études connexes

Chapter 12: Postpartum Physiological Assessments and Nursing Care

View Set

Chapter 7: Movies and the Impact of Images

View Set

Biology 101 - Ch. 15 - Bacteria & Archaea / Ch. 16 - Plants, Fungi, & Protists

View Set