All revision notes topics

Algorithms and flowchartsIB MYP Maths Extended: Revision notes

Section 1

What is an algorithm?

An algorithm is a precise list of steps to solve a problem or complete a task. It has an input (the starting values), a process (the steps) and an output (the result). The steps must be clear, in the right order, and always finish. Everyday examples are a recipe or the method for long division. In maths, algorithms are used to calculate values, generate sequences and solve equations.

Key termsalgorithminputoutput

Section 2

Flowcharts

A flowchart shows an algorithm as a diagram, with arrows showing the order. Standard shapes: an oval for start and stop, a parallelogram for input and output, a rectangle for a process (a calculation), and a diamond for a decision (a yes/no question with two exits). Follow the arrows from the start. In a written description, each box is a numbered step. A question about a flowchart can be given in words, such as: input xx, double it and subtract 33 to get yy; if y>10y>10, output 'Large', otherwise output yy.

Key termsflowchartdecision
Exam tip

Read the test carefully: y>10y>10 is false when y=10y=10, but y≥10y\ge10 would be true.

Section 3

Tracing an algorithm

To trace an algorithm, follow the steps with real numbers and record the values in a trace table, one row per pass. For n=5n=5, total=0total=0 (add nn to totaltotal, reduce nn by 11, repeat while n>0n>0): after each pass totaltotal is 55, 99, 1212, 1414, 1515, and nn is 44, 33, 22, 11, 00. When n=0n=0 the test n>0n>0 fails and the output is 1515. A loop repeats steps until a condition stops it. Count the passes carefully: here Step 2 runs 55 times, for n=5,4,3,2,1n=5,4,3,2,1.

Key termstrace tableloop
Common mistake

Stopping one pass early or one pass late. Decide whether the test happens before or after the value changes.

Section 4

Writing an algorithm

To write an algorithm: (1) say what the inputs are, (2) list the steps in order, using clear operations, (3) include any decision or repeat, (4) say what is output. Test it with an example you know. For the equation px+q=rx+spx+q=rx+s: input pp, qq, rr, ss; work out p−rp-r; work out s−qs-q; divide (s−q)(s-q) by (p−r)(p-r); output xx. With 5x+7=2x+225x+7=2x+22 this gives 15÷3=515\div3=5. Check by substituting back: 3232 on both sides.

Key termsvariable
Exam tip

Say what happens when something goes wrong, such as dividing by zero, and make the algorithm avoid it.

Section 5

Algorithms and sequences

An algorithm that repeats a rule generates a sequence. If u1=3u_1=3 and each term is twice the previous term plus 11, the terms are 3,7,15,31,63,127,255,511,…3,7,15,31,63,127,255,511,\ldots. You can spot a pattern: each term plus 11 is a power of 22 (4,8,16,32,…4,8,16,32,\ldots). A term-to-term rule (what to do to the previous term) is an algorithm. To find the first term greater than 500500, keep applying the rule until it is passed: 255<500<511255<500<511, so it is the 88th term. Other rules, such as 'start at 55 and add 33', give 5,8,11,…5,8,11,\ldots and the nnth term is 5+3(n−1)5+3(n-1).

Key termssequenceterm-to-term rule

Section 6

Algorithms and solving equations

Solving ax+b=cax+b=c is an algorithm: undo the operations in reverse order. Subtract bb from cc, then divide by aa. For 3x+5=293x+5=29: 29−5=2429-5=24, then 24÷3=824\div3=8. The algorithm fails if a=0a=0, because dividing by zero is undefined and the equation has no xx term. Working backwards through a flowchart uses the same idea: if a flowchart multiplies by 44 then subtracts 66 to output 1010, undo the steps in reverse: 10+6=1610+6=16, then 16÷4=416\div4=4.

Key termsinverse operation
Common mistake

Undoing the steps in the same order. Reverse the order as well as the operations.

That's the notes covered.

Carry on to the next subtopic.

Exam questions on Algorithms and flowcharts

  1. An algorithm is written in steps. Step 1: Set n=5n=5 and total=0total=0. Step 2: Add nn to totaltotal. Step 3: Reduce nn by 11. Step 4: If n>0n>0, go back to Step 2; otherwise output totaltotal and stop.
    Step 1 is changed to set n=8n=8. Find the new output.2 marks
  2. A flowchart takes a number xx as its input. Process: double xx and subtract 33 to get yy. Decision: if y>10y>10, output the word "Large"; otherwise output yy.
    Find the smallest whole number input that gives the output 'Large'.2 marks
  3. A sequence is generated by an algorithm. Step 1: Set the first term u1=3u_1=3. Step 2: To get the next term, multiply the previous term by 22 and then add 11. Step 3: Repeat Step 2 until the terms needed have been found.
    Use the algorithm to find the first five terms of the sequence.3 marks
See the full worksheet

Written by the Exaim team, led by Shaun Daswani (Head of Upper Secondary, Improve ME Institute; MSc Financial Mathematics, Imperial College London; BSc, UCL) and Jason Daswani (operational lead, Improve ME Institute; LSE).