There are n students standing in a line. The students have to rearrange themselves in ascending order of their roll numbers. This rearrangement must be accomplished only by successive swapping of adjacent students.

(i) Design an algorithm for this purpose that minimises the number of swaps required.

(ii) Derive an expression for the number of swaps needed by your algorithm in the worst case.