Algorithm & Programming

Slides:



Advertisements
Similar presentations
PROBLEM SOLVING TECHNIQUES
Advertisements

ALGORITHMS AND FLOWCHARTS
 Control structures  Algorithm & flowchart  If statements  While statements.
Program Design and Development
Pseudocode and Algorithms
Pseudocode.
1 Chapter 2 Problem Solving Techniques INTRODUCTION 2.2 PROBLEM SOLVING 2.3 USING COMPUTERS IN PROBLEM SOLVING : THE SOFTWARE DEVELOPMENT METHOD.
Pseudocode.
Chapter 3 Planning Your Solution
Review Algorithm Analysis Problem Solving Space Complexity
ALGORITHMS AND FLOW CHARTS 1 Adapted from the slides Prepared by Department of Preparatory year Prepared by: lec. Ghader Kurdi.
Fundamentals of C programming
ALGORITHMS AND FLOWCHARTS
DCT 1123 Problem Solving & Algorithms
Sw development1 Software Development 1.Define the problem (Analysis) 2.Plan the solution 3.Code 4.Test and debug 5.Maintain and Document.
Software Life Cycle What Requirements Gathering, Problem definition
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.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Chapter 2 Pseudocode. Objectives To introduce common words, keywords and meaningful names when writing pseudocode To define the three basic control structures.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
Chapter 2: General Problem Solving Concepts
1 Program Planning and Design Important stages before actual program is written.
The Hashemite University Computer Engineering Department
Problem, Problem Solving, Algorithm & Flow Charts –Part 1 Presented By Manesh T Course:101 CS 101CS Manesh T1.
WHAT IS THIS? Clue…it’s a drink SIMPLE SEQUENCE CONTROL STRUCTURE Introduction A computer is an extremely powerful, fast machine. In less than a second,
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.
Introduction to Flowcharts
Program Program is a collection of instructions that will perform some task.
Lecture 2: Introduction to Programming EEE2108: 공학프로그래밍 서강대학교 전자공학과 2011 학년도 2 학기 - Algorithms and Flowcharts -
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
 Problem Analysis  Coding  Debugging  Testing.
Program design Program Design Process has 2 phases:
ALGORITHMS AND FLOWCHARTS
GC101 Introduction to computers and programs
Problem Solving Concepts
Unit 3: ALGORITHMS AND FLOWCHARTS
Problem , Problem Solving, Algorithm & Flow Charts –Part 1
1-1 Logic and Syntax A computer program is a solution to a problem.
ALGORITHMS AND FLOWCHARTS
COVERED BASICS ABOUT ALGORITHMS AND FLOWCHARTS
CS111 Computer Programming
Algorithms and Flowcharts
Pseudocode Upsorn Praphamontripong CS 1110 Introduction to Programming
Understand Problem Solving Tools to Design Programming Solutions
Lecture 2 Introduction to Programming
Introduction To Flowcharting
Programming Fundamentals
Algorithm and Ambiguity
CHAPTER 2 & 3: Pseudocode and Developing and Algorithm
ALGORITHMS AND FLOWCHARTS
PROBLEM SOLVING AND OFFICE AUTOMATION
Control Structure Senior Lecturer
Unit# 9: Computer Program Development
Problem Solving Techniques
ALGORITHMS AND FLOWCHARTS
Pseudocode.
Structured Program
1) C program development 2) Selection structure
ALGORITHMS AND FLOWCHARTS
Chapter 2- Visual Basic Schneider
Introduction to Algorithms and Programming
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Chapter 2- Visual Basic Schneider
Understanding Problems and how to Solve them by using Computers
Introduction to Programming
Basic Concepts of Algorithm
Presentation transcript:

Algorithm & Programming Subject : T0016 – ALGORITHM AND PROGRAMMING Year : 2013 Algorithm & Programming

T0016 - Algorithm and Programming Learning Outcomes At the end of this session, student will be able to: Define algorithm theory and design (LO1) T0016 - Algorithm and Programming

T0016 - Algorithm and Programming Sub Topics Algorithm and Programming: Algorithm Definition Algorithm Development Steps Pseudo-code Flow Chart Structured Theorem Exercise T0016 - Algorithm and Programming

T0016 - Algorithm and Programming Algorithm Definition Algorithm is a procedure for solving a problem in terms of the actions to be executed, and the order in which these actions are to be executed Derived from the word algoris and ritmis. Introduced by Al-Khowarizmi. In the programming domain, algorithm define as method that consist of structured steps in problem solving using computer. T0016 - Algorithm and Programming

Simple Algorithm Example Rise and Shine Algorithm Get out of bed Take off pajamas Take a shower Get dressed Eat breakfast Carpool to work T0016 - Algorithm and Programming

