- -
UPV
 

Iterative Algorithm Analysis: insertion sort

Insertion Sort is a simple iterative sorting algorithm that simulates adding elements to a vector, comparing and moving them to their correct positions. The algorithm works by iterating through the unsorted portion of the vector, picking an element, and searching for its correct position in the sorted portion. This process involves a traversal loop and a search loop, which combine to sort the vector. The implementation of Insertion Sort in Python is demonstrated, showing how the algorithm iterates through the vector, picks an index, and searches for the correct position using a secondary loop. The video explains the step-by-step process, highlighting how the algorithm combines both traversal and search operations. The complexity of Insertion Sort is discussed, with the best-case scenario being linear when the list is already sorted. However, in the worst-case scenario, where the list is sorted in reverse order, the algorithm performs on the order of n squared operations.


EMAS upv