Top 7 Coding Interview Algorithms
- 24Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
24 questions
- 1Binary search can only be used on a_____list.
Hint
The list must be ordered in some way for this algorithm to work.
Answer
sorted
- 2The worst-case time complexity of binary search is_____.
Hint
Think about how the number of elements to search halves each step.
Answer
O(logn)
- 3Linear search has a worst-case time complexity of_____.
Hint
In the worst case, you might have to check every single element.
Answer
O(n)
- 4In depth-first search, the process of returning to an unvisited branch after reaching the end of a path is called_____.
Hint
Think about what you do when you hit a dead end in a maze.
Answer
backtracking
- 5Depth-first search uses a_____array to keep track of visited nodes.
Hint
We need to avoid revisiting the same node.
Answer
visited
- 6One real-life application of depth-first search is solving a_____.
Hint
Think about exploring paths until you find the exit.
Answer
maze
- 7The time complexity of depth-first search is expressed as_____.
Hint
It depends on the number of vertices (nodes) and edges (connections).
Answer
O(V+E)
- 8In breadth-first search, nodes are visited level by level using a_____.
Hint
First-in-first-out data structure.
Answer
queue
- 9Breadth-first search is used in chess algorithms to explore all possible moves at each_____.
Hint
The algorithm looks at moves for the current player, then all responses, etc.
Answer
turn
- 10The time complexity of breadth-first search is also_____.
Hint
Same as DFS for the same reason.
Answer
O(V+E)
- 11Insertion sort works by comparing adjacent elements and_____them if they are out of order.
Hint
It moves elements into the correct position one by one.
Answer
swapping
- 12The best-case time complexity of insertion sort is_____.
Hint
When the list is already sorted, no swaps are needed.
Answer
O(n)
- 13The worst-case time complexity of insertion sort is_____.
Hint
When the list is in reverse order, many swaps are required.
Answer
O(n2)
- 14Insertion sort is best used for lists that are_____.
Hint
It performs well when little movement is needed.
Answer
small or nearly sorted
- 15Merge sort is a_____algorithm, breaking the problem into smaller subproblems.
Hint
It splits the list into halves, sorts them, then combines.
Answer
divide-and-conquer
- 16Merge sort has a time complexity of_____in both best and worst cases.
Hint
The list is always split in half and then linearly merged.
Answer
O(nlogn)
- 17Quick sort picks a pivot and then_____the list into two sublists based on that pivot.
Hint
Elements are rearranged so that all less than pivot come before it.
Answer
partitions
- 18The worst-case time complexity of quick sort is_____.
Hint
Occurs when the pivot is always the smallest or largest element.
Answer
O(n2)
- 19Quick sort has a space complexity of_____while merge sort has a space complexity of O(n).
Hint
Quick sort can be implemented in-place, but recursion adds stack space.
Answer
O(logn)
- 20On average, quick sort is_____times faster than merge sort when implemented correctly.
Hint
The inner loop of quick sort can be highly optimized.
Answer
2-3
- 21Greedy algorithms make the best_____decision at each step without considering future consequences.
Hint
They focus on immediate gain rather than global optimization.
Answer
local
- 22Greedy algorithms are used when finding the_____solution is computationally infeasible.
Hint
They provide a good enough answer when exact optimization is too slow.
Answer
optimal
- 23In the traveling salesman problem, a greedy approach might always choose the_____unvisited city.
Hint
At each step, select the option that minimizes immediate distance.
Answer
nearest
- 24The number of possible routes in the traveling salesman problem with n cities is_____.
Hint
Consider permutations of cities, accounting for starting point and direction.
Answer
2(nā1)!ā

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