Logout

4.3.8

Analyse the use of variables, constants and operators in algorithms.

 

Teaching Note:

For example, identify and justify the use of a constant as opposed to a variable in a given situation.

MYP Mathematics: forms of numbers, algebra—patterns and sequences, logic, algorithms.


 

Sample Question:

sdfsdfsf

JSR Notes:

So, from the Teaching Note, a constant should be used when we don't want the value to change, or indeed if a change in the variable would potentially cause a problem. A good example here is the length of an array. Meantime, a variable will be a value we either expect will change, or don't mind if it does change.


private static final ARRAYLENGTH = 100; private static int counter = 0; //The assumption here is that a counter variable is one to keep track //of an value which incrementes up by 1 each time through a looping structure.

The use of most operators most of the time is straight-forward. But there is one notable exception, both in terms of the problems it can cause, and the preferences of the IB. The ++ and -- and += and -= etc. operators can have unexpected results when included in complex expressions. So it is actually better to not use them at all, outside of loops and simple counters.

***Note this for the answering of IBCS examination questions; even for simple counters, you should instead, use:


counter = counter + 1;

More examples could go here, but likely this kind of thing will be in the context of a larger question, the kind in which you are tracing, finding a problem and offering a suggestion. So the suggestion might be, "make the variable a constant", or "change the variable from being a constant", for example.

Refer also to the examples with the next assessment statement, 4.3.9.