Presentation is loading. Please wait.

Presentation is loading. Please wait.

3.1 Fundamentals of algorithms

Similar presentations


Presentation on theme: "3.1 Fundamentals of algorithms"— Presentation transcript:

1 3.1 Fundamentals of algorithms
3.1.1 Representing algorithms (pseudo-code) Lesson

2 What do these words mean to you?
Code Ambiguous Pseudo What do these words mean to you? Flowchart Decomposition This slide is designed as a starting point to find a baseline of understanding.

3 Objectives 1. Know what pseudo-code is.
2. Understand the link between code, pseudo-code and flowcharts. 3. Understand the main pseudo-code methodologies. 4. Be able to solve a problem using pseudo-code. Keywords: Pseudo-code Flowchart Code Problem Solution Whilst this lesson is focussed on pseudo-code, the link between code and flowcharts needs to be borne in mind.

4 Flowcharts provide an overview of how to solve a problem.
1. Know what pseudo-code is. 2. Understand the link between code, pseudo-code and flowcharts. Pseudo-code looks at in-depth algorithms to solve problems without having to worry about code syntax. Pseudo-code is almost computer code – but not quite. Think of it as a half-way house between a flowchart overview and actual computer code. Computer code implements algorithms in such a way that a computer can understand it. Students need to understand that pseudo-code is a means to an end. In this presentation we look at one approach and form a link between flowcharts, pseudo-code and code. This is the format that students will be presented with in exams. When writing their own code it just has to be understandable and unambiguous.

5 Contents Sequence Variable assignment If...Then If...Then... Else Case
While loops Repeat loops For loops Procedures Procedures with parameters Functions Each of the above is a hyperlink which will take you to the relevant section in the presentation. Each section consists of an explanation of the word or phrase, a task and a blank slide for students’ responses. Writing files Reading files

6 Sequence 3. Understand the main pseudo-code methodologies.
x  USERINPUT OUTPUT x The left arrow indicates assignment. The user input is put in to x. Programs have to flow in sequence. You can’t divide a total by the number of elements to work out an average if you haven’t added them up first. It is expected that teachers talk through the pseudo-code – this is not a topic that you can just look at! There is often a 1-to-1 relationship between pseudo-code and actual code. Back to Contents

7 Task: Write pseudo-code to input your name
4. Be able to solve a problem using pseudo-code. Sequence Task: Write pseudo-code to input your name and age and output them to the screen. Allow 3-4 minutes. Back to Contents

8 Sequence 4. Be able to solve a problem using pseudo-code
This slide is an opportunity for students to use an interactive whiteboard to write up their pseudo-code. The whole group can then discuss, look at alternatives, identify areas which are different from AQA pseudo-code and whether they are acceptable or not. Back to Contents

9 gridOfWords[3][4]= ”hello”
3. Understand the main pseudo-code methodologies Variable assignment The left arrow indicates assignment singleNumber3 listOfNumber[3]5 gridOfWords[3][4]”hello” initialisedList[2, 32, 45, -1] singleNumber3 listOfNumber[3]5 gridOfWords[3][4]”hello” initialisedList[2, 32, 45, -1] singleNumber = 3 listOfNumber[3] = 5 gridOfWords[3][4]= ”hello” initialisedList = [2, 32, 45, -1] Arrays or lists use square brackets to identify elements within them These are examples of assignation, this is not a full program. Lists can be initialised with values Back to Contents

10 Task: Create pseudo-code to create a list of exam results.
4. Be able to solve a problem using pseudo-code. Variable assignment Task: Create pseudo-code to create a list of exam results. Extension: Create a list of names that link to the exam results. Allow 3-4 minutes. Back to Contents

11 Variable assignment 4. Be able to solve a problem using pseudo-code
This slide is an opportunity for students to use an interactive whiteboard to write up their pseudo-code. The whole group can then discuss, look at alternatives, identify areas which are different from AQA pseudo-code and whether they are acceptable or not. Back to Contents

12 If ... then 3. Understand the main pseudo-code methodologies.
Text has speech marks around it. Comparisons are common sense. Discussions can cover use of single/double speech marks for strings, comparison operators. Control statements have an END <statement> to aid understanding. Back to Contents

13 4. Be able to solve a problem using pseudo-code.
If…then Task: Create pseudo-code to input an exam grade and output a message to the screen if it is a pass grade. Allow 3-4 minutes. Back to Contents

