- #1
phospho
- 251
- 0
Q: Find the maximum number of interchanges needed to sort a list of six pieces of data using the bubble-sort algorithm
working:
for the first past, maximum needed is n-1 swaps where n is the amount of the pieces of data
2nd - n-2
3rd - n-3
4th - n-4
5th - n-5
so generally it takes
(n-1) + (n-2) +... (n-(n-1))
is this correct? It works for six as the it will be a maximum of 15 swaps, also how can I generalise this?
working:
for the first past, maximum needed is n-1 swaps where n is the amount of the pieces of data
2nd - n-2
3rd - n-3
4th - n-4
5th - n-5
so generally it takes
(n-1) + (n-2) +... (n-(n-1))
is this correct? It works for six as the it will be a maximum of 15 swaps, also how can I generalise this?