Key Computer Science Algorithms
- 43Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
43 questions
- 1In recursion, a function calls_____within its own body.
Hint
Think about the defining characteristic of recursive functions.
Answer
itself
- 2A recursive algorithm must have at least one_____case and one recursive case.
Hint
What is the term for the condition that stops the recursion?
Answer
base
- 3The strategy of breaking a problem into smaller subproblems and combining their solutions is known as_____.
Hint
Think about how you split a problem into manageable pieces.
Answer
divide and conquer
- 4The Fibonacci sequence has two base cases: F(1)=1 and $F(2) =_____.$
Hint
Consider the first two terms of the Fibonacci sequence.
Answer
1
- 5The recursive case for the Fibonacci sequence is $F(n) = F(n-1) +_____.$
Hint
What two terms sum to the current term?
Answer
F(n−2)
- 6The time complexity of the naive recursive Fibonacci algorithm is $O(_____).$
Hint
It grows exponentially with n.
Answer
2n
- 7Memoization reduces the time complexity of Fibonacci from O(2n) to $O(_____).$
Hint
It becomes linear after caching results.
Answer
n
- 8The iterative Fibonacci algorithm uses $O(_____)$ space.
Hint
It only needs a constant number of variables.
Answer
1
- 9In a binary tree, inorder traversal visits the left subtree, then the_____, then the right subtree.
Hint
What is the order of processing the current node?
Answer
node
- 10Preorder traversal visits the_____before the left and right subtrees.
Hint
Which part is visited first in preorder?
Answer
node
- 11Postorder traversal visits the left subtree, then the right subtree, then the_____.
Hint
The current node is visited last.
Answer
node
- 12When reversing a string recursively, the base case is when the string length equals_____.
Hint
What length indicates no characters left to reverse?
Answer
0
- 13Linear search has a time complexity of $O(_____)$.
Hint
It grows linearly with the number of elements.
Answer
n
- 14Binary search requires the array to be_____.
Hint
What property must the array have for binary search to work?
Answer
sorted
- 15Binary search has a time complexity of $O(_____)$.
Hint
It halves the search space each iteration.
Answer
logn
- 16In binary search, the base case for not finding the element is when the start index is greater than the_____index.
Hint
What index condition indicates no more elements to search?
Answer
end
- 17Depth-first search uses a_____data structure to keep track of nodes to visit.
Hint
LIFO structure.
Answer
stack
- 18Breadth-first search uses a_____data structure to traverse nodes level by level.
Hint
FIFO structure.
Answer
queue
- 19The time complexity of DFS on a grid of width W and height H is $O(_____).$
Hint
It visits each cell at most once.
Answer
W×H
- 20A stable sorting algorithm maintains the relative order of elements with_____keys.
Hint
What kind of keys are considered when checking stability?
Answer
equal
- 21An in-place sorting algorithm modifies the_____array without using extra space proportional to input size.
Hint
It does not create a new array.
Answer
original
- 22Selection sort selects the smallest element from the unsorted portion and swaps it with the_____element.
Hint
Which position in the unsorted part does it swap with?
Answer
first
- 23Selection sort has a time complexity of $O(_____).$
Hint
It's one of the inefficient sorts.
Answer
n2
- 24Insertion sort builds the sorted array one element at a time by_____each new element into the correct position.
Hint
What action is performed to place the element?
Answer
inserting
- 25Insertion sort is efficient for_____sorted data.
Hint
When the data is almost in order.
Answer
partially
- 26Bubble sort repeatedly swaps_____elements if they are in the wrong order.
Hint
Which elements are compared and swapped?
Answer
adjacent
- 27The largest element in bubble sort_____to the end of the array after each pass.
Hint
Think about the name of the algorithm.
Answer
bubbles
- 28Merge sort divides the array into two halves, sorts them recursively, and then_____them.
Hint
What operation combines the sorted halves?
Answer
merges
- 29Merge sort has a time complexity of $O(_____).$
Hint
It is one of the efficient sorts.
Answer
nlogn
- 30Heap sort uses a_____data structure to sort elements.
Hint
What data structure is referenced in the name?
Answer
heap
- 31Quicksort selects a_____element and partitions the array around it.
Hint
What is the chosen element called?
Answer
pivot
- 32Dijkstra's algorithm finds the shortest_____from a start vertex to all other vertices.
Hint
What does the algorithm compute?
Answer
distance
- 33In Dijkstra's algorithm, the table stores the current shortest distance and the_____node for each vertex.
Hint
Which node leads to the current vertex on the shortest path?
Answer
previous
- 34Dijkstra's algorithm uses a_____set to avoid revisiting vertices.
Hint
What is the set that marks completed nodes?
Answer
visited
- 35The time complexity of Dijkstra's algorithm with a min-heap is $O((V + E) \log_____)$.
Hint
The logarithm is base 2 of what?
Answer
V
- 36The A* algorithm extends Dijkstra's algorithm by using a_____to estimate the distance to the goal.
Hint
What function provides an educated guess?
Answer
heuristic
- 37A spanning tree of a graph connects all vertices with no_____.
Hint
What is forbidden in a tree structure?
Answer
cycles
- 38Kruskal's algorithm sorts all edges by_____and adds the smallest edge that does not form a cycle.
Hint
What property of edges is used for sorting?
Answer
weight
- 39In Kruskal's algorithm, the stopping condition is when the number of edges selected equals_____.
Hint
How many edges are in a spanning tree?
Answer
V−1
- 40The time complexity of Kruskal's algorithm is $O(_____)$.
Hint
Sorting edges dominates the complexity.
Answer
ElogE
- 41Dynamic programming stores results of_____to avoid redundant calculations.
Hint
What smaller parts of the problem are saved?
Answer
subproblems
- 42The minimum sum subarray problem can be solved in O(n) time using_____programming.
Hint
What technique avoids recomputation?
Answer
dynamic
- 43In the DP solution for minimum sum subarray, at each element we decide to either start a new subarray or include the_____sum ending at the previous element.
Hint
What value from the previous element is considered?
Answer
minimum

Ask anything
We've read this whole study set, so questions about it get the best answers.