14 If … then 4. Be able to solve a problem using pseudo-code.
This slide is an opportunity for students to use an interactive whiteboard to write up their pseudo-code. The whole group can then discuss, look at alternatives, identify areas which are different from AQA pseudo-code and whether they are acceptable or not. Back to Contents

15 Control statements have an END <statement> to aid understanding.
3. Understand the main pseudo-code methodologies. If … then ... else Note the end is still ENDIF and after the else. Control statements have an END <statement> to aid understanding. Back to Contents

16 4. Be able to solve a problem using pseudo-code.
If … then ... else Task: Extend your previous pseudo-code to output a different message if it is a fail grade. Allow 2-3 minutes. Back to Contents

17 If ... then ... else 4. Be able to solve a problem using pseudo-code.
This slide is an opportunity for students to use an interactive whiteboard to write up their pseudo-code. The whole group can then discuss, look at alternatives, identify areas which are different from AQA pseudo-code and whether they are acceptable or not. Back to Contents

18 Control statements have an END <statement> to aid understanding.
3. Understand the main pseudo-code methodologies. Case In the case of x being… Discussion as to simplicity of multiple tests as opposed to nested decisions. Control statements have an END <statement> to aid understanding. Back to Contents

19 4. Be able to solve a problem using pseudo-code.
Case Task: Create pseudo-code to output a different message for each exam grade that can be entered. Allow 4-5 minutes. Back to Contents

20 Case 4. Be able to solve a problem using pseudo-code. Back to Contents
This slide is an opportunity for students to use an interactive whiteboard to write up their pseudo-code. The whole group can then discuss, look at alternatives, identify areas which are different from AQA pseudo-code and whether they are acceptable or not. Back to Contents

21 While loops 3. Understand the main pseudo-code methodologies.
Criteria is the same for coding, flowcharts and pseudo-code. Discussion as to criteria, choice of type of loop. Control statements have an END <statement> to aid understanding. Back to Contents

22 4. Be able to solve a problem using pseudo-code.
While loops Task: Create pseudo-code to repeatedly input a number and add it on to a total until they input a number which is less than 0 Allow 5-6 minutes. Back to Contents

23 While loops 4. Be able to solve a problem using pseudo-code.
This slide is an opportunity for students to use an interactive whiteboard to write up their pseudo-code. The whole group can then discuss, look at alternatives, identify areas which are different from AQA pseudo-code and whether they are acceptable or not. Back to Contents

24 Criteria is the same for coding, flowcharts and pseudo-code.
3. Understand the main pseudo-code methodologies. Repeat loops Criteria is the same for coding, flowcharts and pseudo-code. Discussion as to choice of loop. Counting loop = FOR, at least once = REPEAT, may not be needed at all = WHILE. Pyhon does not have a REPEAT loop so a cheat is needed. Back to Contents

25 4. Be able to solve a problem using pseudo-code.
Repeat loops Task: Create pseudo-code to initialise a variable by 2 and then repeatedly output the variable and then times it by itself until the variable exceeds 1,000,000 Allow 5-6 minutes. Back to Contents

26 Repeat loops 4. Be able to solve a problem using pseudo-code
This slide is an opportunity for students to use an interactive whiteboard to write up their pseudo-code. The whole group can then discuss, look at alternatives, identify areas which are different from AQA pseudo-code and whether they are acceptable or not. Back to Contents

27 For loops 3. Understand the main pseudo-code methodologies.
For loops need ranges to loop through. FOR loops are for counting loops. Control statements have an END <statement> to aid understanding. Back to Contents

28 4. Be able to solve a problem using pseudo-code
For loops Task: Create pseudo-code to fill a list with ten names, and then use a ‘For’ loop to output them one at a time. Allow 4-5 minutes. Back to Contents

29 For loops 4. Be able to solve a problem using pseudo-code.
This slide is an opportunity for students to use an interactive whiteboard to write up their pseudo-code. The whole group can then discuss, look at alternatives, identify areas which are different from AQA pseudo-code and whether they are acceptable or not. Back to Contents

30 Procedures 3. Understand the main pseudo-code methodologies.
You have to differentiate between procedures and functions. Control structures have an END <statement> to aid understanding. Procedures without parameters are useful for taking long and distracting elements of code (such as outputting menus and large amounts of text) outside of the main program flow. Call procedures by name. Back to Contents

31 4. Be able to solve a problem using pseudo-code.
Procedures Task: Create a pseudo-code procedure that outputs your name five times. Call the procedure by name. Allow 3-4 minutes. Back to Contents

