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^2) 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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Comparison among Bubble Sort, Selection Sort and Insertion Sort
- Insertion sort to sort even and odd positioned elements in different orders
- Merge Sort vs. Insertion Sort
- C Program for Binary Insertion Sort
- Java Program for Binary Insertion Sort
- Python Program for Binary Insertion Sort
- Time complexity of insertion sort when there are O(n) inversions?
- An Insertion Sort time complexity question
- Recursive Insertion Sort
- Insertion Sort
- Insertion Sort for Doubly Linked List
- C Program for Insertion Sort
- Insertion sort using C++ STL
- C Program for Recursive Insertion Sort
- Java Program for Recursive Insertion Sort
- Python Program for Recursive Insertion Sort
- Insertion Sort by Swapping Elements
- C program for Time Complexity plot of Bubble, Insertion and Selection Sort using Gnuplot
- Sorting algorithm visualization : Insertion Sort
- Lower Insertion Point