Professional Documents
Culture Documents
Lecture 4 - Insertion Sort PDF
Lecture 4 - Insertion Sort PDF
Lecture 4 - Insertion Sort PDF
Insertion Sort:
Insertion sort is a sorting algorithm that builds a final sorted array one element at a
time. While sorting is a simple concept, it is a basic principle used in complex computer
programs such as file search, data compression, and path finding.
*permutation refers to a mathematical calculation of the number of ways a particular set can be arranged
Insertion Sort
The insertion sort algorithm iterates through an input array and removes one element
per iteration, finds the place the element belongs in the array, and then places it there.
This process grows a sorted list from left to right. The algorithm is as follows:
Design and Analysis of Algorithm Lecture # 5
Algorithm:
Insertion sort has a fast best-case running time and is a good sorting algorithm to use if the
input list is already mostly sorted. For larger or more unordered lists, an algorithm with a
faster worst and average-case running time, such as mergesort, would be a better choice.