0% found this document useful (0 votes)
2 views3 pages

Sort

The document outlines five sorting algorithms: Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, and Quick Sort, detailing their advantages and disadvantages. Each algorithm is evaluated based on time complexity, space requirements, stability, in-place capability, and best use cases. Overall, it highlights the trade-offs between simplicity and efficiency for different datasets.

Uploaded by

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

Sort

The document outlines five sorting algorithms: Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, and Quick Sort, detailing their advantages and disadvantages. Each algorithm is evaluated based on time complexity, space requirements, stability, in-place capability, and best use cases. Overall, it highlights the trade-offs between simplicity and efficiency for different datasets.

Uploaded by

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

1.

Bubble Sort

 Advantages:

o Simple to implement.

o Good for educational purposes.

o Detects already sorted arrays early (with optimization).

 Disadvantages:

o Very ine icient for large datasets (O(n²) time complexity).

o Not suitable for performance-critical applications.

2. Selection Sort

 Advantages:

o Simple to understand and implement.

o Performs well on small lists.

o Requires no additional memory (in-place).

 Disadvantages:

o Ine icient for large datasets (O(n²)).

o Does not adapt to the input (e.g., partially sorted arrays).

3. Insertion Sort

 Advantages:

o E icient for small or nearly sorted datasets.

o Stable sort.

o In-place (no extra space required).

o Simple implementation.

 Disadvantages:

o O(n²) in the worst case (e.g., reverse sorted arrays).

o Not e icient for large datasets.


4. Merge Sort

 Advantages:

o Time complexity is always O(n log n), even in the worst case.

o Stable sort.

o Good for linked lists and external sorting (e.g., large files on disk).

 Disadvantages:

o Requires O(n) extra space.

o Slower for small datasets compared to in-place sorts.

5. Quick Sort

 Advantages:

o Very e icient in practice (average case O(n log n)).

o In-place (uses less memory than merge sort).

o Fastest general-purpose sorting algorithm in many scenarios.

 Disadvantages:

o Worst-case time complexity is O(n²) (can be mitigated with good pivot


selection).

o Not stable.

o Performance degrades with poorly chosen pivots.

Summary Table:

Algorithm Time (Avg) Space Stable In-place Best Use Case

Bubble Sort O(n²) O(1) Yes Yes Educational purposes

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

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

Merge Sort O(n log n) O(n) Yes No Linked lists, large datasets

Quick Sort O(n log n) O(log n) No Yes General-purpose, fast sorting

You might also like