Download presentation
1
Algorithms and Pseudocode
2
Activity 1 Quickly sketch a flow chart for the following problem. Create a program that takes in two numbers and outputs their sum.
3
Solution Start End Store in variable “Num1” Store in variable “Num2”
Number 1? Solution Store in variable “Num1” Number 2? Store in variable “Num2” Answer = Num1+Num2 Display Answer End
4
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. Hands up if you can explain the following: What is an algorithm?
5
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. Remembering Algorithms In general, an 'algorithm' is the name given to a set of steps needed to complete a task. Think of an algorithm as a recipe. For instance you could define an algorithm to make a cup of tea. You start by filling the kettle, then place a tea bag in the cup and so on. In computer terms, an algorithm describes the set of steps needed to carry out a software task or solve a problem
6
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. Writing Algorithms Problem Algorithm Algorithms are independent of any language
7
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. Hands up if you can explain the following: What is an algorithm?
8
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. Writing Algorithms Writing an algorithm in a specific language: Too time consuming Pointless – could just code Can’t be taken by a programmer using a different language Too complex – need knowledge of syntax (code specific to a language) Writing an algorithm in everyday language (standard English): Too time consuming Inaccurate as it could be open to interpretation Algorithms are independent of any language There are therefore methods used to write algorithms so that they are succinct, accurate and easy to understand so that a programmer of any language could understand the steps required to solve a task: Flowcharts and Pseudocode
9
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. Writing Algorithms Problem: Calculate the Sales Tax (VAT) of an item and then using it to work out the final price 1. Flowchart 2. Pseudocode Examples of each method of algorithm writing
10
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. Pseudocode Today we will focus on Pseudocode Represents an algorithm using adapted everyday language and common keywords from programming languages Instructions are easy to read and understand, but look similar to statements found in programming languages and so can be more readily turned into code. Psedo-code is NOT a strict list of commands, there are no universal standards, however, using certain keywords (as shown on the next few slides) is an expectation – this way any programmer should be able to take your algorithm an understand it. Example: A central heating system will try to keep the temperature between 2 values (19 and 21) If the temperature falls below 19 It will turn the heating system on If the temperature rises above 21 it will switch the heating system off. START IF Temp < 19 THEN Heating On ELSE IF Temp > 21 THEN Heating Off END
11
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. Start and End “Key Words” Pseudocode begin with a START and ends with END The algorithm goes in between. START …………………………….. END Pseudocode and their statements
12
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. Process “Key Words” Most of the time pseudocode will outline the logical sequence of instructions to be carried out. Simple processes will often use the key words shown below (like “CALCULATE X*2” or “INCREMENT X by 1)” You don’t have to always use these words, for example the logic statements such as “Add 1 to x” or “append x to List”) are fine too.. Pseudocode and their statements Compute Calculate Determine Increment; ++ or += Decrement; -- or -=
13
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. Input / Output “Key Words” At times your program will most certainly ask the user for inputs and output values too. Inputs and Outputs (like “Name?” or “…display age”) are indicated using the following words. Usually a programmer will chose one and stick with it throughout their algorithm. Pseudocode and their statements INPUTS: READ OBTAIN GET INPUT OUTPUTS: PRINT DISPLAY SHOW OUTPUT
14
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. Variable Assignment “Key Words” At times your program will assign values to variables. In pseudocode this is done using the following key words. SET INIT Pseudocode and their statements Very commonly, an arrow is used instead e.g.: X 10 This means SET X to 10
15
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. Decision/Selection “Key Words” At times your program will be programmed to make a decision based on certain conditions. Decisions (like “IF X = 3, THEN …”) are shown using, unsurprisingly, the following key words. IF THEN ELSE ELSE-IF ENDIF Pseudocode and their statements
16
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. Loops / Iterations “Key Words” Programs will often loop in places while certain conditions occur (infinitely) or for a set number of times (finitely). Loops use the following key words: Pseudocode and their statements FINITE: FOR INFINITE: WHILE / ENDWHILE REPEAT / UNTIL
17
Algorithms and Pseudocode
Summary Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. , Pseudocode and their statements Pseudocode is written a bit like a programming language however it should never be confused with one. It is independent of any language.
18
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. Pseudocode and their key words / statements in action… GET Height GET Base Answer (Base * Height) / 2 DISPLAY “Right angled triangle area” = Answer END 1. Use of capitalised pseudocode key words/statements 2. Indentation GET Name FOR x = 1 TO 10 DISPLAY “Your name is” = Name END
19
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. 4 things you need to be able to do with algorithms for your exam Understand them Correct them if they have errors, Complete them if they are incomplete Produce them after being given a problem to solve
20
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. Tips on reading algorithms. Remember, arrows often show the assignment of a value to a variable. Here the variable is a list and will contain 5 items Start from top and read each line at a time. Remember what the key words, arrows and statements mean Logically work out what the algorithms is doing. Task: What is this algorithm doing?
21
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. Tips on correcting algorithms. START WHILE TRUE X Temperature IF X > 19 Heating TRUE ELSE-IF X < 21 Heating FALSE END Read the pseudocode and look for decisions which don’t make sense START X WHILE X < 10 DO X X+1 END Or it might be a loop which you cannot get into or perhaps out of.
22
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. Tips on completing algorithms. Start from top and understand each line in turn Remember what the keywords mean Logically work out what the algorithms is doing. THEN, Use your knowledge of the algorithm so far AND Use your knowledge of the pesudocode keywords …and complete the algorithm START INPUT Length, Width, Height objectVolume ← Print “Volume = ” END
23
Algorithms and Pseudocode
Learning Objectives: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. Tips on writing algorithms.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.