Home > Other stuff > Trace tables question

Trace tables question

Below is the question you did in class on Tuesday, along with a full answer.

Things you need to take away from this are:

  • You would obviously not be expected to colour-code your answer. I have only done this to make it easier for you to see what is going on.
  • The first question asks you to show the array contents after each iteration of the loop. This is all you really need to do for this question. You don’t need to show N, K or K < N – 1. However, showing those variables might help you avoid mistakes.
  • Note that I have generally provided more than the minimum amount of information for each question. This is a “belt and braces” approach. It is good exam technique.
  • Read the question! Some of you didn’t show the contents of the array!
  • Note the standard technique for reversing an array in-place.
  • Be careful with the number of loop iterations.
  • For part c, It is not good enough that the loop condition should be K < N – 2, because that will only work for an array of this length! You must generalise. In general then, you need to go halfway into the array to make sure you have reversed it, and so the condition should be K <= N/2.

 
Trace tables Q&A

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s