CS 160 MIDTERM 2 EXAM |COMPLETE QUESTIONS WITH 100% RATED EXPERT
SOLUTIONS |2026 LATEST UPDATED
1. The worst-case runtime of an algorithm is _____ number of steps taken to execute a program.: maximum
2. What is the merge sort algorithm's runtime?: O(N·logN)
3. The best case runtime complexity of an algorithm that searches an array of size N is _____.: O(1)
4. he following algorithm is an example of _____. (Hint: at each level we have two recursive calls. Each recursive
call makes two additional recursive calls. Hence, the number of recursive method calls doubles at each level).
def MyMath(num) if num
<= 1 return num
return MyMath(num - 2) + MyMath(num - 1): an exponential runtime complexity
5. The Big O notation of the algorithm 7+12N+3N2 is _____.: N2
6. Given a doubly-linked list (2, 3, 4, 5, 6, 7), node 2's pointer(s) point(s) to _____.: node 3 and null
7. Replace XXX in the following function header for a doubly-linked list: ListInsertAfter(listName, currentNode,
XXX): newNode
8. A recursive algorithm is based on _____ application(s) of the same algorithm on smaller problems.: repeated
9. comparable object: capable of comparing itself with another object
10. comparator: external to the element type we are comparing and is a separate class
11. arrayList class: a resizable array which can be found in the java.util package
12. built-in array: size of array can(not) be modified: cannot
13. arrayList class: size of array can(not) be modified: can
1/6
, 14. syntax to create an ArrayList object: ArrayList<String> cars = new ArrayList<String>();
15. linkedList is ______________ to arrayList: identical
16. a stack: LIFO
17. LIFO: objects can be inserted at any time, but only the last (the most-recently inserted) object can be removed
18. pushing is synonymous with: inserting
19. popping is synonymous with: removing 20. queue: FIFO
21 FIFO: elements may be inserted at any time, but only the element which has been in the queue the longest may be
removed
22. where are elements inserted and removed in queue: inserted at the rear (enqueued)
and removed from the front (dequeued)
23. the java deque interface represents: a double ended queue 24. push(stack, x): inserts x on top of
stack.
25. Pop(stack): returns and removes item at top of stack
26. Peek(stack): returns but does not remove item at top of stack
27. Enqueue(queue, x): inserts x at the end of the queue
28. Dequeue(queue): returns and removes item at front of queue
29. Peek(queue): returns but does not remove item at the front of the queue
30. PushFront(deque, x): inserts x at the front of the deque
31. PushBack(deque, x): inserts x at the back of the deque
32. PopFront(deque): returns and removes item at front of deque
33. PopBack(deque): returns and removes item at back of deque
2/6
SOLUTIONS |2026 LATEST UPDATED
1. The worst-case runtime of an algorithm is _____ number of steps taken to execute a program.: maximum
2. What is the merge sort algorithm's runtime?: O(N·logN)
3. The best case runtime complexity of an algorithm that searches an array of size N is _____.: O(1)
4. he following algorithm is an example of _____. (Hint: at each level we have two recursive calls. Each recursive
call makes two additional recursive calls. Hence, the number of recursive method calls doubles at each level).
def MyMath(num) if num
<= 1 return num
return MyMath(num - 2) + MyMath(num - 1): an exponential runtime complexity
5. The Big O notation of the algorithm 7+12N+3N2 is _____.: N2
6. Given a doubly-linked list (2, 3, 4, 5, 6, 7), node 2's pointer(s) point(s) to _____.: node 3 and null
7. Replace XXX in the following function header for a doubly-linked list: ListInsertAfter(listName, currentNode,
XXX): newNode
8. A recursive algorithm is based on _____ application(s) of the same algorithm on smaller problems.: repeated
9. comparable object: capable of comparing itself with another object
10. comparator: external to the element type we are comparing and is a separate class
11. arrayList class: a resizable array which can be found in the java.util package
12. built-in array: size of array can(not) be modified: cannot
13. arrayList class: size of array can(not) be modified: can
1/6
, 14. syntax to create an ArrayList object: ArrayList<String> cars = new ArrayList<String>();
15. linkedList is ______________ to arrayList: identical
16. a stack: LIFO
17. LIFO: objects can be inserted at any time, but only the last (the most-recently inserted) object can be removed
18. pushing is synonymous with: inserting
19. popping is synonymous with: removing 20. queue: FIFO
21 FIFO: elements may be inserted at any time, but only the element which has been in the queue the longest may be
removed
22. where are elements inserted and removed in queue: inserted at the rear (enqueued)
and removed from the front (dequeued)
23. the java deque interface represents: a double ended queue 24. push(stack, x): inserts x on top of
stack.
25. Pop(stack): returns and removes item at top of stack
26. Peek(stack): returns but does not remove item at top of stack
27. Enqueue(queue, x): inserts x at the end of the queue
28. Dequeue(queue): returns and removes item at front of queue
29. Peek(queue): returns but does not remove item at the front of the queue
30. PushFront(deque, x): inserts x at the front of the deque
31. PushBack(deque, x): inserts x at the back of the deque
32. PopFront(deque): returns and removes item at front of deque
33. PopBack(deque): returns and removes item at back of deque
2/6