Array Sorting Algorithms Flashcards
What is the best time complexity of quicksort?
O(n log(n)) - bad
What is quicksort?
A divide and conquer algorithm where it divides the array into two smaller sub arrays. An index in each array is chosen as pivot, and the pivot compares itself to all the other entries so all smaller values are before it and all larger values are behind it. Recursively goes through each sub array (the one before and the one after the pivot position) and repeats.
What is the average time complexity of quicksort?
O(n log(n)) - bad
What is the worst time complexity of quicksort?
O(n^2) - terrible
What is the worst space complexity of quicksort?
O(log(n)) - good
What is merge sort?
A comparison based divide and conquer algorithm, where the list is divided into sublists of one element, then compared with an adjacent list to merge the two lists until it is sorted.
A new array needs to be allocated to store the sorted list.
What is the best time complexity of merge sort?
O(n log(n)) - bad
What is the average time complexity of merge sort?
O(n log(n)) - bad
What is the worst time complexity of merge sort?
O(n log(n)) - bad
What is the worst space complexity of merge sort?
O(n) - okay
What is timsort?
An adaptive sorting algorithm designer by Tim Peters, where it identifies the longest “run” (sorted subarray) and chooses either insertion or merge sort.
What is the best time complexity of timsort?
O(n) - great!
What is the average time complexity of timsort?
O(n log(n)) - bad
What is the worst time complexity of timsort?
O(n log(n)) - bad
What is the worst space complexity of timsort?
O(n) - okay
What is heapsort?
An in-place algorithm that builds a heap out is the data that is placed in an array in the layout of a binary tree. The sorting is done by repeatedly moving the largest element from the heap and inserting into array.
What is the best time complexity of heapsort?
O(n log(n)) - bad
What is the average time complexity of heapsort?
O(n log(n)) - bad