We can use binary search to reduce the number of comparisons in normal insertion sort. Binary Insertion Sort uses binary search to find the proper location to insert the selected item at each iteration.
In normal insertion sort, it takes O(n) comparisons(at nth iteration) in worst case. We can reduce it to O(log n) by using binary search.
Sorted array: 0 12 17 23 31 37 46 54 72 88 100
Time Complexity: The algorithm as a whole still has a running worst case running time of O(n2) because of the series of swaps required for each insertion.
This article is contributed by Amit Auddy. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Recursive Insertion Sort
- Tree Sort
- Time Complexities of all Sorting Algorithms
- BogoSort or Permutation Sort
- Why Quick Sort preferred for Arrays and Merge Sort for Linked Lists?
- Merge Sort for Doubly Linked List
- Sorting Terminology
- Bubble Sort
- Selection Sort
- Merge Sort
- Insertion Sort
- Stability in sorting algorithms