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.
AlgorithmBestAverageWorstAuxiliary Space
BubbleO(n)O(n²)O(n²)O(1)
InsertionO(n)O(n²)O(n²)O(1)
SelectionO(n²)O(n²)O(n²)O(1)
MergeO(n log n)O(n log n)O(n log n)O(n)
QuickO(n log n)O(n log n)O(n²)O(log n) avg.
CountingO(n+k)O(n+k)O(n+k)O(n+k)
RadixO(d(n+k))O(d(n+k))O(d(n+k))O(n+k)
BucketO(n+k)O(n+k)O(n²)O(n+k)
HeapO(n log n)O(n log n)O(n log n)O(1)
Shelldepends on gapsdepends on gapsO(n²)O(1)

Ready.