0% found this document useful (0 votes)
3 views1 page

Sorting Algorithms: Overview and Examples

Uploaded by

cavadovamin108
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Sorting Algorithms: Overview and Examples

Uploaded by

cavadovamin108
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Sorting Algorithms: Comparison and Examples

Algorithm Working Principle Example Steps Result


→ [3, 5, 4, 2, 8]
→ [3, 4, 2, 5, 8]
Bubble Sort Compares neighbors and swaps [5, 3, 8, 4, 2] [2, 3, 4, 5, 8]
→ [3, 2, 4, 5, 8]
→ [2, 3, 4, 5, 8]

→ [10, 29, 14, 37, 13]


Selection Sort Finds min and puts it at start [29, 10, 14, 37, 13] → [10, 13, 14, 37, 29] [10, 13, 14, 29, 37]
→ [10, 13, 14, 29, 37]

→ [2, 5, 4, 6, 1, 3]
→ [2, 4, 5, 6, 1, 3]
Insertion Sort Inserts each element in place [5, 2, 4, 6, 1, 3] [1, 2, 3, 4, 5, 6]
→ [1, 2, 4, 5, 6, 3]
→ [1, 2, 3, 4, 5, 6]

Split → [38, 27, 43] + [3, 9, 82, 10]


Merge Sort Divide array, sort parts, merge [38, 27, 43, 3, 9, 82, 10] [3, 9, 10, 27, 38, 43, 82]
Merge → [3, 9, 10, 27, 38, 43, 82]

Pivot=10
Left=[7, 8, 9, 1, 5]
Quick Sort Pivot chosen, left < pivot, right > pivot [10, 7, 8, 9, 1, 5] [1, 5, 7, 8, 9, 10]
Sort left → [1, 5, 7, 8, 9]
Merge → [1, 5, 7, 8, 9, 10]

You might also like