Algorithms and Pseudocode

Slides:



Advertisements
Similar presentations
Algorithms 10 IST – Topic 6.
Advertisements

PROBLEM SOLVING TECHNIQUES
COMPUTER PROGRAMMING I Understand Problem Solving Tools to Design Programming Solutions.
PSEUDOCODE & FLOW CHART
Chapter 1 - An Introduction to Computers and Problem Solving
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
Session Objectives# 24 COULD code the solution for an algorithm
1 Pseudocode For Program Design. 22 Rules for Pseudocode Write only one statement per line Capitalise initial keyword Indent to show hierarchy and structures.
ITEC113 Algorithms and Programming Techniques
Chapter 2- Visual Basic Schneider
Programming Fundamentals (750113) Ch1. Problem Solving
Chapter 1 Program Design
Chapter 3 Planning Your Solution
The Program Design Phases
Review Algorithm Analysis Problem Solving Space Complexity
Fundamentals of C programming
ALGORITHMS AND FLOWCHARTS
Adapted from slides by Marie desJardins
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer.
1. Know the different types of flow block 2. Understand how problems can be broken down into smaller problems.
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Algorithmic Problem Solving CMSC 201 Adapted from slides by Marie desJardins (Spring 2015 Prof Chang version)
Chapter 2 - Algorithms and Design
By the end of this session you should be able to...
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
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.
Flowcharts and Algorithms. Review of Terms  A computer is a machine that can represent and manipulate data –Ultimately the data and the instructions.
Procedural Programming. Programming Process 1.Understand the problem 2.Outline a general solution 3.Decompose the general solution into manageable component.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
Software Development. Software Development Loop Design  Programmers need a solid foundation before they start coding anything  Understand the task.
Algorithm Discovery and Design Objectives: Interpret pseudocode Write pseudocode, using the three types of operations: * sequential (steps in order written)
Intro to Loops 1.General Knowledge 2.Two Types of Loops 3.The WHILE loop 1.
Problem-solving with Computers. 2Outline  Computer System  5 Steps for producing a computer program  Structured program and programming  3 types of.
Flowchart. a diagram of the sequence of movements or actions of people or things involved in a complex system or activity. a graphical representation.
STEP 3- DEVELOP AN ALGORITHM At this stage we break down the problem into simple manageable steps so that they can be handled easily.
P ROGRAMMING L OGIC GWDA123 Sharon Kaitner, M.Ed. Winter 2015: Week 2.
PROBLEM SOLVING. What is a Problem? A problem is a situation that needs to be resolved.
Pseudocode. Algorithm A procedure for solving a problem in terms of the actions to be executed and the order in which those actions are to be executed.
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
 Problem Analysis  Coding  Debugging  Testing.
Algorithms and Flowcharts
Programming revision Revision tip: Focus on the things you find difficult first.
INTRODUCTION TO PROBLEM SOLVING
Introduction to Algorithms
2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park
Chapter 2- Visual Basic Schneider
Lecture 2 Introduction to Programming
Introduction To Flowcharting
Unit 2.1 – computational thinking & Algorithms
Algorithm and Ambiguity
ALGORITHMS AND FLOWCHARTS
Introduction to pseudocode
Algorithms & Pseudocode
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
ALGORITHMS AND FLOWCHARTS
Chapter 2- Visual Basic Schneider
Chapter 2- Visual Basic Schneider
Algorithm and Ambiguity
Data and Flowcharts Session
Computational Thinking
Data and Flowcharts Session
Flowcharts and Pseudo Code
ICT Gaming Lesson 2.
Data and Flowcharts Session
Basic Concepts of Algorithm
WJEC GCSE Computer Science
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

Algorithms and Pseudocode

Activity 1 Quickly sketch a flow chart for the following problem. Create a program that takes in two numbers and outputs their sum.

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

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?

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

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

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?

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

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

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

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

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 -=

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

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

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

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

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.

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

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

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?

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 10 WHILE X < 10 DO X X+1 END Or it might be a loop which you cannot get into or perhaps out of.

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

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.