Fundamentals 9 min read

Master 8 Essential Sorting Algorithms: From Insertion to Radix

This article introduces eight fundamental internal sorting algorithms—Insertion, Shell, Selection, Heap, Bubble, Quick, Merge, and Radix—explaining their mechanisms, visual illustrations, and analyzing their time and space complexities to help readers choose the appropriate method for different data sets.

Java Backend Technology
Java Backend Technology
Java Backend Technology
Master 8 Essential Sorting Algorithms: From Insertion to Radix
Sorting can be classified into internal sorting (all records fit in memory) and external sorting (requires external storage). The following algorithms are internal sorts.

8 Major Sorting Algorithms Explained

Insertion Sort

In a list where the first (n‑1) elements are already sorted, the nth element is inserted into its correct position among the sorted part, repeating until the whole list is ordered.

Shell Sort (Diminishing Increment Sort)

The list is divided into groups based on a gap d (initially n/2). Each group undergoes insertion sort, then the gap is reduced (d/2) and the process repeats until the gap becomes 1, after which a final insertion sort completes the ordering.

Selection Sort

The smallest element is selected and swapped with the first position, then the next smallest is swapped with the second position, and so on until the list is sorted.

Heap Sort

Heap sort builds a binary heap (max‑heap) from the array, repeatedly swaps the root (largest element) with the last element of the heap, reduces the heap size, and restores the heap property, resulting in a sorted sequence.

Bubble Sort

Adjacent elements are compared and swapped if they are in the wrong order, causing larger elements to "bubble" to the end of the list with each pass.

Quick Sort

A pivot element (often the first or last) partitions the array into elements less than the pivot and elements greater or equal, then the sub‑arrays are recursively sorted.

Merge Sort

Merge sort divides the array into sorted sub‑arrays and then merges them to produce a fully sorted array.

Radix Sort

All numbers are padded to the same length. Starting from the least significant digit, a stable sort is performed on each digit position, resulting in a sorted list after the most significant digit is processed.

Algorithm Complexity Details

Time Complexity

Time complexity describes how the execution time grows with input size n, expressed using Big‑O notation such as O(1), O(log n), O(n), O(n log n), O(n²), O(n³), O(2ⁿ), etc.

Worst‑case time complexity is usually discussed; average‑case complexity considers all inputs with equal probability.

Space Complexity

Space complexity measures the memory required by an algorithm, including a fixed part (code, constants, static variables) and a variable part (dynamic allocations, recursion stack). It is expressed as S(n)=O(f(n)).

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

algorithm complexityinsertion sortmerge sortQuick Sort
Java Backend Technology
Written by

Java Backend Technology

Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.