32 Procedures 4. Be able to solve a problem using pseudo-code.
This slide is an opportunity for students to use an interactive whiteboard to write up their pseudo-code. The whole group can then discuss, look at alternatives, identify areas which are different from AQA pseudo-code and whether they are acceptable or not. Back to Contents

33 Procedures with parameters
3. Understand the main pseudo-code methodologies. Parameters are passed in with a name. Control structures have an END <statement> to aid understanding. Procedures with parameters allow pieces of code to be repeated with some variation Call procedures by name and include a value or variable as the parameter. Back to Contents

34 Procedures with parameters
4. Be able to solve a problem using pseudo-code. Task: Adapt your previous procedure to accept a name as a parameter and output it five times. Extension: Accept a second parameter to specify the number of times to repeat the name. Allow 4-5 minutes. Back to Contents

35 Procedures with parameters
4. Be able to solve a problem using pseudo-code. This slide is an opportunity for students to use an interactive whiteboard to write up their pseudo-code. The whole group can then discuss, look at alternatives, identify areas which are different from AQA pseudo-code and whether they are acceptable or not. Back to Contents

36 Functions 3. Understand the main pseudo-code methodologies.
Parameters are passed in with a name. The result of the calculation is returned. Functions can be used to produce repeated mathematical calculations amongst many other things. The returned value is assigned to a variable for use. Call functions by name and include a value or variable as the parameter. Back to Contents

37 4. Be able to solve a problem using pseudo-code.
Functions Task: Create pseudo-code to create a function that accepts a number as a parameter, and then adds a random number between 1 and 10 to the number and returns the answer. Allow 4-5 minutes. Back to Contents

38 Functions 3. Understand the main pseudo-code methodologies.
Parameters are passed in with a name. The result of the calculation is returned. Functions can be used to produce repeated mathematical calculations amongst many other things. The returned value is assigned to a variable for use. Call functions by name and include a value or variable as the parameter. Back to Contents

39 Writing files 3. Understand the main pseudo-code methodologies.
LEN is a function for getting the size of a file or list. Lists start at 0 but AQA pseudo-code files start at 1 Python has easier to use in-built functions – pseudo-code should be independent of a programming language. Writing text files in AQA pseudo-code is contrary to most programing languages. It is important that students remember that as long as their code is clear and unambiguous then they will be fine. Back to Contents

40 Extension: Repeat forever until the user inputs the word “stop”.
4. Be able to solve a problem using pseudo-code. Writing files Task: Create pseudo-code to ask for a word and write it to a file. This should be repeated five times. Extension: Repeat forever until the user inputs the word “stop”. Allow 4-5 minutes. Back to Contents

41 Writing files 4. Be able to solve a problem using pseudo-code.
This slide is an opportunity for students to use an interactive whiteboard to write up their pseudo-code. The whole group can then discuss, look at alternatives, identify areas which are different from AQA pseudo-code and whether they are acceptable or not. Back to Contents

42 Reading files 3. Understand the main pseudo-code methodologies.
LEN is a function for getting the size of a file or list. AQA suggest pseudo-code that reads a line at a time Python has easier to use in-built functions – pseudo-code should be independent of a programming language. Reading text files in AQA pseudo-code is contrary to most programing languages. It is important that students remember that as long as their code is clear and unambiguous then they will be fine. Back to Contents

43 Extension: Extend the pseudo-code to output the file in reverse order.
4. Be able to solve a problem using pseudo-code. Reading files Task: Create pseudo-code to read in the file you created in the last task and output it to screen. Extension: Extend the pseudo-code to output the file in reverse order. Allow 4-5 minutes. Back to Contents

44 Reading files 4. Be able to solve a problem using pseudo-code.
This slide is an opportunity for students to use an interactive whiteboard to write up their pseudo-code. The whole group can then discuss, look at alternatives, identify areas which are different from AQA pseudo-code and whether they are acceptable or not. Back to Contents

45 1. Know what pseudo-code is.
2. Understand the link between code, pseudo-code and flowcharts. 3. Understand the main pseudo-code methodologies. 4. Be able to solve a problem using pseudo-code. Complete the following tasks: Review the flowcharts you have created for your controlled assessment. Take one subroutine at a time and create pseudo-code to form an algorithm. Remember: Pseudo-code should be independent of the programming language. Pseudo-code should be clear. Pseudo-code should be unambiguous. These are quite challenging, it may be worth doing this (and the previous requirement of creating flowcharts) on a previous controlled assessment prior to trying with the real ones.


Download ppt "3.1 Fundamentals of algorithms"

Similar presentations


Ads by Google