Insertion sort
Builds on Sorting algorithm
Definition
Let be a totally ordered set. Let and let be a sorted sequence over . Let be the largest index in with or . The insertion of into is the sequence . Insertion sort is the sorting algorithm that, on input , starts with the empty sequence . For it lets be the insertion of into , and it returns .
Remarks
In the usual array version, is found by comparing with from the right and shifting each larger element one place. The number of shifts equals the number of inversions of the input, the pairs with . So the running time is , where is the number of inversions; it is on the reversed list, which has inversions. Inserting after all equal elements makes the algorithm stable.
Example: on one gets , since , and , since for .
Non-example: appending each at the end of instead of at position just copies the input, and stays unsorted.
Reading path
To understand this page from the ground up, read these 2 pages in order. The foundations come first.
Show the path as a graph
- no evidence level
- Sorting algorithm concept
- Insertion sort definition
Further reading
About this page
| Tag | 5DYWS7DVQJ |
|---|---|
| URI | m2://5DYWS7DVQJ |
| Kind | definition |
| Writing | W0 stub |
| MSC | 68P10, 68W40 |
| Defines | Insertion sort |
| Uses | Sorting algorithm |
| Changed | 3 November 2026 |
Markdown · JSON · Edit on GitHub
What this page needs for W1
- an inventory row: the row of the inventory that the node accounts for (0 of 1)
- a source with a locator (0 of 1)
The writing levels say how complete the text of a page is. They do not measure its truth.
What links here
No page links to this page yet.