3.1 Fundamentals of algorithms

Slides:



Advertisements
Similar presentations
PROBLEM SOLVING TECHNIQUES
Advertisements

ITEC113 Algorithms and Programming Techniques
Program Design and Development
A High-Level Model For Software Development
ALGORITHMS AND FLOWCHARTS
Adapted from slides by Marie desJardins
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Algorithmic Problem Solving CMSC 201 Adapted from slides by Marie desJardins (Spring 2015 Prof Chang version)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
By the end of this session you should be able to...
Software Life Cycle What Requirements Gathering, Problem definition
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
Visual Basic Programming
1. Understand the application of Pseudo Code for programming purposes 2. Be able to write algorithms in Pseudo Code.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
Algorithm Discovery and Design Objectives: Interpret pseudocode Write pseudocode, using the three types of operations: * sequential (steps in order written)
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
COMPUTER PROGRAMMING Year 9 – lesson 1. Objective and Outcome Teaching Objective We are going to look at how to construct a computer program. We will.
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
Programming revision Revision tip: Focus on the things you find difficult first.
Victorian Curriculum Mathematics F - 6 Algorithms unplugged
Learning outcomes 5 Developing Code – Using Flowcharts
ALGORITHMS AND FLOWCHARTS
Introduction to Computing Science and Programming I
Lesson Objectives Aims To be able to write an algorithm in Pseudo Code
Pseudocode Key Revision Points.
INTRODUCTION TO PROBLEM SOLVING
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Algorithm & Programming
Topics Introduction to Repetition Structures
GC211Data Structure Lecture2 Sara Alhajjam.
ALGORITHMS AND FLOWCHARTS
COVERED BASICS ABOUT ALGORITHMS AND FLOWCHARTS
CS1001 Programming Fundamentals 3(3-0) Lecture 2
PROGRAM CONTROL STRUCTURE
Introduction To Flowcharting
Programming Fundamentals
Siti Nurbaya Ismail Senior Lecturer
ALGORITHMS AND FLOWCHARTS
Print slides for students reference
Control Structure Senior Lecturer
Unit# 9: Computer Program Development
Learning to Program in Python
Fill the screen challenge!
Number and String Operations
Algorithms & Pseudocode
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Java Programming Loops
Algorithm Discovery and Design
ALGORITHMS AND FLOWCHARTS
ARRAYS 1 GCSE COMPUTER SCIENCE.
Do While (condition is true) … Loop
Coding Concepts (Basics)
CIS 16 Application Development Programming with Visual Basic
Programming We have seen various examples of programming languages
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Creating Computer Programs
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Flowcharts and Pseudo Code
Java Programming Loops
Topics Introduction to Repetition Structures
Basic Concepts of Algorithm
Review of Previous Lesson
Creating Computer Programs
WJEC GCSE Computer Science
Algorithms For use in Unit 2 Exam.
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Introduction to Programming
Presentation transcript:

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

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.

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.

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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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.