Sorting algorithms - Complexities Flashcards
Binary Search - Best case complexity
O(1)
Binary Search - Best case scenario
Target value in middle of array
Binary Search - Worst case complexity
O(log(N))
Binary Search - Worst case scenario
Target value either at very start or end of array
Insertion Sort - Best case complexity
O(N)
Insertion Sort - Best case scenario
Already sorted
Insertion Sort - Worst case complexity
O(N^2)
Insertion Sort - Worst case scenario
Reverse order (Element i > i+1)
Selection Sort - Best case complexity
O(N^2)
Selection Sort - Best case scenario
N/A
Selection Sort - Worst case complexity
O(N^2)
Selection Sort - Worst case scenario
N/A
Merge Sort - Best case complexity
O(N log(N))
Merge Sort - Best case scenario
N/A
Merge Sort - Worst case complexity
O(N log(N))