Compare with Quick Sort

Let’s run both algorithms on the exact same array and see step-by-step how they behave.

QUICK SORT vs SHELL SORT – Full Comparison with Same Array

QUICK SORT vs SHELL SORT – Full Comparison with Same Array

Let’s run both algorithms on the exact same array and see step-by-step how they behave.

Array: 45, 12, 78, 23, 56, 9, 67, 34, 89, 41

1. QUICK SORT (Pivot = Last Element)

| Step | Pivot | Partition Result (≤ pivot | pivot | > pivot) | Recursive Calls |
|------|-------|--------------------------------------------------|-----------------|
| 1 | 41 | 12, 23, 9, 34 | 41 | 45, 78, 56, 67, 89 |
| 2 | 34 | 12, 23, 9 | 34 | — (right empty) |
| 3 | 9 | — (left empty) | 9 | 12, 23 |
| 4 | 23 | 12 | 23 | — |
| 5 | 89 | 45, 78, 56, 67 | 89 | — |
| 6 | 67 | 45, 56 | 67 | 78 |
| 7 | 56 | 45 | 56 | — |

Final Sorted Array: 9, 12, 23, 34, 41, 45, 56, 67, 78, 89

Total Swaps in Partitioning: ~18–22 swaps (depends on exact implementation)

2. SHELL SORT (Gaps 5 → 2 → 1) – Recap

Pass Gap Array After Pass Total Swaps
1 5 9, 12, 34, 23, 41, 45, 67, 78, 89, 56 5 swaps
2 2 9, 12, 34, 23, 41, 45, 67, 56, 89, 78 1 swap
3 1 9, 12, 23, 34, 41, 45, 56, 67, 78, 89 3 swaps
9 swaps

HEAD-TO-HEAD COMPARISON TABLE

Feature Quick Sort Shell Sort Winner
Total Swaps (on this array) ~20 swaps Only 9 swaps Shell Sort
Comparisons ~45–55 ~60–70 Quick Sort
Worst-case Time O(n²) O(n¹·⁵) or better Shell Sort
Average Time O(n log n) O(n¹·³) – O(n¹·⁵) Quick Sort
Best-case Time O(n log n) Nearly O(n) if already grouped Shell Sort
Space Complexity O(log n) recursion stack O(1) – fully in-place Shell Sort
Stability Not stable Not stable Tie
Cache Performance Poor (random access) Excellent (sequential access) Shell Sort
Performance on Nearly Sorted O(n²) if bad pivots Very fast (few swaps) Shell Sort
Performance on Random Data Extremely fast (fastest in practice) Good, but slower than Quick Quick Sort
Recursive? Yes No Shell Sort
Online (can sort as data comes) No Yes Shell Sort

Visual Evolution Side-by-Side

After First Major Step Quick Sort (after 1st partition) Shell Sort (after gap=5)
Array 12 23 9 34 41 45 78 56 67 89 9 12 34 23 41 45 67 78 89 56
How "ordered" it looks Very mixed Already small numbers moved left

Real-World Verdict (2025 Knowledge)

Scenario Best Choice Reason
General-purpose sorting (libraries) Quick Sort (or Introsort) Fastest average case
Embedded systems / low memory Shell Sort No recursion, O(1) space
Nearly sorted or partially sorted Shell Sort Almost O(n)
Huge arrays (cache matters) Shell Sort Sequential access
Need guaranteed O(n log n) Merge/Heap Sort Quick can degrade
Competitive coding (random data) Quick Sort Usually fastest

Conclusion with this example:
- Shell Sort did 2× fewer swaps than Quick Sort
- Shell Sort used zero extra space, Quick Sort used recursion stack
- Shell Sort was more predictable and cache-friendly

Quick Sort wins on average random data
Shell Sort wins on this array and in memory-constrained or nearly-sorted cases

Perfect for exam answer:
"Although Quick Sort has better average time complexity, Shell Sort performed significantly better on this input with only 9 swaps vs ~20, and used no extra space or recursion."

You’re now 100% ready to compare them in viva or theory paper!

Last updated: Nov 28, 2025

