Dry Run an Algorithm

Computer Science and ICT discussion, revision, exam and homework help.

Announcements Posted on
TSR launches Learn Together! - Our new subscription to help improve your learning 16-05-2013
IMPORTANT: You must wait until midnight (morning exams)/4.30AM (afternoon exams) to discuss Edexcel exams and until 1pm/6pm the following day for STEP and IB exams. Please read before posting, including for rules for practical and oral exams. 28-04-2013
Sign in to Reply
  1. falc0n's Avatar
    • Full Member
    • Location: UK
    • Posts: 99
    Dry Run an Algorithm
    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. iainmacn's Avatar
    • Overlord in Training
    • Location: London
    • Posts: 2,126
    Re: Dry Run an Algorithm
    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. falc0n's Avatar
    • Full Member
    • Location: UK
    • Posts: 99
    Re: Dry Run an Algorithm
    Thanks iainmacn, it makes sense now , sort of :P
  4. Azimuth's Avatar
    • Benevolent Member
    • Location: Canary Wharf
    • Posts: 664
    Re: Dry Run an Algorithm
    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. iainmacn's Avatar
    • Overlord in Training
    • Location: London
    • Posts: 2,126
    Re: Dry Run an Algorithm
    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. Dmanscoop's Avatar
    • Junior Member
    • Posts: 33
    Re: Dry Run an Algorithm
    (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?
Sign in to Reply
Share this discussion:  
Article updates
Moderators

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

Reputation gems:
The Reputation gems seen here indicate how well reputed the user is, red gem indicate negative reputation and green indicates a good rep.
Post rating score:
These scores show if a post has been positively or negatively rated by our members.