
Sorting Algorithms
– My Learning and Approach In this session, I learned about different sorting algorithms. At first, I thought sorting is just arranging numbers, but later I understood that how we sort matters a lot, especially when the data size is large. Here I am writing my understanding and the way I approached each sorting method. Why Sorting is Needed Before going into algorithms, I understood that sorting is useful because: It makes searching faster It helps to organize data clearly Many problems depend on sorted data 1. Bubble Sort – My Approach How I Thought First, I tried to compare each element with the next one. If the current element is greater, I swap it. By doing this again and again, the largest element automatically moves to the end. What I Observed After each iteration, one element gets fixed at the correct position. Code public void bubbleSort ( int [] arr ) { int n = arr . length ; for ( int i = 0 ; i < n - 1 ; i ++) { boolean swapped = false ; for ( int j = 0 ; j < n - i - 1 ; j ++
Continue reading on Dev.to
Opens in a new tab



