the same principle is used even if the list contains many elements there are lot of variations of the bubble sort too that minimize the number of iterations and comparisons the bubble sort is highly inefficient sorting algorithm with time complexity of ( and best case of (ngenerallythe bubble sort algorithm should not be used to sort large lists howeveron relatively small listsit performs fairly well there is variant of the bubble sort algorithm where if there is no comparison within the inner loopwe simply quit the entire sorting process the absence of the need to swap elements in the inner loop suggests the list has already been sorted in waythis can help speed up the generally considered slow algorithm insertion sort the idea of swapping adjacent elements to sort list of items can also be used to implement the insertion sort in the insertion sort algorithmwe assume that certain portion of the list has already been sortedwhile the other portion remains unsorted with this assumptionwe move through the unsorted portion of the listpicking one element at time with this elementwe go through the sorted portion of the list and insert it in the right order so that the sorted portion of the list remains sorted that is lot of grammar let' walk through the explanation with an example consider the following array