Algorithm Development Steps Executable code: => Run PROBLEM PROCESS SOLUTION Algorithm Source Code Executable Code Problem Definition Model Development Algorithm Design Writing Code COMPILE Syntax Err Executable code: => Run Output Err T0016 - Algorithm and Programming Documentation

Algorithm Development Steps Executable code: => Run Problem Definition Model Development Algorithm Design Writing Code COMPILE Problem: Finding the solution or root of quadratic equation Definition: Quadratic equation : ax^2 + bx + c = 0 Data needed: Coefficient of a, b and c : real type Syntax Err Executable code: => Run Output Err Documentation T0016 - Algorithm and Programming

Algorithm Development Steps Executable code: => Run Problem Definition Model Development Algorithm Design Writing Code COMPILE Syntax Err Mathematical model: Quadratic formula: x1 = (-b + sqrt(b^2 - 4ac))/2a x2 = (-b – sqrt(b^2 - 4ac))/2a Executable code: => Run Output Err Documentation T0016 - Algorithm and Programming

Algorithm Development Steps Executable code: => Run Problem Definition Model Development Algorithm Design Writing Code Start COMPILE Input a,b,c Syntax Err d = b^2 – 4ac Executable code: => Run Y d < 0 T Output Err x1=(-b+sqrt(d))/2a x2 =(-b-sqrt(d))/2a Print: “Imaginary” Documentation Print : x1, x2 T0016 - Algorithm and Programming Stop

Algorithm Development Steps Executable code: => Run Problem Definition Model Development Algorithm Design Writing Code COMPILE Syntax Err Executable code: => Run Output Err Documentation T0016 - Algorithm and Programming

Algorithm Development Steps Executable code: => Run Problem Definition Model Development Algorithm Design Writing Code COMPILE Syntax Err Executable code: => Run Output Err Documentation T0016 - Algorithm and Programming

Algorithm Development Steps Executable code: => Run Problem Definition Model Development Algorithm Design Writing Code COMPILE Syntax Err Executable code: => Run Output Err Documentation T0016 - Algorithm and Programming

Algorithm Development Steps Executable code: => Run Problem Definition Model Development Algorithm Design Writing Code COMPILE Syntax Err Executable code: => Run Output Err Documentation T0016 - Algorithm and Programming

Algorithm Development Steps Executable code: => Run Problem Definition Model Development Algorithm Design Writing Code COMPILE Syntax Err Executable code: => Run Output Err Documentation T0016 - Algorithm and Programming

Algorithm Development Steps Executable code: => Run Problem Definition Model Development Algorithm Design Writing Code COMPILE Syntax Err Executable code: => Run Output Err Documentation T0016 - Algorithm and Programming

Representing Algorithm How to develop an algorithm? We can use: Writing Structure English and Pseudo-code. Drawing Flow Chart T0016 - Algorithm and Programming

T0016 - Algorithm and Programming Pseudo-code An artificial and informal language that helps you develop algorithms Pseudo-code is similar to everyday English, convenient, and user friendly Keywords are used to describe control structure Example: if, else, print, set, add, while, etc. T0016 - Algorithm and Programming

T0016 - Algorithm and Programming Pseudo-code Basic Computer Operation: Input Output Compute Storing value to an identifier (Store) Compare Repetition (Loop) T0016 - Algorithm and Programming

T0016 - Algorithm and Programming 1. Input Statements can be used when a computer receive information or input Read, Get, Input or Key-In Example: Read bilangan Get tax_code Baca students_name T0016 - Algorithm and Programming

T0016 - Algorithm and Programming 2. Output Statements can be used when a computer displaying information or output: Print, Write, Put, Output, or Display Example: Print “Bina Nusantara University” Write “Algorithm and Programming” Output Total T0016 - Algorithm and Programming

T0016 - Algorithm and Programming 3. Compute To do arithmetic calculation the following operators are used: + (add) - (subtract) * (multiply) / (divide) () (scope) Statement Compute, Calculate or Add also can be used Example: Add number to total Total = Total + number T0016 - Algorithm and Programming

4. Storing Value to An Identifier (Store) There are three ways of storing value into a variable: Initializing value using statement Initialize or Set Storing value as calculation result using = To simply store a value into a variable using “Save” or Store Example: Set Counter to 0 Total = Price * Qty T0016 - Algorithm and Programming

T0016 - Algorithm and Programming 5. Compare One of the main operation in computing is comparing values and choosing options based on its result Keyword used: IF, THEN and ELSE Example: IF Menu=‘1’ THEN Discount = 0.1 * price ELSE Discount = 0.2 * price ENDIF T0016 - Algorithm and Programming

