CMSC 104: Peter Olsen, Fall 99Lecture 9:1 Algorithms III Representing Algorithms with pseudo-code.

Slides:



Advertisements
Similar presentations
CS101: Introduction to Computer programming
Advertisements

More on Algorithms and Problem Solving
Chapter 2: Problem Solving
Chapter 2: Problem Solving
Program Design Tool. 6 Basic Computer Operations Receive information Put out information Perform arithmetic Assign a value to variable (memory location)
ITEC113 Algorithms and Programming Techniques
1 Chapter 2 Problem Solving Techniques INTRODUCTION 2.2 PROBLEM SOLVING 2.3 USING COMPUTERS IN PROBLEM SOLVING : THE SOFTWARE DEVELOPMENT METHOD.
Chapter 3 Planning Your Solution
The Program Design Phases
PRE-PROGRAMMING PHASE
Fundamentals of C programming
Chapter 2: Problem Solving
CSEB114: PRINCIPLE OF PROGRAMMING Chapter 2: Problem Solving.
Programming Techniques I SCJ1013
Chapter 2: Problem Solving
U NDERSTANDING P ROBLEMS AND HOW TO S OLVE THEM BY USING C OMPUTERS.
Spring 2005, Gülcihan Özdemir Dağ Lecture 3, Page 1 BIL104E: Introduction to Scientific and Engineering Computing, Spring Lecture 3 Outline 3.1 Introduction.
TMF1013 : Introduction To Computing Lecture 1 : Fundamental of Computer ComputerFoudamentals.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
Slide 1 Software Development 1. Requirement Specification 2. Analysis 3. Algorithm Design 4. Implementation 5. Testing 6. Documentation.
Chapter 2 Problem Solving On A Computer 2.1 Problem Solving Steps Solving a problem on a computer requires steps similar to those followed when solving.
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.
CMSC 1041 Algorithms III Problem Solving and Pseudocode.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
Module 4 Part 1 Introduction To Software Development : Systems Analysis & Design Introduction To Software Development : Systems Analysis & Design.
กระบวนการแก้ปัญหาด้วย คอมพิวเตอร์ 3 พฤษภาคม :00-17:00.
PROGRAMMING PAPER 2 AS Algorithms.
ITEC113 Algorithms and Programming Techniques
Chapter 2: General Problem Solving Concepts
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
Principles of Programming - NI July Chapter 2: Problem Solving In this chapter you will learn about: Introduction to Problem Solving Software development.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
1 Program Planning and Design Important stages before actual program is written.
 In this chapter you will learn about:  Introduction to Problem Solving  Software development method (SDM)  Specification of needs  Problem analysis.
CSEB114: Principle of programming
The Hashemite University Computer Engineering Department
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
STEP 3- DEVELOP AN ALGORITHM At this stage we break down the problem into simple manageable steps so that they can be handled easily.
Programming Fundamentals Introduction to Problem Solving  Programming is a problem solving activity. When you write a program, you are actually writing.
Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose.
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.
Introduction to Problem Solving Programming is a problem solving activity. When you write a program, you are actually writing an instruction for the computer.
 Problem Analysis  Coding  Debugging  Testing.
2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park
Algorithms and Flowcharts
Introduction To Flowcharting
Introduction to Computer Programming
UMBC CMSC 104 – Section 01, Fall 2016
Programming Fundamentals
Algorithm and Ambiguity
2008/09/24: Lecture 6b CMSC 104, Section 0101 John Y. Park
Lecture 2: Logical Problems with Choices
Unit# 9: Computer Program Development
2008/09/22: Lecture 5 CMSC 104, Section 0101 John Y. Park
Structured Program
Chapter 3 - Structured Program Development
Chapter 2- Visual Basic Schneider
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Chapter 3 - Structured Program Development
Chapter 2- Visual Basic Schneider
Understanding Problems and how to Solve them by using Computers
Lecture 7 Algorithm Design & Implementation. All problems can be solved by employing any one of the following building blocks or their combinations 1.
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Basic Concepts of Algorithm
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Structural Program Development: If, If-Else
Presentation transcript:

CMSC 104: Peter Olsen, Fall 99Lecture 9:1 Algorithms III Representing Algorithms with pseudo-code

CMSC 104: Peter Olsen, Fall 99Lecture 9:2 Goal l A method for representing algorithms that: oIs easy to use (or it won’t be) oClear and precise (or why bother?) oUnderstandable by others without special training.

CMSC 104: Peter Olsen, Fall 99Lecture 9:3 Algorithm Definition An algorithm for a problem is a sequence of finite number of steps arranged in a specific logical order which, when executed, will produce a correct solution for a specific problem. “An algorithm is any finite sequence of steps connecting a problem with its solution.”

CMSC 104: Peter Olsen, Fall 99Lecture 9:4 Requirements for a Solution Algorithm – Unambiguous – Finite – Defined Input – Desired Output – Generality – Correctness – Efficiency

CMSC 104: Peter Olsen, Fall 99Lecture 9:5 Algorithm Representations English Pseudo-code (“Structured English”) Flow chart

