What is the Comparison Based Sorting in DSA? with Free Notes

What is Comparison Based Sorting ???

Comparison Based Sorting Algorithms sort data by comparing elements their code. Here are some commonly use comparisons based sorting algorithms.

1. Bubble Sort

Bubble Sort is the simple Algorithm that repeatedly steps through the list, compare adjacent elements and swaps them if they are in the wrong order. This process continues until no more swaps are needed, indicating that the list is sorted.

  • Complexity : – O(n2)
  • Stability : – Stable
  • In-Place: – Yes
  • Adaptiveness: – Can be adaptive if a optimized version is used (by stopping if no swaps are made in pass).

2. Selection Sort

Selection Sort works by repeatedly finding the minimum elements from the unsorted portion and moving it to the beginning. It divides the list into a sorted and an unsorted region and incrementally expands the sorted region.

  • Complexity : – O(n2)
  • Stability : – Not Stable
  • In – Place: – Yes
  • Adaptiveness: – Not Adaptive’

3. Insertion Sort

Insertion Sort builds the final sorted array one item at a time. It takes each element from the input and finds the correct position within the sorted portion, then inserts it there. This Algorithms is similar to sorting playing cards by hand.

  • Complexity : – O(n2)
  • Stability : – Stable
  • In – Place: – Yes
  • Adaptiveness : – Adaptive

4. Quick Sort

Quick Sort is a divide and conquer algorithms. It selects a “pivot” element, partitions the array into elements less than the pivot and elements greater than the pivot, and recursively sorts the partitions. The pivot is the its final position.

  • Complexity: – Average Case O(n log n), Worst Case O(n2)
  • Stability: – Not Stable
  • In-Place: – Yes
  • Adaptiveness: – Not Adaptive

5. Merge Sort

Merge Sort is a stable, divide – and – conquer algorithms that divides the array into halves, recursively sorts each half, and then merges the sorted halves to produce a single sorted list.

  • Complexity : – O (n log n)
  • Stability: – Stable
  • In – Place: – No (requires additional space for merging).
  • Adaptiveness: – Not Adaptive

6. Heap Sort

Heap Sort involves building a binary heap from input data and then repeatedly extracting the maximum element from the heap and rebuilding the heap. This process continues until all elements are sorted.

  • Complexity:- O ( n log n)
  • Stability : – Not Stable
  • In – Place: – Yes
  • Adaptiveness: – Not Adaptive

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top