Algorithm & Flowchart Credit: Mr Ainullotfi.

Slides:



Advertisements
Similar presentations
ALGORITHMS AND FLOWCHARTS
Advertisements

Introduction to Flowcharting
Introduction to Flowcharting
Flow Control Analysis & Design Tool: Flowcharts
Chapter 3 IFTHENELSE Control Structure © 2008 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved. Marilyn Bohl/Maria Rynn Tools for Structured.
Introduction to Flowcharting
Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Published by Addison-Wesley.
Subject: Information Technology Grade: 10
ALGORITHMS AND FLOWCHARTS
Mathematics for Computing Lecture 4: Algorithms and flowcharts Dr Andrew Purkiss-Trew Cancer Research UK
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
Java Planning our Programs Flowcharts Arithmetic Operators.
Fundamentals of Algorithms MCS - 2 Lecture # 4
 Control structures  Algorithm & flowchart  If statements  While statements.
Designing Algorithms Csci 107 Lecture 4. Outline Last time Computing 1+2+…+n Adding 2 n-digit numbers Today: More algorithms Sequential search Variations.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
Designing Algorithms Csci 107 Lecture 3. Designing algorithms Last time –Pseudocode –Algorithm: computing the sum 1+2+…+n –Gauss formula for 1+2+…+n Today.
Flowcharts Remember that a solution to a problem is called an algorithm. Algorithms are often a series of steps required to solve the problem. A flowchart.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
The Program Design Phases
Review Algorithm Analysis Problem Solving Space Complexity
(C)opyright 2003 Scott/Jones Publishers Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Scott/Jones Publishers.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering.
ALGORITHMS AND FLOWCHARTS
CSC103: Introduction to Computer and Programming
DCT 1123 Problem Solving & Algorithms
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
CIS Computer Programming Logic
Flow Charting. Goals Create Algorithms using Flow Charting procedures. Distinguish between Flow Charting and Pseudocode. Top-Down Design Bottom-up Design.
Muhammad Adnan Talib Lec#4 27 th Sep,2012 Computer Science Department COMSATS Institute of Information Technology Sahiwal Introduction to Computer Programming.
Chapter 2 - Algorithms and Design
PROGRAMMING LANGUAGES Prof. Lani Cantonjos. PROGRAM - set of step-by-step instructions that tells or directs the computer what to do. PROGRAMMING LANGUAGE.
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
CSE 102 Introduction to Computer Engineering What is an Algorithm?
Flowcharts.
Introduction to Programming with RAPTOR
Chapter 2 - Algorithms and Design print Statement input Statement and Variables Assignment Statement if Statement Flowcharts Flow of Control Looping with.
Visual Basic Programming
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
1 Chapter 2 - Algorithms and Design print Statement input Statement and Variables Assignment Statement if Statement Flowcharts Flow of Control Looping.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering Problem Solving and Logic.
(C)opyright 2000 Scott/Jones Publishers Introduction to Flowcharting.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
Computer Programming TCP1224 Chapter 5 The Selection Structure.
1 Introduction to Flowcharting Computer Science Principles ASFA.
11 PART 2 ARRAYS. 22 PROCESSING ARRAY ELEMENTS Reassigning Array Reference Variables The third statement in the segment below copies the address stored.
Layers of the Atmosphere Layer NameAltitude (km) Temperature change with altitude.
Introduction to Flowcharts
An Introduction to Programming with C++1 The Selection Structure Tutorial 6.
Data Types Mr Tottman Link. Data Types Programs need to use data for calculations and for output to various devices The best programs will always use.
Algorithm & Flowchart.
CST 1101 Problem Solving Using Computers
ALGORITHMS AND FLOWCHARTS
Algorithms and Flowcharts
The Selection Structure
Introduction To Flowcharting
ALGORITHMS AND FLOWCHARTS
Unit# 9: Computer Program Development
ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTS
SME1013 PROGRAMMING FOR ENGINEERS
Introduction to Algorithms and Programming
Faculty of Computer Science & Information System
SME1013 PROGRAMMING FOR ENGINEERS
Flowcharts and Pseudo Code
The Atmosphere.
Chapter 5: The Selection Structure
Pseudocode For Program Design.
Presentation transcript:

Algorithm & Flowchart Credit: Mr Ainullotfi

Refers to a separate flowchart Decision Common Flowchart Symbols Start/Stop Process Input/Output Refers to a separate flowchart Decision Connector Off-page Connector Comments Preparation (for loops etc)

Example Problem #1 Given a set of numbers, calculate their sum and the average value (mean). Formula: n is the number of numbers in the set

