Computer Scienc2
Computer Scienc2
Detailed Explanation:
1. Bubble Sort:
o A simple sorting algorithm that compares adjacent elements and swaps them if
they are in the wrong order.
o Time Complexity: O(n2)O(n^2)O(n2).
o Example: Sorting an array by repeatedly swapping adjacent elements that are
out of order.
2. QuickSort:
o A divide-and-conquer algorithm that partitions the array into sub-arrays and
recursively sorts them.
o Time Complexity: Best and Average Case O(nlogn)O(n \log n)O(nlogn),
Worst Case O(n2)O(n^2)O(n2).
o Example: Partitioning an array around a pivot and sorting the left and right
sub-arrays.
3. Merge Sort:
o A stable sorting algorithm that divides the array into halves, recursively sorts
them, and then merges the sorted halves.
o Time Complexity: O(nlogn)O(n \log n)O(nlogn).
o Example: Sorting large datasets efficiently.