Algorithms. Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing.

Slides:



Advertisements
Similar presentations
C Programming Technique – Firdaus-Harun.com
Advertisements

ALGORITHMS AND FLOWCHARTS
More on Algorithms and Problem Solving
PROBLEM SOLVING TECHNIQUES
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
 Control structures  Algorithm & flowchart  If statements  While statements.
 2002 Prentice Hall. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 The if Selection Structure.
Chapter 3 - Structured Program Development
Introduction to Computers and Programming Lecture 5 New York University.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
Introduction to Computers and Programming Lecture 8: More Loops New York University.
Program Design and Development
Introduction to Computers and Programming Lecture 5 Boolean type; if statement Professor: Evan Korth New York University.
Introduction to Computers and Programming More Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Control Structure.
1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection Statement 4.6 if else Selection Statement 4.7 while.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control.
Chapter 2: Algorithm Discovery and Design
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection.
Structured Program Development in C
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering.
Chapter 2: Algorithm Discovery and Design
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection.
ALGORITHMS AND FLOWCHARTS
The University of Texas – Pan American
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Simple Program Design Third Edition A Step-by-Step Approach
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
Structured Program Development Outline 2.1Introduction 2.2Algorithms 2.3Pseudo code 2.4Control Structures 2.5The If Selection Structure 2.6The If/Else.
PSEUDOCODE C Programming Technique – Firdaus-Harun.com.
C Lecture Notes 1 Structured Program Development.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
C++ Programming Lecture 6 Control Structure II (Repetition) By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Control Structures: Part 1.
1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 The if Selection Structure 4.6 The if / else Selection Structure 4.7.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection.
Unit 2 – Algorithms & Pseudocode. Algorithms Computer problems solved by executing series of action in order Procedure –The Actions to execute –The Order.
Structured Program Development Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010.
1 Lecture 3 Control Structures else/if and while.
Lecture 5: Stopping with a Sentinel. Using a Sentinel Problem Develop a class-averaging program that will process an arbitrary number of grades each time.
Chapter 3 Structured Program Development Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
ALGORITHMS AND FLOWCHARTS. A typical programming task can be divided into two phases: Problem solving phase  produce an ordered sequence of steps that.
Lecture 2: Introduction to Programming EEE2108: 공학프로그래밍 서강대학교 전자공학과 2011 학년도 2 학기 - Algorithms and Flowcharts -
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (while) Outline 3.7The While Repetition.
JavaScript: Control Structures I Outline 1 Introduction 2 Algorithms 3 Pseudocode 4 Control Structures 5 if Selection Structure 6 if/else Selection Structure.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 23, 2005 Lecture Number: 11.
ALGORITHMS AND FLOWCHARTS
Algorithm: procedure in terms of
GC101 Introduction to computers and programs
Unit 3: ALGORITHMS AND FLOWCHARTS
CS111 Computer Programming
Programming Fundamentals
ALGORITHMS AND FLOWCHARTS
Problem Solving Techniques
MSIS 655 Advanced Business Applications Programming
Structured Program
Chapter 3 - Structured Program Development
ALGORITHMS AND FLOWCHARTS
Chapter 3 - Structured Program Development
Click to add Text Computers & Instructions. Computers are given instructions in the form of computer programs that are created through the development.
Introduction to Programming
Programming Concepts and Database
Chapter 4 - Control Structures: Part 1
EPSII 59:006 Spring 2004.
Structural Program Development: If, If-Else
Presentation transcript:

Algorithms

Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing a program: –Know your “building blocks” (e.g. data types, data structures, control structures, selection structures, etc) –Use good programming principles for efficiency and correct results

Pseudocode What is pseudocode? –Artificial, informal language that helps us develop algorithms –Similar to everyday English –Not actually executed on computers –Helps us “think out” a program before writing it Converts into a corresponding program Consists only of executable statements

Formulating Algorithms with Top-Down, Stepwise Refinement First, define the problem in words: For palindromes, the problem becomes: What are the steps necessary to test the string?

Formulating Algorithms with Top-Down, Stepwise Refinement, Step 2: Top-down, stepwise refinement –Begin with a pseudocode representation of the problem: Determine whether the string is a palindrome –Divide the problem into smaller tasks and list them in order: Initialize variables and arrays Input the string Test the string Return the result Many programs have four phases: –Initialization: declare & initialize all program variables –Input: input data values and adjust any program variables –Processing: manipulate the data –Termination: calculate and print the final results (output)

Formulating Algorithms with Top-Down, Stepwise Refinement, Step 3: Refine the initialization phase from Initialize variables to: set any counters to zero determine the data type & length of the array and declare it Refine test the string to Check first and last elements While the first and last elements are the same, continue If they differ, exit and the string is not a palindrome Otherwise, test until all pairs are matched

Formulating Algorithms with Top-Down, Stepwise Refinement, Step 4: Refine Print the result to If the string is a palindrome Print “The string … is a palindrome.” else Print “The string … is not a palindrome.”