Unit 3: ALGORITHMS AND FLOWCHARTS

Slides:



Advertisements
Similar presentations
ALGORITHMS AND FLOWCHARTS
Advertisements

ALGORITHMS AND FLOWCHARTS
Summer ’12 AP Computer Science APCS Summer Assignments Read thoroughly this ppt and solve examples 6 and 7.
ALGORITHMS AND FLOWCHARTS
PROBLEM SOLVING TECHNIQUES
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
ALGORITHMS AND FLOWCHARTS
Fundamentals of Algorithms MCS - 2 Lecture # 4
Chapter 2- Visual Basic Schneider
Algorithms. Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing.
Developing logic (Examples on algorithm and flowchart)
Review Algorithm Analysis Problem Solving Space Complexity
PRE-PROGRAMMING PHASE
ALGORITHMS AND FLOW CHARTS 1 Adapted from the slides Prepared by Department of Preparatory year Prepared by: lec. Ghader Kurdi.
Fundamentals of C programming
Chapter 1 Pseudocode & Flowcharts
ALGORITHMS AND FLOWCHARTS
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.
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
CSC141 Introduction to Computer Programming
Software Life Cycle What Requirements Gathering, Problem definition
Algorithm & Flow Charts
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.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
Flowcharting & Algorithms. Quick. Close your Eyes and Listen You are still sitting in the classroom. However, you have been called to the counselor’s.
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.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that.
Concepts of Algorithms CSC-244 Unit Zero Pseudo code, Flowchart and Algorithm Master Prince Computer College Qassim University K.S.A.
Problem, Problem Solving, Algorithm & Flow Charts –Part 1 Presented By Manesh T Course:101 CS 101CS Manesh T1.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
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
Lecture 2: Introduction to Programming EEE2108: 공학프로그래밍 서강대학교 전자공학과 2011 학년도 2 학기 - Algorithms and Flowcharts -
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
Lecture 3 Computer Programming -1-. The main steps of program development to solve the problem: 1- problem definition : The problem must be defined into.
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
Program design Program Design Process has 2 phases:
Problem Solving & Computer Programming
ALGORITHMS AND FLOWCHARTS
GC101 Introduction to computers and programs
Algorithm & Flow Charts Week 1
Problem Solving Concepts
Problem , Problem Solving, Algorithm & Flow Charts –Part 1
Algorithm & Programming
Chapter 2- Visual Basic Schneider
ALGORITHMS AND FLOWCHARTS
FLOWCHARTS.
COVERED BASICS ABOUT ALGORITHMS AND FLOWCHARTS
CS111 Computer Programming
Algorithms and Flowcharts
Algorithms An algorithm is a sequence of steps written in the form of English phrases that specific the tasks that are performed while solving the problem.It.
Lecture 2 Introduction to Programming
Introduction To Flowcharting
Algorithm Algorithm is a step-by-step procedure or formula or set of instruction for solving a problem Its written in English language or natural language.
ALGORITHMS AND FLOWCHARTS
Unit# 9: Computer Program Development
Problem Solving Techniques
ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTS
Chapter 2- Visual Basic Schneider
Introduction to Algorithms and Programming
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Chapter 2- Visual Basic Schneider
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
Basic Concepts of Algorithm
Presentation transcript:

Unit 3: ALGORITHMS AND FLOWCHARTS

The Big Picture (SDLC) Problem definition Analysis Design Coding Running the program Debugging Testing Documentation

ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe solution of problem this sequence of steps is called an algorithm Implementation phase implement the program in some programming language

Steps in Problem Solving First produce a general algorithm (one can use pseudocode) Refine the algorithm successively to get step by step detailed algorithm that is very close to a computer language. Pseudocode is an informal language that helps programmers develop algorithms. Pseudocode is very similar to everyday English.

Pseudocode & Algorithm Example: Write an algorithm to determine a student’s final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four marks.

Pseudocode & Algorithm Input a set of 4 marks Calculate their average by summing and dividing by 4 if average is below 50 Print “FAIL” else Print “PASS”

