Skip to main content

Posts

Showing posts with the label Bubble Sort and Selection Sort in C

Bubble Sort and Selection Sort in C

Sorting is nothing but arranging the data in ascending or descending order. The term sorting came into picture, as humans realized the importance of searching quickly. sorting allows everyone to arrange data in an order, hence making it easier to search. Bubble Sort Algorithm Bubble Sort is a simple algorithm which is used to sort a given set of n elements. Bubble Sort compares all the element one by one and sort them based on their values. Watch the video for the demo  https://www.youtube.com/watch?v=yIQuKSwPlro If the given array has to be sorted in ascending order, then bubble sort will start by comparing the first element of the array with the second element, if the first element is greater than the second element, it will swap both the elements, and then move on to compare the second and the third element, and so on. If we have total n elements, then we need to repeat this process for n-1 times. But it is noted that when the array is sorted , comparing adjacent element does