Programming Techniques :: Flow Diagrams and Pseudocode

Slides:



Advertisements
Similar presentations
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
Advertisements

Chapter 8 and 9 Review: Logical Functions and Control Structures Introduction to MATLAB 7 Engineering 161.
PRE-PROGRAMMING PHASE
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Flowcharts and Algorithms. Review of Terms  A computer is a machine that can represent and manipulate data –Ultimately the data and the instructions.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
The Hashemite University Computer Engineering Department
Algorithms and Pseudocode
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
Algorithms and Flowcharts
Component 1.6.
Learning outcomes 5 Developing Code – Using Flowcharts
ALGORITHMS AND FLOWCHARTS
Understand Problem Solving Tools to Design Programming Solutions
A451 Theory – 7 Programming 7A, B - Algorithms.
FLOWCHARTS Part 1.
Be A programmer in Steps
Chapter 2- Visual Basic Schneider
Pseudocode Upsorn Praphamontripong CS 1110 Introduction to Programming
Understand Problem Solving Tools to Design Programming Solutions
Lecture 2 Introduction to Programming
Introduction To Flowcharting
Introduction to Computer Programming
Programming Fundamentals
Algorithm and Ambiguity
Teaching Computing to GCSE
CS 240 – Lecture 11 Pseudocode.
ALGORITHMS AND FLOWCHARTS
Print slides for students reference
Unit# 9: Computer Program Development
Programming & languages
Algorithms & Pseudocode
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Global Challenge Night Sensor Lesson 2.
ALGORITHMS AND FLOWCHARTS
Chapter 2- Visual Basic Schneider
Global Challenge Night Sensor Lesson 2.
Faculty of Computer Science & Information System
Chapter 2- Visual Basic Schneider
Global Challenge Night Sensor Lesson 2.
Global Challenge Night Sensor Lesson 2.
Global Challenge Night Sensor Lesson 2.
Algorithm and Ambiguity
Understanding Problems and how to Solve them by using Computers
Global Challenge Night Sensor Lesson 2.
Global Challenge Night Sensor Lesson 2.
Global Challenge Night Sensor Lesson 2.
CS 1111 Introduction to Programming Spring 2019
Flowcharts and Pseudo Code
Global Challenge Night Sensor Lesson 2.
COMPUTATIONAL THINKING COMPUTATIONAL THINKING IN PROGRAMMING
Global Challenge Night Sensor Lesson 2.
Basic Concepts of Algorithm
Global Challenge Night Sensor Lesson 2.
WJEC GCSE Computer Science
Programming Techniques :: Records
Programming Techniques :: File Handling
Programming Techniques :: String Manipulation
Data Representation :: Binary & Hexadecimal
Running & Testing :: IDEs
Programming Techniques :: Logic & Truth Tables
Programming Techniques :: Data Types and Variables
Networks :: Wireless Networks
Programming Techniques :: Sorting Algorithms
Running & Testing Programs :: Translators
Data Representation :: Compression
Programming Techniques :: Arithmetic & Boolean Operators
Programming Techniques :: Computational Thinking
Presentation transcript:

Programming Techniques :: Flow Diagrams and Pseudocode jamie@drfrostmaths.com www.drfrostmaths.com @DrFrostMaths Last modified: 28th June 2019

www.drfrostmaths.com ? Everything is completely free. Why not register? Registering on the DrFrostMaths platform allows you to save all the code and progress in the various Computer Science mini-tasks. It also gives you access to the maths platform allowing you to practise GCSE and A Level questions from Edexcel, OCR and AQA. With Computer Science questions by: Your code on any mini-tasks will be preserved. Note: The Tiffin/DFM Computer Science course uses JavaScript as its core language. Most code examples are therefore in JavaScript. Using these slides: Green question boxes can be clicked while in Presentation mode to reveal. Slides are intentionally designed to double up as revision notes for students, while being optimised for classroom usage. The Mini-Tasks on the DFM platform are purposely ordered to correspond to these slides, giving your flexibility over your lesson structure. ?

