Table of Content


1. Selection Sort

Selection Sort is a simple and intuitive sorting algorithm. Imagine organizing a scattered pile of papers with numbers on them in ascending order. Selection Sort mimics this process by repeatedly selecting the smallest number and placing it in the correct position.

Selection Sort Process

Optimizing Selection Sort

Pseudo-Code

for i from 0 to n-2:
    minIndex = i
    for j from i+1 to n-1:
        if arr[j] < arr[minIndex]:
            minIndex = j
    swap arr[i] with arr[minIndex]

Analyzing Complexity

Conclusion

Selection Sort is a straightforward algorithm that performs well on small datasets. Its simplicity makes it a good choice for educational purposes, despite its O(N²) time complexity.


2. Bubble Sort

Bubble Sort is another simple sorting algorithm that is easy to understand. It repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order.

Bubble Sort Process

Pseudo-Code

n = size of array
for i from 0 to n-2:
    for j from 0 to n-2-i:
        if arr[j] > arr[j+1]:
            swap arr[j] with arr[j+1]