Insertion Sort: Difference between revisions
Appearance
Created page with "{{Infobox algorithm | name = Insertion sort | signature = <span class="eoa-proc">Insertion-Sort</span>(<span class="eoa-var">A</span>, <span class="eoa-var">n</span>) | code = # '''for''' <span class="eoa-var">i</span> = 2 '''to''' <span class="eoa-var">n</span> # {{I}}<span class="eoa-var">key</span> = <span class="eoa-var">A</span>[<span class="eoa-var">i</span>] # {{I}}<span class="eoa-var">j</span> = <span class="eoa-var">i</span> − 1 # {{I}}'''while''' <span c..." |
Add the algorithm. |
||
| Line 1: | Line 1: | ||
{{Stub}} | |||
{{Infobox algorithm | {{Infobox algorithm | ||
| name = Insertion sort | | name = Insertion sort | ||
| signature = | | signature = Insertion-Sort(A) | ||
| code = | | code = | ||
for i = 2 to A.length | |||
key = A[i] | |||
j = i - 1 | |||
while j > 0 and A[j] > key | |||
A[j + 1] = A[j] | |||
j = j - 1 | |||
A[j + 1] = key | |||
}} | }} | ||
Latest revision as of 19:33, 3 August 2026
This article is a stub. It might be missing pseudocode, complexity analysis, or a correctness sketch. It might need some other information which is incomplete perhaps.
Insertion sort
Insertion-Sort(A)
- for i = 2 to A.length
- key = A[i]
- j = i - 1
- while j > 0 and A[j] > key
- A[j + 1] = A[j]
- j = j - 1
- A[j + 1] = key