COSC 130: Data Structures

Sorting Algorithms

Insertion Sort Example:

Initial Array: [6, 8, 3, 2, 7, 5, 1, 4]

First Iteration: [6][ 8, 3, 2, 7, 5, 1, 4]


Step-by-Step Process:


Iteration 1 (Index 1: 8):


Iteration 2 (Index 2: 3):


Iteration 3 (Index 3: 2):


Iteration 4 (Index 4: 7):


Iteration 5 (Index 5: 5):


Iteration 6 (Index 6: 1):


Iteration 7 (Index 7: 4):


Final Sorted Array:

[1, 2, 3, 4, 5, 6, 7, 8]


Summary of Key Points: