Turn on thread page Beta

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

    • Thread Starter
    Offline

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

    12
    ReputationRep:
    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
    Offline

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

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

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

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

    13
    ReputationRep:
    (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
 
 
 
Reply
Submit reply
Turn on thread page Beta
Updated: February 28, 2016

University open days

  1. University of Bradford
    University-wide Postgraduate
    Wed, 25 Jul '18
  2. University of Buckingham
    Psychology Taster Tutorial Undergraduate
    Wed, 25 Jul '18
  3. Bournemouth University
    Clearing Campus Visit Undergraduate
    Wed, 1 Aug '18
Poll
How are you feeling in the run-up to Results Day 2018?
Useful resources

Make your revision easier

Maths

Maths Forum posting guidelines

Not sure where to post? Read the updated guidelines here

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

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

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