From 8e983ae9f096df21e98a496f714de9b74f051f4c Mon Sep 17 00:00:00 2001 From: Siddhartha Shankar Padhy <83332618+Siddhartha-Padhy@users.noreply.github.com> Date: Sat, 4 Dec 2021 12:29:06 +0530 Subject: [PATCH] Update binary_insertion_sort.cpp --- sorting/binary_insertion_sort.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sorting/binary_insertion_sort.cpp b/sorting/binary_insertion_sort.cpp index 23ab216a2..32514e2f1 100644 --- a/sorting/binary_insertion_sort.cpp +++ b/sorting/binary_insertion_sort.cpp @@ -4,7 +4,12 @@ * (Insertion Sort)](https://en.wikipedia.org/wiki/Insertion_sort) * * \details - * If the cost of comparisons exceeds the cost of swaps, as is the case for example with * string keys stored by reference or with human interaction (such as choosing one of a pair * displayed side-by-side), then using binary insertion sort may yield better performance. * Binary insertion sort employs a binary search to determine the correct location to insert * new elements, and therefore performs ⌈log2 n⌉ comparisons in the worst case. When each * element in the array is searched for and inserted this is O(n log n). + * If the cost of comparisons exceeds the cost of swaps, as is the case for example with + * string keys stored by reference or with human interaction (such as choosing one of a pair + * displayed side-by-side), then using binary insertion sort may yield better performance. + * Binary insertion sort employs a binary search to determine the correct location to insert + * new elements, and therefore performs ⌈log2 n⌉ comparisons in the worst case. + * When each element in the array is searched for and inserted this is O(n log n). * The algorithm as a whole still has a running time of O(n2) on average because of the series * of swaps required for each insertion. * However it has several advantages such as * 1. Easy to implement