You are Here: Home >< Maths

# D1 - number of swaps of a list for 50 in a bubble sort watch

1. Book says it is .5*49*50=1225 using the summation formula.

But I have 0.5 * (1+50)*50=1275 :/
From Sn = 0.5(a+L)*n

So where have gone wrong, why is it 49 and not 51 smh.
2. AFAIK the relevant formula is 1/2n(n-1), not entirely sure though, it's been a while since I've covers D1

Posted from TSR Mobile
3. (Original post by Mihael_Keehl)
Book says it is .5*49*50=1225 using the summation formula.

But I have 0.5 * (1+50)*50=1275 :/
From Sn = 0.5(a+L)*n

So where have gone wrong, why is it 49 and not 51 smh.
On the first pass we have at most 49 swaps, on the second we have at most 48, and so on down to 1 on the final pass. Hence there are at most 49 + 48 + 47 +... + 1 swaps.
4. (Original post by 16Characters....)
On the first pass we have at most 49 swaps, on the second we have at most 48, and so on down to 1 on the final pass. Hence there are at most 49 + 48 + 47 +... + 1 swaps.
thnx so there is a different summation formula: Sk = k(k+1)*0.5 for the maximum number of swaps in a list for a bubble sort.
5. (Original post by Mihael_Keehl)
thnx so there is a different summation formula: Sk = k(k+1)*0.5 for the maximum number of swaps in a list for a bubble sort.
Yes that is the correct formula, with k = n-1 where n is the number of items in your list.
6. (Original post by 16Characters....)
Yes that is the correct formula, with k = n-1 where n is the number of items in your list.
thnx
7. (Original post by drandy76)
AFAIK the relevant formula is 1/2n(n-1), not entirely sure though, it's been a while since I've covers D1

Posted from TSR Mobile
yeah that sounds right thnx

### Related university courses

TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Updated: February 28, 2016
Today on TSR

How do you think you'll do?

### University open days

Wed, 25 Jul '18
2. University of Buckingham
Wed, 25 Jul '18
3. Bournemouth University
Wed, 1 Aug '18
Poll
Useful resources

### Maths Forum posting guidelines

Not sure where to post? Read the updated guidelines here

### How to use LaTex

Writing equations the easy way

### Study habits of A* students

Top tips from students who have already aced their exams