Specifying Algorithms An algorithm is just a set of instructions to carry out a problem. When designing an algorithm, we often plan the steps that the algorithm will need to take before we write the code. If we’re working in a team or want to share the algorithm with others, we need some way to describe how the algorithm work that is not dependent on a particular programming language. Take for example a well-known algorithm like Dijkstra’s Algorithm, which finds the shortest path between two vertices in a graph: We could write a worded description of the algorithm. We could write ‘pseudocode’ (which we’ll look at in a second)

Specifying Algorithms In some cases we can also describe an algorithm by providing a flow diagram. Start Flow diagrams provide a visual way of showing the sequence of steps in an algorithm. ? Indicates route to follow in the algorithm. Input number No ? Start/Stop ? Start and end of the algorithm (note rounded corners) ? Is number 42? e.g. Values taken from console, read from file, outputted to console… Input/Output ? ? A general step/instruction in your algorithm. Process Yes ? Where we decide where to progress based on a particular question. There will be multiple arrows coming out. ? Destroy Earth Decision ? Reference other flow diagrams. Subroutines are covered in another resource. ? Sub Routine End ?

Output current position Example Flow Diagram You want to devise an algorithm that searches an array for the name “Bob” and outputs the position in the array where Bob is found. We want to do a linear search, i.e. check the items in order one by one until we find the item. The algorithm should output the position of the name if found, and -1 otherwise. Draw a flow diagram for this algorithm. ? No At end of array? No Is name “Bob” Get next name in array Start Yes Yes Output current position -1 Stop

Receive shot notification Test Your Understanding You are producing a scorekeeping system for a game of archery, and keep a tally of the player’s score. Each time they hit the target, they score 10 points, and if not, score no points. There repeat this until they’ve had 20 attempts, at which point their score is displayed. Draw a flow diagram for this algorithm. ? Start Add 10 to score No Yes Had 20 shots? No Hit target? Set score to 0 Receive shot notification Yes Output score Stop

Pseudocode Pseudocode is notation intended to resemble code. It is intended to be language-neutral and not be concerned with the exact syntax of a particular language. Like flow diagrams, the intention is that programmers can then convert these quickly into code in a particular language. As pseudocode is intended to resemble code, this is much easier than converting a flow diagram to code. Pseudocode is not a real language and is not an exact science. The important thing is to make it easy to understand and easy to convert to actual code. Avoid being too general or too vague. It is fine to use control structures that are common to most languages, e.g. if statements, while and for loops. Regardless of the language-specific function needed to input a number, it’s immediately obvious what this line means. age:= input(“What is your age”) age:= age + 3 print(“Your age in 3 years time is “+age) It’s again clear, regardless of syntax, that we want reassign age with a value 3 greater. Ask for age Increment age by 3 Output the new age Technically this is still pseudocode. But it reads more like a description. A programmer would have to think more to turn it into code.

Converting Flow Diagrams to Pseudocode An algorithm can be represented by the following flow diagram: Using appropriate pseudocode, write this algorithm. End Start Add numbers Output result Input a number 𝑥 Yes Is 𝑥 even? No Yes Input a number 𝑦 Subtract 𝑦 from 𝑥 ? x = input(“Enter a number x”) y = input(“Enter a number y”) if(isEven(x))print x + y else print x - y while we could have used x%2 = 0 for “is x even?”, this is too language specific. isEven(x) is very clear in its meaning.

Round 2 – Where a while is required An algorithm can be represented by the following flow diagram: Using appropriate pseudocode, write this algorithm. Add number to total Start No Is number >10? Let total be 0 Input a number Yes Output total End ? total = 0 num = input(“Enter a number”) while(num <= 10) total= total + num endwhile print(“Total is “+total) You need to be careful here that you don’t add the last number inputted if that number was greater than 10. It’s possible to avoid duplicating the input line of code.

Exam-Style Question ? ? ? OCR Specimen Paper Either a more description-based or pseudocode based approach is acceptable.

Review ? ? ? Why might we write pseudocode for an algorithm? Gives a clear idea of how the algorithm works, in such a way that makes it easy to translate to actual code. It is not tied down to the specifics a particular programming language. Why then might we prefer a flow diagram to pseudocode? Gives a clearer visual indication of the flow of the code. What does the following flowchart shape mean? A decision where subsequent flow in the diagram depends on the result of that decision. ? ? ?