In: Computer Science
Rank the algorithms from slowest to fastest. .
Bubble Sort
Linear Search
Binary Search
Shellsort
Here is the answer to your following question --- slowest to fastest
Hope it helps, if any queries please ask in the comment section. Upvoting will be really helpful Thanks :)
Note that we will only compare the above algorithms according to the worst time complexity taken by these algorithms.
1. Bubble Sort - It is an O(n2) algorithm (worst case time complexity) because it the simplest algorithm for sorting which swaps the adjacent elements repeatedly if they are present in an incorrect way. It is the slowest algorithm of the above algorithms mentioned
2. Shell Sort - This sorting algorithm's time complexity is also O(n2) algorithm (worst case time complexity) but it is
faster than bubble sort as it applies intertion sort by dividing the arrays, so there is slight less comparison of elements as compared to Bubble sort
3. Linear Search - Next comes linear search whose worst case time complexity is linear i.e O(n) as it will compare all the elements from starting to ending once in worst case. It is much faster than Bubble sort and Shell sort.
4. Binary Search - It is the fastest algorithms among all the mentioned above. If you are given an sorted array and we do not consider the time taken for sorting .We can search for an element in the array in O(log2N) time as it is a divide and conquor algorithm and only consider half of the elements each time. If we consider the time for sorting, then it may vary as sorting will take O(nlogn) which when compares to Linear Search becomes slower. Depending on the whether you consider the time for sorting or not the time complaxity may vary.