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.
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 , double it and subtract to get ; if , output 'Large', otherwise output .
Read the test carefully: is false when , but 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 , (add to , reduce by , repeat while ): after each pass is , , , , , and is , , , , . When the test fails and the output is . A loop repeats steps until a condition stops it. Count the passes carefully: here Step 2 runs times, for .
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 : input , , , ; work out ; work out ; divide by ; output . With this gives . Check by substituting back: on both sides.
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 and each term is twice the previous term plus , the terms are . You can spot a pattern: each term plus is a power of (). A term-to-term rule (what to do to the previous term) is an algorithm. To find the first term greater than , keep applying the rule until it is passed: , so it is the th term. Other rules, such as 'start at and add ', give and the th term is .
Section 6
Algorithms and solving equations
Solving is an algorithm: undo the operations in reverse order. Subtract from , then divide by . For : , then . The algorithm fails if , because dividing by zero is undefined and the equation has no term. Working backwards through a flowchart uses the same idea: if a flowchart multiplies by then subtracts to output , undo the steps in reverse: , then .
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
- An algorithm is written in steps. Step 1: Set and . Step 2: Add to . Step 3: Reduce by . Step 4: If , go back to Step 2; otherwise output and stop.Step 1 is changed to set . Find the new output.2 marks
- A flowchart takes a number as its input. Process: double and subtract to get . Decision: if , output the word "Large"; otherwise output .Find the smallest whole number input that gives the output 'Large'.2 marks
- A sequence is generated by an algorithm. Step 1: Set the first term . Step 2: To get the next term, multiply the previous term by and then add . 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
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).