0% found this document useful (0 votes)
0 views

Sorting Algorithms Comparison

Uploaded by

sahil khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Sorting Algorithms Comparison

Uploaded by

sahil khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Comparison of Sorting

Algorithms
Understanding Key Differences in
Popular Sorting Methods
Introduction
• Sorting algorithms organize data in a specific
order (ascending/descending).
• They differ in:
• 1. Time Complexity
• 2. Space Complexity
• 3. Stability
• 4. Approach (Comparison-based/Non-
comparison-based)
Bubble Sort
• Definition: Repeatedly swaps adjacent
elements if they are in the wrong order.
• Best Time Complexity: O(n)
• Worst Time Complexity: O(n²)
• Space Complexity: O(1)
• Stable: Yes
• Suitable for: Small datasets, easy
implementation
Quick Sort
• Definition: Divides data into smaller partitions
around a pivot.
• Best Time Complexity: O(n log n)
• Worst Time Complexity: O(n²)
• Space Complexity: O(log n)
• Stable: No
• Suitable for: Large datasets, efficient
Insertion Sort
• Definition: Builds a sorted array one item at a
time.
• Best Time Complexity: O(n)
• Worst Time Complexity: O(n²)
• Space Complexity: O(1)
• Stable: Yes
• Suitable for: Small datasets, nearly sorted
arrays
Heap Sort
• Definition: Uses a binary heap to sort
elements.
• Best Time Complexity: O(n log n)
• Worst Time Complexity: O(n log n)
• Space Complexity: O(1)
• Stable: No
• Suitable for: Large datasets, priority queues
Selection Sort
• Definition: Repeatedly selects the smallest
element and moves it to the sorted portion.
• Best Time Complexity: O(n²)
• Worst Time Complexity: O(n²)
• Space Complexity: O(1)
• Stable: No
• Suitable for: Small datasets, simple to
implement
Shell Sort
• Definition: Generalized version of insertion
sort with gaps.
• Best Time Complexity: O(n log n)
• Worst Time Complexity: O(n²)
• Space Complexity: O(1)
• Stable: No
• Suitable for: Medium-sized datasets
Radix Sort
• Definition: Sorts numbers digit by digit (non-
comparison-based).
• Best Time Complexity: O(nk)
• Worst Time Complexity: O(nk)
• Space Complexity: O(n + k)
• Stable: Yes
• Suitable for: Large integers or strings
Merge Sort
• Definition: Divides the array into halves and
merges them in sorted order.
• Best Time Complexity: O(n log n)
• Worst Time Complexity: O(n log n)
• Space Complexity: O(n)
• Stable: Yes
• Suitable for: Large datasets, external sorting
Comparative Table
Algorithm Best Time Worst Time Space Stable Use Case

Bubble Sort O(n) O(n²) O(1) Yes Small datasets

Quick Sort O(n log n) O(n²) O(log n) No Large datasets

Insertion Sort O(n) O(n²) O(1) Yes Nearly sorted data

Heap Sort O(n log n) O(n log n) O(1) No Priority Queues

Selection Sort O(n²) O(n²) O(1) No Small datasets

Shell Sort O(n log n) O(n²) O(1) No Medium datasets

Radix Sort O(nk) O(nk) O(n + k) Yes Integers, strings

Merge Sort O(n log n) O(n log n) O(n) Yes Large datasets
Conclusion
• Sorting algorithms differ in their efficiency and
use cases.
• Choose based on:
• 1. Dataset size
• 2. Data structure
• 3. Time and space constraints

You might also like