Sorting Algorithms
This is an algorithm that works by distributing elements into several buckets, then sorting these buckets individually and then merging them to get a sorted result. Its particularly useful when the input is evenly distributed over a range. The worst-case time complexity is when most of the elements are placed in a single bucket as it leads to further sorting which takes longer.
Bubble sort
This is one of the simplest sorting algorithms. It repetitively steps through the list, compares adjacent elements, and swaps them if there in the wrong order. This process continues till the list is sorted. This makes it not time efficient for large lists or for an array to be in reverse order as these forces the algorithm to make the maximum number of comparisons and swaps.
Quick sort
This is one of the most efficient sorting algorithms and it uses a divide and conquer approach. It picks a pivot element and partition the array around the pivot placing elements smaller than the pivot to its left and larger elements to its right. I then recursively apply this process to the left and right subarrays until the entire array is sorted. The worst-case time complexity is when the chosen pivot is consistently the smallest or largest element in the array, which will lead to unbalanced partitioning’s.
This comment has been removed by the author.
ReplyDelete