Binary search only works on a list that is what?
AnswerSorted
Binary search halves the search range each step, which requires the items to be in sorted order.
Coding · Facts & stats
7 fact-checked facts about algorithms, each with the reason behind it. 5 more are in today's round and join this page after it closes.
AnswerSorted
Binary search halves the search range each step, which requires the items to be in sorted order.
AnswerA function that calls itself
A recursive function solves a problem by calling itself on smaller versions of the same problem.
AnswerO(log n)
Each step of binary search halves the remaining items, giving logarithmic time.
AnswerO(n²)
Bubble sort may compare and swap neighbors across the list many times, giving quadratic time.
AnswerShortest paths in a graph with non-negative edge weights
Dijkstra's algorithm finds the shortest paths from a starting node when edge weights are not negative.
AnswerO(n log n)
Merge sort splits the list in half repeatedly and merges in linear time, always giving O(n log n).
AnswerO(n²)
Quicksort averages O(n log n), but consistently bad pivot choices degrade it to O(n²).