T0016 - Algorithm and Programming 6. Repetition (Looping) To repeat an action/step, we use keyword DOWHILE and ENDDO Example: DOWHILE number < 10 print number number = number +1 ENDDO T0016 - Algorithm and Programming

T0016 - Algorithm and Programming Pseudo-code Example Example : Algorithm using a calculator Start Set the calculator ON Empty any values Do Input price Push plus button (+) while all prices have been input print total price turn OFF calculator End T0016 - Algorithm and Programming

T0016 - Algorithm and Programming Pseudo-code Example Example : Algorithm Class Average Start Set total to zero Set grade counter to one While grade counter is less than or equal to ten Input the next grade Add the grade into the total Add one to the grade counter Set the class average to the total divided by ten Print the class average. End T0016 - Algorithm and Programming

T0016 - Algorithm and Programming Flow Chart T0016 - Algorithm and Programming

T0016 - Algorithm and Programming Flow Chart Example Start Input a,b,c d = b^2 – 4ac Y d < 0 T x1=(-b+sqrt(d))/2a x2 =(-b-sqrt(d))/2a Print message “Imaginary” Print: x1, x2 Stop T0016 - Algorithm and Programming

Good Algorithm Practice Having the right logical flow to solve the problem Producing the correct output in a time efficient manner Written using unambiguous structured language Easy implementation into real programming language All steps and operations are clearly defined and ended T0016 - Algorithm and Programming

T0016 - Algorithm and Programming Structure Theorem Structure theorem which makes the computer programming possible using only three control structure, which are: Sequence Selection Repetition T0016 - Algorithm and Programming

T0016 - Algorithm and Programming 1. Sequence Sequence is series of consecutive commands/statements Commonly programming language has sequence of statements flowing from top of the program to its end T0016 - Algorithm and Programming

T0016 - Algorithm and Programming 1. Sequence Example : Print “Number of students:” Set total to 49 Print “Add new student:” Read newStudent total = total + newStudent Print total Description Sequence of command is from the 1st line to the end of code. If newStudent input is 2 then total that later on printed out is 51 T0016 - Algorithm and Programming

T0016 - Algorithm and Programming 2. Selection Selection control structure is structure that allow us to choose from several options of statement/command The first statement will be executed if the condition is satisfied, if not then the else statement will be executed (if the other exist) T0016 - Algorithm and Programming

T0016 - Algorithm and Programming 2. Selection Example : IF Day=1 THEN Print “Monday” ELSE Print “Obviously not Monday” Description The word “Monday” will be printed out if Day’s value equal to 1, else it will print out the sentence “Obviously not Monday”. T0016 - Algorithm and Programming

T0016 - Algorithm and Programming 3. Repetition A number of statements/commands can be repeated several times using Repetition structure control Statements/commands will be repeated while the looping condition is satisfied (may use DOWHILE – ENDDO) T0016 - Algorithm and Programming

T0016 - Algorithm and Programming 3. Repetition Example : Stars = 0 DOWHILE Stars < 5 Print Stars Stars = Stars + 1 ENDDO Description At first Stars’ value equals to 0, after following the DOWHILE looping Stars’ value will be updated 5 times resulting: 0 1 2 3 4 T0016 - Algorithm and Programming

T0016 - Algorithm and Programming Exercise Using the Pseudo-code, create: an algorithm to calculate a rectangle area! an algorithm to change second into hour and minute unit! an algorithm to decide whether an input number is an odd or even number! an algorithm to calculate a circle area! an algorithm to accept three numbers and find the max number! Repeat no. 1 using Flow Chart T0016 - Algorithm and Programming

T0016 - Algorithm and Programming Summary Algorithm is a procedure for solving a problem in terms of the actions to be executed Algorithm development steps consists of: problem definition, model development, algorithm design, writing code, and documentation We can use writing (Structure English and Pseudo-code) or drawing (Flow Chart) to represent algorithm Basic Computer Operation: input, output, compute, store, compare, and repetition (loop) Structure theorem are sequence, selection, and repetition T0016 - Algorithm and Programming

T0016 - Algorithm and Programming References Paul J. Dietel,Harvey M. Deitel,. 2010. C : how to program. PEAPH. New Jersey. ISBN:978-0-13-705966-9 Chapter 3 Programming in C: http:// www.cs.cf.ac.uk/Dave/C/ C Language Tutorial: http://www.physics.drexel.edu/courses/Comp_Phys/General/C_basics/ Pseudocode Examples: http://www.unf.edu/~broggio/cop2221/2221pseu.htm Computer & Internet Help : Understanding Flowchart Symbols: http://www.youtube.com/watch?v=xLoL7tlJYws T0016 - Algorithm and Programming

T0016 - Algorithm and Programming END T0016 - Algorithm and Programming