Demo Assignmentt
Demo Assignmentt
1. Bubble Sort
Pros:
Cons:
Applications:
1. Educational purposes for teaching sorting logic.
2. Small datasets where simplicity is key.
2. Selection Sort
Pros:
1. Simple to understand and implement.
2. Requires minimal swaps .
3. Requires only a constant O(1) extra memory space .
Cons:
1. Selection sort has a time complexity of O(n2) makes it slower compared to other sorting algorithms.
2. Not stable.
Applications:
1. Good for small datasets.
2. Used when swap cost is expensive.
3. Ideal for teaching basic sorting concepts .
3. Insertion Sort
Pros:
1. Simple and intuitive.
2. If the array is nearly sorted, the algorithm performs fewer comparisons and shifts, making it faster than its
worst-case time complexity suggests .
3. Insertion sort is stable .
Cons:
1. The time complexity is O(n2) in the worst and average case, which makes it very inefficient for large
datasets.
2. As the size of the array increases, the algorithm becomes slower because it has to perform many
comparisons and shifts for each element.
Applications:
4. Merge Sort
Pros:
1. Consistent performance O (n log n).
2. Stable sort.
3. Works well with large datasets.
4. It is a divide-and-conquer algorithm that makes it easier to solve problems.
Cons:
1. Requires additional memory O (n).
2. Slower for small datasets.
Applications:
1. Sorting linked lists.
2. External sorting for large datasets that don’t fit in memory.
3. Merge Sort and its variations are used in library methods of programming languages.
5. Quick Sort
Pros:
1. It is a divide-and-conquer algorithm that makes it easier to solve problems.
2. Very fast on average O(n log n) .
3. In-place sorting .
4. Performs well with large datasets.
Cons:
1. Worst-case performance O(n2) when pivot choice is poor.
2. It is not a stable sort, meaning that if two elements have the same key, their relative order will not be
preserved in the sorted output in case of quick sort, because here we are swapping elements according to
the pivot’s position without considering their original positions .
3. It is not a good choice for small data sets.
Applications:
1. General-purpose sorting.
2. Sorting arrays where memory usage needs to be minimized.
3. Important in theoretical computer science for analyzing average-case complexity and developing
new techniques.
4. Applied in cryptography for generating random permutations and unpredictable encryption keys.
6. Bucket Sort
Pros:
1. Very fast for uniformly distributed data O(n).
2. Easy to parallelize.
Cons:
1. Requires prior knowledge of data distribution, as this information is needed to determine the size and
number of buckets needed.
2. Not suitable for large ranges of data.
Applications:
1. Sorting floating-point numbers or integers within a known range.
2. Histogram sorting.
7. Counting Sort
Pros:
1. Linear time complexity O(n + k) for small ranges.
2. Stable sort.
3. Counting sort is easy to code.
Cons:
1. Counting sort doesn’t work on decimal values.
8. Radix Sort
Pros:
1. Linear time complexity O(n⋅k)for small keys.
2. Stable sort.
Cons:
1. Requires a stable sub-sorting algorithm (e.g., counting sort).
2. Works only for data that can be digitized.
Applications:
1. Sorting strings, integers, or large datasets with uniform keys.
9. Heap Sort
Pros:
Cons:
1. Not stable.
2. Slower compared to quicksort in practice due to cache inefficiency.
Applications:
1. Priority queues.
2. Sorting in scenarios where memory usage is critical.