You are Here: Home >< Maths

# D1 HELP Watch

1. My textbook says that the maximum no. of comparisons for bubble sort is 0.5n(n-1). Is this only true if the list is in reverse? For example you has sort the list (1,2,3,4,5,6,7,8,9,10) form largest to smallest would it take 0.5*10*9=45 comparisons.

For example, the answer to question 1(iii) is 5+4+3+2+1=15 (https://drive.google.com/file/d/0B6v...R3anBXSTg/view)

How are we meant to know how many comparisons there are in each pass. Also, wouldn't the answer only be 15 if the list was in reverse?

Thanks
2. bump
3. You find the comparisons by listing the comparisons for each pass when you are sorting. Theres no easy way. I think the max number of comparisons
0.5(n)(n-1) is the formula for total passes not one passes and it asks for total number of comparisons. Not 100% sure tho.
4. (Original post by SWISH99)
My textbook says that the maximum no. of comparisons for bubble sort is 0.5n(n-1). Is this only true if the list is in reverse? For example you has sort the list (1,2,3,4,5,6,7,8,9,10) form largest to smallest would it take 0.5*10*9=45 comparisons.

For example, the answer to question 1(iii) is 5+4+3+2+1=15 (https://drive.google.com/file/d/0B6v...R3anBXSTg/view)

How are we meant to know how many comparisons there are in each pass. Also, wouldn't the answer only be 15 if the list was in reverse?

Thanks
Comparisons is n-1 per pass. You do a comparison for each pair next to each other and you look at every one per pass so it's the total numbers in that pass -1.
5. (Original post by fpmaniac)
You find the comparisons by listing the comparisons for each pass when you are sorting. Theres no easy way. I think the max number of comparisons
0.5(n)(n-1) is the formula for one pass not all passes and it asks for total number of swaps. Not 100% sure tho.
No thats total comparisons. For each pass its n-1 (n is remaining numbers).
6. (Original post by Vikingninja)
No thats total comparisons. For each pass its n-1 (n is remaining numbers).
Oops, Wrote it the other way round. Also wrote swaps instead of comparisons lol.
7. (Original post by fpmaniac)
Oops, Wrote it the other way round. Also wrote swaps instead of comparisons lol.
Ive forgotten how to derive the equation since I've only ever seen it once which was a show that question but the 0.5n gives the average comparisons per pass and n-1 is the number of passes.
8. (Original post by Vikingninja)
Comparisons is n-1 per pass. You do a comparison for each pair next to each other and you look at every one per pass so it's the total numbers in that pass -1.
so its n-1 per pass in every situation?
9. (Original post by SWISH99)
so its n-1 per pass in every situation?
Yes where n is what is remaining. Though a well sorted listed at the start before doing bubble sort can terminate early in terms of passes.

Also your equation for max comparisons is when its completely in reverse.
10. (Original post by Vikingninja)
Yes where n is what is remaining. Though a well sorted listed at the start before doing bubble sort can terminate early in terms of passes.

Also your equation for max comparisons is when its completely in reverse.
thanks,
but why does the equation still apply for the example i posted even though the list is not in reverse?
11. (Original post by SWISH99)
thanks,
but why does the equation still apply for the example i posted even though the list is not in reverse?
Looked at the thing again. It's because of that 4 on the right hand side, it needs to be taken from the far right to the far left so max number of passes are needed so max number of comparisons.

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: June 14, 2016
Today on TSR

### Oxford interview invitations

When can you expect yours?

### Official Cambridge interview invite list

Discussions on TSR

• Latest
• ## See more of what you like on The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

• Useful resources

## Make your revision easier

### 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

Can you help? Study help unanswered threads

## Groups associated with this forum:

View associated groups
Discussions on TSR

• Latest
• ## See more of what you like on The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

• The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.