Compare with Quick Sort

Let’s run both algorithms on the exact same array and see step-by-step how they behave.

QUICK SORT vs SHELL SORT – Full Comparison with Same Array

QUICK SORT vs SHELL SORT – Full Comparison with Same Array

Let’s run both algorithms on the exact same array and see step-by-step how they behave.

Array: 45, 12, 78, 23, 56, 9, 67, 34, 89, 41

1. QUICK SORT (Pivot = Last Element)

| Step | Pivot | Partition Result (≤ pivot | pivot | > pivot) | Recursive Calls |
|------|-------|--------------------------------------------------|-----------------|
| 1 | 41 | 12, 23, 9, 34 | 41 | 45, 78, 56, 67, 89 |
| 2 | 34 | 12, 23, 9 | 34 | — (right empty) |
| 3 | 9 | — (left empty) | 9 | 12, 23 |
| 4 | 23 | 12 | 23 | — |
| 5 | 89 | 45, 78, 56, 67 | 89 | — |
| 6 | 67 | 45, 56 | 67 | 78 |
| 7 | 56 | 45 | 56 | — |

Final Sorted Array: 9, 12, 23, 34, 41, 45, 56, 67, 78, 89

Total Swaps in Partitioning: ~18–22 swaps (depends on exact implementation)

2. SHELL SORT (Gaps 5 → 2 → 1) – Recap

Pass Gap Array After Pass Total Swaps
1 5 9, 12, 34, 23, 41, 45, 67, 78, 89, 56 5 swaps
2 2 9, 12, 34, 23, 41, 45, 67, 56, 89, 78 1 swap
3 1 9, 12, 23, 34, 41, 45, 56, 67, 78, 89 3 swaps
9 swaps

HEAD-TO-HEAD COMPARISON TABLE

Feature Quick Sort Shell Sort Winner
Total Swaps (on this array) ~20 swaps Only 9 swaps Shell Sort
Comparisons ~45–55 ~60–70 Quick Sort
Worst-case Time O(n²) O(n¹·⁵) or better Shell Sort
Average Time O(n log n) O(n¹·³) – O(n¹·⁵) Quick Sort
Best-case Time O(n log n) Nearly O(n) if already grouped Shell Sort
Space Complexity O(log n) recursion stack O(1) – fully in-place Shell Sort
Stability Not stable Not stable Tie
Cache Performance Poor (random access) Excellent (sequential access) Shell Sort
Performance on Nearly Sorted O(n²) if bad pivots Very fast (few swaps) Shell Sort
Performance on Random Data Extremely fast (fastest in practice) Good, but slower than Quick Quick Sort
Recursive? Yes No Shell Sort
Online (can sort as data comes) No Yes Shell Sort

Visual Evolution Side-by-Side

After First Major Step Quick Sort (after 1st partition) Shell Sort (after gap=5)
Array 12 23 9 34 41 45 78 56 67 89 9 12 34 23 41 45 67 78 89 56
How "ordered" it looks Very mixed Already small numbers moved left

Real-World Verdict (2025 Knowledge)

Scenario Best Choice Reason
General-purpose sorting (libraries) Quick Sort (or Introsort) Fastest average case
Embedded systems / low memory Shell Sort No recursion, O(1) space
Nearly sorted or partially sorted Shell Sort Almost O(n)
Huge arrays (cache matters) Shell Sort Sequential access
Need guaranteed O(n log n) Merge/Heap Sort Quick can degrade
Competitive coding (random data) Quick Sort Usually fastest

Conclusion with this example:
- Shell Sort did 2× fewer swaps than Quick Sort
- Shell Sort used zero extra space, Quick Sort used recursion stack
- Shell Sort was more predictable and cache-friendly

Quick Sort wins on average random data
Shell Sort wins on this array and in memory-constrained or nearly-sorted cases

Perfect for exam answer:
"Although Quick Sort has better average time complexity, Shell Sort performed significantly better on this input with only 9 swaps vs ~20, and used no extra space or recursion."

You’re now 100% ready to compare them in viva or theory paper!

Last updated: Nov 28, 2025