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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- C Program for Binary Insertion Sort
- Java Program for Binary Insertion Sort
- Python Program for Binary Insertion Sort
- 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
- Insertion Sort
- Insertion sort using C++ STL
- Recursive Insertion Sort
- C Program for Insertion Sort
- Insertion Sort by Swapping Elements
- C Program for Recursive Insertion Sort
- Java Program for Recursive Insertion Sort
- Python Program for Recursive Insertion Sort
- Time complexity of insertion sort when there are O(n) inversions?
- An Insertion Sort time complexity question
- Sorting algorithm visualization : Insertion Sort
- Insertion Sort for Doubly Linked List
- C program for Time Complexity plot of Bubble, Insertion and Selection Sort using Gnuplot
- Sort a binary array using one traversal