Algorithm 1. Start 2. Get one number in the set 3. Count the numbers as it is obtained 4. If there are still numbers to be obtained, go back to step 2. 5. Sum the numbers in the set 6. Divide the sum by the number of numbers in the set to get the average 7. Show the sum and the average 8. Stop

Flowchart Start Get number Calculate mean Show sum and mean Stop Count number Any more number? Calculate sum Yes No

Detailed Flowchart Start sum ← 0 i ← 0 Mean = sum/n j ← 0 i ← i + 1 Get xi Mean = sum/n Show sum and mean Stop i ← i + 1 Any more number? Yes No i ← 0 n ← i sum ← 0 j ← 0 j ← j + 1 Is j < n? sum ← sum + xj

Pseudocode 1. Start 2. i  0 3. i  i + 1 4. Get xi 5. If there more numbers repeat from 3. 6. n  i 7. sum  0 8. j  0

Pseudocode 9. j  j + 1 10. sum  sum + xi 11. If j < n repeat from step 9 12. mean  sum / n 13. Show sum and mean 14. Stop

Variables A variable is a location in the computer memory which is given a specific name and can hold a single value at a time A variable can be compared to a box or a container that is given a label – and the box can hold one content at a time In the last example, i, j, n, sum, mean and x1, x2, x3… etc are all variables

Variable Assignments Variables are given values either directly by the user through the input statements (e.g. Get xi) or by assignments statements i  0 is an assignment expression meaning ‘assign the value 0 to variable i’ n  i means ‘assign the value equivalent to that in variable i to variable n’ (the value in variable i is not changed) j  j + 1 means ‘add 1 to the value in j’

Variable Types Variables can be of several types depending of the kind of data it stores In general variables can be classified into: (a) Numeric type (b) String type (c) Logical type Assignment expressions would involve similar type of variables only

Numeric Variables Numeric variables store numerical data which can be used in mathematical calculations Examples of numeric expressions are: i  0 j  j + 1 mean  sum / n y  x*x z  sin(x) + 3

String Variables String variables store alphanumeric data, symbols and control characters Although strings may store numbers, they are of the type not used for calculations e.g. phone numbers, addresses etc String variables are useful for labels, names and comments name  ‘lotfi’ is a string expression

Logical Variables Logical variables store only either a ‘True’ or a ‘False’ value k  (3 > 4) is an example of a logical expression – in this case k has the value ‘False’ since it is not true that 3 is greater than 4 Logical expressions are useful for tests and decision making algorithms

Example Problem #2 Atmospheric temperature vary with altitude according to the following tables Alt h (m) Temp T (K) 288.15 11000 216.65 20000 32000 228.65 47000 270.65 51000 71000 214.65 85000 186.946 Alt h (m) dT/dh (K/m) 0-11000 -6.5 x 10-3 11000-20000 20000-32000 1 x 10-3 32000-47000 2.8 x 10-3 47000-51000 51000-71000 -2.8 x 10-3 71000-85000 -2.0 x 10-3

Troposphere Stratosphere Mesosphere

Example Problem #2 The Troposphere is the layer from sea level up to 11000 m The Stratosphere is between 11000 to 51000m The Mesosphere is between 51000 to 71000m Given an altitude, the temperature of the atmosphere need to be calculated

Algorithm 1. Start 2. Get altitude 3. Determine which altitude band it is in 4. Calculate the temperature using the equation associated with that band 5. Show the altitude and the temperature 6. Stop

Determine altitude band Calculate temperature Flowchart Start Get altitude Determine altitude band Calculate temperature Show sum and mean Stop

Flowchart Start Yes Get altitude h h < 11000? Yes T ← 288.15 – 6.5*h*10-3 No h < 20000? Yes T ← 216.65 No h < 32000? Yes T ← 216.65 + h*10-3 No B A

Flowchart A h < 47000? T ← 228.65 + 2.8*h*10-3 A h < 51000? Show h and T h < 71000? T ← 270.65 - 2.8*h*10-3 Stop T ← 214.65 - 2*h*10-3

Pseudocode 1. Start 2. Get h 3. If h < 11000 then 5. Else if h < 20000 then 6. T ← 216.15 7. Else if h < 32000 then 8. T ← 216.15 + *h*10-3

Pseudocode 9. Else if h < 47000 then 10. T ← 228.65 + 2.8*h*10-3 15. Else T ← 214.65 + 2*h*10-3 16. Show h and T 17. Stop

Types of Algorithms Sequential algorithm Looping algorithm Decision algorithm Link algorithm