Bubble Sort VS Selection Sort Sorting Algorithms
Sorting algorithms are crucial tools for arranging data in a systematic and orderly manner in the enormous ocean of computer science and algorithmic effectiveness. They are essential to many applications, from databases and search engines to commonplace jobs like compiling lists or organizing information tables. Bubble Sort and Selection Sort are two foundational techniques that stand as cornerstones of simplicity and efficiency among the myriad sorting algorithms.
In this essay, we compare these two sorting methods in an effort to comprehend their inner workings, advantages, and disadvantages. It will become clearer when and why one algorithm might be preferred over the other as we delve into the inner workings of Bubble Sort and Selection Sort. So buckle up as we set sail into the realm of sorting algorithms, navigating the waters of Bubble Sort and Selection Sort to assist you in making wise decisions in your coding endeavors.
Bubble Sort
- traverse from left and compare adjacent elements and the higher one is placed at right side.
- In this way, the largest element is moved to the rightmost end at first.
- This process is then continued to find the second largest and place it and so on until the data is sorted.
How does Bubble Sort Work?
Selection Sort
How does selection sort works ?
- For the first position in the sorted array, the whole array is traversed from index 0 to 4 sequentially. The first position where 64 is stored presently, after traversing whole array it is clear that 11 is the lowest value.
- Thus, replace 64 with 11. After one iteration 11, which happens to be the least value in the array, tends to appear in the first position of the sorted list.
- Now, for third place, where 25 is present again traverse the rest of the array and find the third least value present in the array.
- While traversing, 22 came out to be the third least value and it should appear at the third place in the array, thus swap 22 with element present at third position.
- Similarly, for fourth position traverse the rest of the array and find the fourth least element in the array
- As 25 is the 4th lowest value hence, it will place at the fourth position.
- At last the largest value present in the array automatically get placed at the last position in the array
- The resulted array is the sorted array.
- In bubble sort, two adjacent elements are compared. If the adjacent elements are not at the correct position, swapping would be performed, while in Selection Sort the minimum element is selected from the array and swap with an element which is at the beginning of the unsorted sub array.
- The Bubble Sort, The time complexities in best case and worst case are O(n) and O(n2) respectively, while in Selection Sort both best and worst cases is O(n 2).
- Bubble Sort is not an efficient sorting technique, while Selection Sort is an efficient sorting technique as compared to Bubble sort.
- Bubble Sort uses an exchanging method, while Selection Sort uses a selection method
- Bubble Sort is slower than the selection sort as a greater number of comparisons is required
~Rizki
As an ORE assignment to fulfill CCIT-FTUI's requirement
Source :
https://www.geeksforgeeks.org/bubble-sort/
https://www.javatpoint.com/bubble-sort-vs-selection-sort
Comments
Post a Comment