Sorting Algorithms
Bubble Sort
- Compare adjacent elements and swap them when they are out of order.
- After each pass, the largest remaining value moves to the end.
Insertion Sort
- Take the next element and move it left until it reaches its correct position in the sorted prefix.
- Efficient for small or nearly sorted inputs.
Selection Sort
- Find the smallest remaining element.
- Swap it into the next position of the sorted prefix.
Merge Sort
- Split the list recursively into halves.
- Merge the sorted halves back together.
Quick Sort
- Choose a pivot and partition values around it.
- Recursively sort the left and right partitions.
Counting Sort
- Count occurrences of each value.
- Reconstruct the sorted output from those counts.
Radix Sort
- Process numbers digit by digit.
- Use a stable counting step for each place value.
Bucket Sort
- Distribute values into range-based buckets.
- Sort each bucket and concatenate the results.
Heap Sort
- Build a max heap.
- Repeatedly move the root to the end and restore the heap.
Shell Sort
- Apply insertion-sort-like passes using decreasing gaps.
- Finish with a standard gap of one.
Bubble Sort
- Komşu elemanları karşılaştırır ve yanlış sıradaysa yer değiştirir.
- Her geçişte en büyük kalan değer sona taşınır.
Insertion Sort
- Sıradaki elemanı alır ve sıralı ön bölümde doğru yerine kadar sola taşır.
- Küçük veya neredeyse sıralı dizilerde etkilidir.
Selection Sort
- Kalan bölümdeki en küçük elemanı bulur.
- Bu elemanı sıralı bölümün sıradaki konumuna taşır.
Merge Sort
- Listeyi özyinelemeli olarak ikiye böler.
- Sıralı alt listeleri tekrar birleştirir.
Quick Sort
- Bir pivot seçer ve değerleri pivotun çevresinde böler.
- Sol ve sağ bölümleri özyinelemeli olarak sıralar.
Counting Sort
- Her değerin kaç kez geçtiğini sayar.
- Sayım sonuçlarından sıralı diziyi yeniden oluşturur.
Radix Sort
- Sayıları basamak basamak işler.
- Her basamak için kararlı bir sayma adımı uygular.
Bucket Sort
- Değerleri aralıklara göre kovalara dağıtır.
- Her kovayı sıralayıp sonuçları birleştirir.
Heap Sort
- Bir max-heap oluşturur.
- Kökü tekrar tekrar sona taşıyıp heap yapısını yeniden kurar.
Shell Sort
- Azalan aralıklarla insertion sort benzeri geçişler yapar.
- Son geçişte aralık bire düşer.
| Algorithm | Best | Average | Worst | Auxiliary Space |
|---|---|---|---|---|
| Bubble | O(n) | O(n²) | O(n²) | O(1) |
| Insertion | O(n) | O(n²) | O(n²) | O(1) |
| Selection | O(n²) | O(n²) | O(n²) | O(1) |
| Merge | O(n log n) | O(n log n) | O(n log n) | O(n) |
| Quick | O(n log n) | O(n log n) | O(n²) | O(log n) avg. |
| Counting | O(n+k) | O(n+k) | O(n+k) | O(n+k) |
| Radix | O(d(n+k)) | O(d(n+k)) | O(d(n+k)) | O(n+k) |
| Bucket | O(n+k) | O(n+k) | O(n²) | O(n+k) |
| Heap | O(n log n) | O(n log n) | O(n log n) | O(1) |
| Shell | depends on gaps | depends on gaps | O(n²) | O(1) |
Ready.