Different Sorting Methodologies
Different Sorting Methodologies Introduction Sorting is one of the most important operations in computer science. Sorting means arranging elements in a particular order, usually ascending or descen...

Source: DEV Community
Different Sorting Methodologies Introduction Sorting is one of the most important operations in computer science. Sorting means arranging elements in a particular order, usually ascending or descending order. Sorting is used in searching, data analysis, databases, and many real-world applications. In this blog, we will discuss the different sorting algorithms taught in the session, their working methods, and time complexities. Bubble Sort Concept Bubble Sort repeatedly compares adjacent elements and swaps them if they are in the wrong order. The largest element “bubbles up” to the end of the array after each pass. Steps Compare first and second element If first > second → swap Move to next pair Repeat for entire array After each pass, largest element moves to the end Repeat until array is sorted Python Code arr = [5, 3, 8, 4, 2] n = len(arr) for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j] print(arr) Time Complexity Case Time