Design and Analysis of Algorithms20785 marksSorting Algorithms
Write the algorithm for bubble sort and explain its time complexity.
Write the algorithm for bubble sort and explain its time complexity. [5]
Idea: Repeatedly compare adjacent elements and swap them if they are in the wrong order. After each pass, the largest unsorted element "bubbles up" to its correct position. 1. Start from the beginning of the array. 2. Compare adjacent elements A[j] and A[j+1]. 3. If A[j] A[j+1], swap them; otherw...