CMSC 104: Peter Olsen, Fall 99Lecture 9:6 Algorithms in English l To find a zero using Newton’s Method oBegin the procedure by letting x be the current point. oUsing their definitions, calculate f(x) and f’(x). oIf f’(x) is less than an error tolerance, e, quit. oIf it is not, calculate the next point: y = x - f(x)/f’(x) oContinue until f(x) is “close enough” to zero. x is the zero of f.

CMSC 104: Peter Olsen, Fall 99Lecture 9:7 Algorithms in English l Easy to understand. l Easy to use. l Not very clear or precise.

CMSC 104: Peter Olsen, Fall 99Lecture 9:8 Pseudo-code English like Semi-formal Limited vocabulary Intended specifically to design and describe algorithms.

CMSC 104: Peter Olsen, Fall 99Lecture 9:9 Pseudo-code The main purpose of a pseudo-code is to define the procedural logic of an algorithm in a simple, easy-to-understand manner for readers, who may or may not be proficient in computer programming.

CMSC 104: Peter Olsen, Fall 99Lecture 9:10 Pseudo-code Used in designing algorithms. Used in communicating to users. Used in implementing algorithms as programs. Used in debugging logic errors in programs. Used in documenting programs for future maintenance and expansion purposes.

CMSC 104: Peter Olsen, Fall 99Lecture 9:11 Pseudo-code Must have a limited vocabulary. Must be easy to learn. Must produce simple, English-like narrative notation. Must be capable of describing all algorithms, regardless of their complexity.

CMSC 104: Peter Olsen, Fall 99Lecture 9:12 Control Structures of All Computer Programs Sequence Selection Repetition

CMSC 104: Peter Olsen, Fall 99Lecture 9:13 Sequence Series of steps or statements that are executed in the order they are written. Example: Read taxable income Read filing status Compute income tax Print income tax

CMSC 104: Peter Olsen, Fall 99Lecture 9:14 Sequence A sequence can be thought of as one logical step. InOut Sequence

CMSC 104: Peter Olsen, Fall 99Lecture 9:15 Selection Defines one or two courses of action depending on the evaluation of a condition. A condition is an expression that is either true or false. Example if condition (is true) then-part else else-part end_if

CMSC 104: Peter Olsen, Fall 99Lecture 9:16 Nested Selection if status is equal to 1 print “Single” else if status is equal to 2 print “Married filing jointly” else if status is equal to 3 print “Married filing separately end_if end_if end_if

CMSC 104: Peter Olsen, Fall 99Lecture 9:17 Nested Selection SINGLE = 1; MARRIEDJOINT = 2; MARRIEDSEP = 3 if status is equal to SINGLE print “Single” else if status is equal to MARRIEDJOINT print “Married filing jointly” else if status is equal to MARRIEDSEP print “Married filing separately end_if end_if end_if

CMSC 104: Peter Olsen, Fall 99Lecture 9:18 Nested Selection l Defines a logical block with one entrance, one exit, and two or more paths inside. If Endif Input Output

CMSC 104: Peter Olsen, Fall 99Lecture 9:19 Repetition Specifies a block of one or more statements that are repeatedly executed until a condition is satisfied. while condition loop-body end_while

CMSC 104: Peter Olsen, Fall 99Lecture 9:20 Repetition While while m is less than m, … end while For loop for m from 1 to n, … end for Until do … until m is less than n, end do

CMSC 104: Peter Olsen, Fall 99Lecture 9:21 Repetition l A logical block with one input, one output, and one return loop. While EndWhile

CMSC 104: Peter Olsen, Fall 99Lecture 9:22 Conventions Each pseudo-code statement consists of keywords that describe operations and some appropriate, English-like description of operands. Each statement should be written on a separate line. Continuation lines should be indented. Goal is clarity

CMSC 104: Peter Olsen, Fall 99Lecture 9:23 Conventions (II) Sequence statements should begin with unambiguous words (verbs -- compute, set, initialize). Selection statements then-part and else-part should be indented. Selection statements end with the keyword end_if.

CMSC 104: Peter Olsen, Fall 99Lecture 9:24 Conventions (III) Repetition statements end with end_while. Loop-bodies are indented. All words in a pseudo-code statement must be chosen to be unambiguous, and as easy as possible to understand by non- programmers. Enclose comments between /* and */

CMSC 104: Peter Olsen, Fall 99Lecture 9:25 Example Set correctIncomeInput to ‘n’ while correctIncomeInput is equal to ‘n’ print “Enter taxable income: Should not be less than read income if income is equal to or greater than set correctIncomeInput to ‘y’ end_if end_while

CMSC 104: Peter Olsen, Fall 99Lecture 9:26 Flowcharting Flowcharting is another technique used in designing and representing algorithms. A flowchart is a graph consisting of geometric shapes that are connected by flow lines.

CMSC 104: Peter Olsen, Fall 99Lecture 9:27 Symbols Terminal symbol Process symbol Input-Output symbol

CMSC 104: Peter Olsen, Fall 99Lecture 9:28 Symbols (III) Flow Lines indicating the logical sequence of statements

CMSC 104: Peter Olsen, Fall 99Lecture 9:29 Flowchart If Keyboard Process