Quicksort's average time complexity is O(n log n)
Image: User:Captmondo, Copyrighted free use, via Wikimedia Commons
Quicksort's average time complexity is O(n log n)
Quicksort is a popular sorting algorithm known for its efficiency. On average, it performs n log n comparisons to sort n elements. This average performance is often used as a benchmark for comparing other sorting algorithms.
Example
If you have an array of 1000 elements, quicksort will, on average, require approximately 1000 * log2(1000) ≈ 10,000 comparisons to sort the array.
Understanding quicksort's average time complexity helps in choosing the right sorting algorithm for a given problem, ensuring efficient data processing.
Hash table
Hash table lookup: O(1) average time complexity
merge sort: O(n log n) always
Merge sort consistently performs at O(n log n) time complexity for any input size
O(n log n) is the lower bound for comparison-based sorting
O(n log n) is the lower bound because each of n elements must be compared at least log n times to ensure all permutations are considered
Binary search
Time complexity of binary search: O(log n) — halves search space each step
Dijkstra's algorithm
Dijkstra's algorithm time complexity: O((V+E) log V)
Attention Is All You Need
O(n) complexity for long sequences
One email a day: 5 concepts + the 5 stories that matter →
Swipe through 100 ML concepts daily
Open TickerNews