Results are out! Find what you need...fast. Get quick advice or join the chat
x

Unlock these great extras with your FREE membership

  • One-on-one advice about results day and Clearing
  • Free access to our personal statement wizard
  • Customise TSR to suit how you want to use it

Dry Run an Algorithm

Announcements Posted on
Had your SQA results? Find your uni forum to get talking to other applicants, existing students and your future course-mates 04-08-2015
Competition: win a karting session for you and seven mates! 24-07-2015
  1. Offline

    ReputationRep:
    I seriously dont understand this, my teacher has gone over it but i still cant get the suss of it. Could anyone help explain how these work?

    This is the sort of question related to them that i've found on past papers:

  2. Offline

    ReputationRep:
    it basically means to run the code through in your head and fill in the trace table to show how the variables change.

    left arrow means "is assigned to"
  3. Offline

    ReputationRep:
    Thanks iainmacn, it makes sense now , sort of :P
  4. Offline

    ReputationRep:
    That is pretty damn complicated. I can't imagine how I would manage to do that in the pressure of an exam. Usually they're a lot simpler than that.
  5. Offline

    ReputationRep:
    take it a piece at a time, and don't get too bogged down in tracing individual steps. Try to get an idea in your head of what each loop is doing first.

    ptr <-- ptr + 1

    adds one to pointer.

    So - basically move up the array from 1 until you find a value less than the value of the variable new.

    onto the second loop

    values[last+1] <-- values[last]

    shifts the value one slot down the array

    so - move values[3] into values[4] (last is 3 at the start)

    now take one off last, so it's 2

    move values[2] into values[3]

    keep doing that until last matches ptr

    overwrite the value in values[ptr] with the contents of variable new

    What it's basically doing is inserting a new value into the array at the correct position. The top loop finds the position, the second loop shuffles stuff down the array to make room for it, the last statement inserts the new value into the gap.

    HTH
  6. Offline

    ReputationRep:
    (Original post by falc0n)
    I seriously dont understand this, my teacher has gone over it but i still cant get the suss of it. Could anyone help explain how these work?

    This is the sort of question related to them that i've found on past papers:

    What paper is this from?

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. By joining you agree to our Ts and Cs, privacy policy and site rules

  2. Slide to join now Processing…

Updated: June 7, 2010
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
SQA students: did you get the results you wanted today?
Results and Clearing

SQA results chat

Come talk about your results here

new on tsr

Indian? Join the society here

Take part in the chat and make friends

x

Think you'll be in clearing or adjustment?

Hear direct from unis that want to talk to you

Get email alerts for university course places that match your subjects and grades. Just let us know what you're studying.

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