Bubble sort algorithm requires a pair of nested loops. The outer loop must iterate once for each element for the given elements i.e. n times while the inner loop iterates n times for first iteration, n - 1 time for second iteration, n - 2 times for the third iteration and this process continues.
Total number of comparison = (n - 1) + (n - 2) + (n - 3) + … = n(n - 1)/2
= 5(4)/2
= 20/2
= 10