Array sorting is a fundamental topic in Data Structures and Algorithms (DSA). Different sorting algorithms are chosen based on factors like complexity, stability, and data size. Below are brief descriptions along with examples:
Bubble Sort: Repeatedly compares adjacent elements and swaps them if they are in the wrong order. Example: [5, 3, 8, 4] → [3, 5, 4, 8] after one full pass.
Selection Sort: Finds the minimum element from the unsorted portion and swaps it with the first unsorted element. Example: [64, 25, 12, 22, 11] → [11, 25, 12, 22, 64] after the first iteration.
Insertion Sort: Builds the sorted array one element at a time by inserting each new element into its correct position. Example: [12, 11, 13, 5, 6] → After inserting 11 in the correct place, and so on.
Merge Sort: A divide-and-conquer algorithm that splits the array into halves, sorts each half, and merges them. Example: [38, 27, 43, 3, 9, 82, 10] → [3, 9, 10, 27, 38, 43, 82] after complete merging.