D1 HELP

Announcements Posted on
Four things that unis think matter more than league tables 08-12-2016
    • Thread Starter
    Offline

    0
    ReputationRep:
    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
    • Thread Starter
    Offline

    0
    ReputationRep:
    bump
    Offline

    2
    ReputationRep:
    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.
    Offline

    3
    ReputationRep:
    (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.
    Offline

    3
    ReputationRep:
    (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).
    Offline

    2
    ReputationRep:
    (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.
    Offline

    3
    ReputationRep:
    (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.
    • Thread Starter
    Offline

    0
    ReputationRep:
    (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?
    Offline

    3
    ReputationRep:
    (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.
    • Thread Starter
    Offline

    0
    ReputationRep:
    (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?
    Offline

    3
    ReputationRep:
    (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.
 
 
 
Write a reply… Reply
Submit reply

Register

Thanks for posting! You just need to create an account in order to submit the post
  1. this can't be left blank
    that username has been taken, please choose another Forgotten your password?
  2. this can't be left blank
    this email is already registered. Forgotten your password?
  3. this can't be left blank

    6 characters or longer with both numbers and letters is safer

  4. this can't be left empty
    your full birthday is required
  1. Oops, you need to agree to our Ts&Cs to register
  2. Slide to join now Processing…

Updated: June 14, 2016
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.

Poll
Do you think you'll achieve your predicted A Level grades?
Useful resources

Make your revision easier

Maths

Maths Forum posting guidelines

Not sure where to post? Read here first

Equations

How to use LaTex

Writing equations the easy way

Student revising

Study habits of A* students

Top tips from students who have already aced their exams

Study Planner

Create your own Study Planner

Never miss a deadline again

Polling station sign

Thinking about a maths degree?

Chat with other maths applicants

Can you help? Study help unanswered threads

Groups associated with this forum:

View associated groups
Study resources

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

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