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
- C Program for Binary Insertion Sort
- Python Program for Binary Insertion Sort
- Java Program for Binary Insertion Sort
- Insertion sort to sort even and odd positioned elements in different orders
- Insertion sort using C++ STL
- Insertion Sort
- Recursive Insertion Sort
- C Program for Insertion Sort
- Insertion Sort by Swapping Elements
- C Program for Recursive Insertion Sort
- Insertion Sort for Doubly Linked List
- Python Program for Recursive Insertion Sort
- Time complexity of insertion sort when there are O(n) inversions?
- An Insertion Sort time complexity question
- Java Program for Recursive Insertion Sort