Algorithmic Notations Name of the algorithm Step number Explanatory comment Termination

Characteristics of an Algorithm Input: It may accept zero or more inputs. Output: It should produce at least one result. Definiteness: clear, precise no ambiguity. Finiteness: in sequence, no infinite loops. Effectiveness: must solve the given problem for any input.

Pseudocode & Algorithm Detailed Algorithm Algorithm: Determine Results Step 1: Input M1,M2,M3,M4 Step 2: GRADE  (M1+M2+M3+M4)/4 Step 3: if (GRADE < 50) then Print “FAIL” else Print “PASS” endif Step 4: Stop

The Flowchart (General) A schematic representation of a sequence of operations, as in a manufacturing process or computer program. (Technical) A graphical representation of the sequence of operations in an system or program. System flowcharts show how data flows from source modules through the computer to other modules. Program flowcharts show the sequence of instructions in a single program or subroutine. Different symbols are used to draw each type of flowchart.

The Flowchart A Flowchart shows logic of an algorithm emphasizes individual steps and their interconnections e.g. control flow from one action to the next

Flowchart Symbols

Example Algorithm: Determine Results Step 1: Input M1,M2,M3,M4 START Input M1,M2,M3,M4 GRADE(M1+M2+M3+M4)/4 IS GRADE<50 PRINT “FAIL” STOP Y N Algorithm: Determine Results Step 1: Input M1,M2,M3,M4 Step 2: GRADE  (M1+M2+M3+M4)/4 Step 3: if (GRADE <50) then Print “FAIL” else Print “PASS” endif Step 4: Stop PRINT “PASS”

Example Write an algorithm and draw a flowchart that will read the two sides of a rectangle and calculate its area. Pseudocode Input the width (W) and Length (L) of a rectangle Calculate the area (A) by multiplying L with W Print A

Example Step 1: Input W,L Step 2: A  L x W Step 3: Print A Algorithm: Compute Area Step 1: Input W,L Step 2: A  L x W Step 3: Print A Step 4: Stop START Input W, L A  L x W Print A STOP

Example Write an algorithm and draw a flowchart that will calculate the roots of a quadratic equation Hint: d = sqrt ( ), and the roots are: x1 = (–b + d)/2a and x2 = (–b – d)/2a

Example Pseudocode: Input the coefficients (a, b, c) of the quadratic equation Calculate d Calculate x1 Calculate x2 Print x1 and x2

Example Algorithm: Quadratic Roots Step 1: Input a, b, c START Input a, b, c d  sqrt(b x b – 4 x a x c) Print x1 ,x2 STOP x1 (–b + d) / (2 x a) X2  (–b – d) / (2 x a) Algorithm: Quadratic Roots Step 1: Input a, b, c Step 2: d  sqrt ( ) Step 3: x1  (–b + d) / (2 x a) Step 4: x2  (–b – d) / (2 x a) Step 5: Print x1, x2 Step 6: Stop

Example Write an algorithm that reads two values, determines the largest value and prints the largest value with an identifying message. ALGORITHM: Largest of 2 values Step 1: Input VALUE1, VALUE2 Step 2: if (VALUE1 > VALUE2) then MAX  VALUE1 else MAX  VALUE2 endif Step 3: Print “The largest value is”, MAX Step 4: Stop

“The largest value is”, MAX Example MAX  VALUE1 Print “The largest value is”, MAX STOP Y N START Input VALUE1,VALUE2 MAX  VALUE2 is VALUE1>VALUE2

Introduction to C Structured Programming Language High level Machine Independent

History ALGOL- Root of all the modern languages (Structured Programming) BCPL and B- Both are typeless system programming languages C – Dennis Ritchie in 1972 Kerningham and Ritchie C- K&R C

Importance of C Robust, rich build-in functions Efficient and fast Portable Functions/Blocks Extendable

Sample Program main() { /*-------printing begins-------*/ printf (“C-Programming class”); }

Forms of main main() main(void) void main() void main(void) int main() int main(void)

Executing a ‘C’ Program Creating the program Compiling the program Linking the program with C library Executing the program