SlideShare a Scribd company logo
ALGORITHMS &
FLOWCHARTS
Monday, November 21, 2016
LEARNING OUTCOMES
At the end of the lesson, I should be able to:
a. -Define algorithm, Pseudo codes and flowchart
b. -State characteristics of Algorithms
c. -Outline functions of Algorithm
d. -Write algorithm for solving a given problem
e. -Flowchart symbols and their uses
f. -Translating algorithms to flowchart programs
g. -Draw flowcharts for solving given problems
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
1. First produce a general algorithm: (one can
use pseudo code)
2. Refine the algorithm successively to get
step by step detailed algorithm that is very
close to a computer language.
3. Pseudo code is an artificial and informal
language that helps programmers develop
algorithms. Pseudo code is very similar to
everyday English.
PSEUDOCODE & ALGORITHM
1. Example 1: 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
Pseudo code:
1. Input a set of 4 marks
2. Calculate their average by summing and
dividing by 4
3. if average is below 50
Print “FAIL”
else
Print “PASS”
PSEUDOCODE & ALGORITHM
Detailed Algorithm:
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
THE FLOWCHART
A Flowchart is a graphical representation of the sequence
of operations in an information system or program.
Flowchart Characteristics:
1. shows the sequence of instructions in a single program or
subroutine
2. shows logic of an algorithm from start to finish
3. emphasizes individual steps and their interconnections
4. control flow from one action to the next
5. Different symbols are used to draw each type of flowchart
6. The start symbol indicates the beginning of a program
7. The end symbol indicate the end of a program.
FLOWCHART SYMBOLS
Oval
Parallelogram
Rectangle
Diamond
Hybrid
Name Symbol Use in Flowchart
Denotes the beginning or end of the program
Denotes an input operation
Denotes an output operation
Denotes a decision (or branch) to be made.
The program should continue along one of
two routes. (e.g. IF/THEN/ELSE)
Denotes a process to be carried out
e.g. addition, subtraction, division etc.
Flow line Denotes the direction of logic flow in the program
Oval
Parallelogram
Rectangle
Diamond
Hybrid
Name Symbol Use in Flowchart
Denotes the beginning or end of the program
Denotes an input operation
Denotes an output operation
Denotes a decision (or branch) to be made.
The program should continue along one of
two routes. (e.g. IF/THEN/ELSE)
Denotes a process to be carried out
e.g. addition, subtraction, division etc.
Flow line Denotes the direction of logic flow in the program
FLOWCHART SOLUTION TO EXAMPLE 1
PRINT
“PASS”
Algorithm:
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
START
Input
M1,M2,M3,M4
GRADE(M1+M2+M3+M4)/4
IS
GRADE<5
0
PRINT
“FAIL”
STOP
YN
EXAMPLE 2
Write an algorithm and draw a flowchart to convert
the length in feet to centimeter.
Pseudo code:
1. Input the length in feet (Lft)
2. Calculate the length in cm (Lcm) by multiplying
LFT with 30
3. Print length in cm (LCM)
Algorithm
Step 1: Input Lft
Step 2: Lcm  Lft x 30
Step 3: Print Lcm
START
Input
Lft
Lcm  Lft x 30
Print
Lcm
STOP
Flowchart
EXAMPLE 3
Write an algorithm and draw a flowchart
that will read the two sides of a rectangle
and calculate its area.
Pseudocode
1. Input the width (W) and Length (L) of a
rectangle
2. Calculate the area (A) by multiplying L with
W
3. Print A
Algorithm
Step 1: Input W,L
Step 2: A  L x W
Step 3: Print A
START
Input
W, L
A  L x W
Print
A
STOP
EXAMPLE 4
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
2
0ax bx c  
2
4b ac
Pseudo code:
1. Input the coefficients (a, b, c) of the quadratic
equation
2. Calculate d
3. Calculate x1
4. Calculate x2
5. Print x1 and x2
Algorithm:
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
4b b a 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)
ASSIGNMENT
Provide the answer to question number 4 on page
109 of your HiiT textbook.
TERMINOLOGIES
An algorithm is a step by step procedure in solving a
problem
Pseudo code is an artificial and informal language
that helps programmers develop algorithms. Pseudo
code is very similar to everyday English.
Flowchart is a graphical representation of the
sequence of operations in an information system or
program.
END OF LESSON NOTE
ALGORITHMS &
FLOWCHARTS II
Monday, November 21, 2016
LEARNING OUTCOMES
DECISION STRUCTURES
 The expression A>B is a logical expression
 it describes a condition we want to test
 if A>B is true (if A is greater than B) we take
the action on left
 print the value of A
 if A>B is false (if A is not greater than B) we
take the action on right
 print the value of B
DECISION STRUCTURES
is
A>B
Print
B
Print
A
Y N
IF–THEN–ELSE STRUCTURE
 The structure is as follows:
If condition then
true alternative
else
false alternative
endif
IF–THEN–ELSE STRUCTURE
 The algorithm for the flowchart is as follows:
If A>B then
print A
else
print B
endif
is
A>B
Print
B
Print
A
Y N
RELATIONAL OPERATORS
Relational Operators
Operator Description
> Greater than
< Less than
= Equal to
 Greater than or equal to
 Less than or equal to
 Not equal to
EXAMPLE 5
 Write an algorithm that reads two values,
determines the largest value and prints the largest
value with an identifying message.
ALGORITHM
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
MAX  VALUE1
Print
“The largest value is”,
MAX
STOP
Y N
START
Input
VALUE1,VALUE2
MAX  VALUE2
is
VALUE1>VALUE2
NESTED IFS
 One of the alternatives within an IF–THEN–ELSE
statement
 may involve further IF–THEN–ELSE statement
EXAMPLE 6
 Write an algorithm that reads three numbers and
prints the value of the largest number.
Step 1: Input N1, N2, N3
Step 2: if (N1>N2) then
if (N1>N3) then
MAX  N1 [N1>N2, N1>N3]
else
MAX  N3 [N3>N1>N2]
endif
else
if (N2>N3) then
MAX  N2 [N2>N1, N2>N3]
else
MAX  N3 [N3>N2>N1]
endif
endif
Step 3: Print “The largest number is”, MAX
EXAMPLE 7
 Write and algorithm and draw a flowchart to
a) read an employee name (NAME), overtime hours
worked (OVERTIME), hours absent (ABSENT)
and
b) determine the bonus payment (PAYMENT).
Step 1: Input NAME,OVERTIME,ABSENT
Step 2: if (OVERTIME–(2/3)*ABSENT > 40) then
PAYMENT  50
else if (OVERTIME–(2/3)*ABSENT > 30) then
PAYMENT  40
else if (OVERTIME–(2/3)*ABSENT > 20) then
PAYMENT  30
else if (OVERTIME–(2/3)*ABSENT > 10) then
PAYMENT 20
else
PAYMENT  10
endif
Step 3: Print “Bonus for”, NAME “is $”, PAYMENT
Bonus Schedule
OVERTIME – (2/3)*ABSENT Bonus Paid
>40 hours
>30 but  40 hours
>20 but  30 hours
>10 but  20 hours
 10 hours
$50
$40
$30
$20
$10
THANK YOU.

More Related Content

PPTX
Flowchart and algorithm
PPTX
Chapter 6 algorithms and flow charts
PPTX
Algorithm and flowchart
PPT
3 algorithm-and-flowchart
PPTX
Algorithms, flow charts and pseudocodes
PPT
Problem solving using Computer
PPT
pseudo code basics
PPTX
Programming flowcharts for C Language
Flowchart and algorithm
Chapter 6 algorithms and flow charts
Algorithm and flowchart
3 algorithm-and-flowchart
Algorithms, flow charts and pseudocodes
Problem solving using Computer
pseudo code basics
Programming flowcharts for C Language

What's hot (20)

PPTX
Algorithms and Flowcharts
PPTX
Introduction to flowchart
PPTX
ppt of flowchart
PPTX
Unit 1. Problem Solving with Computer
PPTX
Introduction to programming
PPT
Basic concept of OOP's
PPSX
Algorithm and flowchart
PDF
Pseudocode & flowchart examples
PPTX
Algorithm and flowchart
PPTX
register
PPTX
Algorithm and pseudo codes
PPTX
Programming Fundamentals
PPTX
PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMING
PPTX
Basic Computer Organization and Design
PPT
Introduction to Algorithms & flow charts
PPTX
Introduction to c programming
PPTX
Loops in c programming
PPTX
System Programming Unit II
PPTX
Introduction to Data Structure & algorithm
DOCX
C language industrial training report
Algorithms and Flowcharts
Introduction to flowchart
ppt of flowchart
Unit 1. Problem Solving with Computer
Introduction to programming
Basic concept of OOP's
Algorithm and flowchart
Pseudocode & flowchart examples
Algorithm and flowchart
register
Algorithm and pseudo codes
Programming Fundamentals
PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMING
Basic Computer Organization and Design
Introduction to Algorithms & flow charts
Introduction to c programming
Loops in c programming
System Programming Unit II
Introduction to Data Structure & algorithm
C language industrial training report
Ad

Similar to Algorithms and flowcharts (20)

PPTX
Draw the flowchart of the above algorithm.pptx
PPT
Algorithms and flowcharts ppt (seminar presentation)..
PPTX
Algorithms-Flowcharts for programming fundamental
PPT
256958.ppt
PPT
01 Algorithms And Flowcharts.ppt
PPTX
Algorithmsandflowcharts1
PPT
Algorithmsandflowcharts1
PPT
Algorithmsandflowcharts1
PDF
Algorithms and flowcharts
PDF
algorithms and flow chart overview.pdf
PPT
Algorithms and Flowchart for IGCSE Students
PPT
Algorithms and Flowchart.ppt
PPT
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
PPT
Algorithms and Flowchart usages in C laguage
PDF
AlgorithmAndFlowChart.pdf
PPT
Best Techniques To Design Programs - Program Designing Techniques
PPT
Basic Slides on Algorithms and Flowcharts
PPT
Lect1-Algorithms-and-Flowchart-ppt (1).ppt
PPT
Lecture1-Algorithms-and-Flowchart-ppt.ppt
PPT
Lect1 - Algorithms-and-Flowchart-ppt.ppt
Draw the flowchart of the above algorithm.pptx
Algorithms and flowcharts ppt (seminar presentation)..
Algorithms-Flowcharts for programming fundamental
256958.ppt
01 Algorithms And Flowcharts.ppt
Algorithmsandflowcharts1
Algorithmsandflowcharts1
Algorithmsandflowcharts1
Algorithms and flowcharts
algorithms and flow chart overview.pdf
Algorithms and Flowchart for IGCSE Students
Algorithms and Flowchart.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
Algorithms and Flowchart usages in C laguage
AlgorithmAndFlowChart.pdf
Best Techniques To Design Programs - Program Designing Techniques
Basic Slides on Algorithms and Flowcharts
Lect1-Algorithms-and-Flowchart-ppt (1).ppt
Lecture1-Algorithms-and-Flowchart-ppt.ppt
Lect1 - Algorithms-and-Flowchart-ppt.ppt
Ad

More from Samuel Igbanogu (17)

PPTX
Systems development cycle
PPTX
Data conversion
PPTX
Classification of computers with respect to size
PPTX
Classification of computers by type
PPTX
Classification of computers by generation
PPT
File organisation
PPTX
Computer system soft ware
PPTX
Relational models
PPTX
Handling computer files
PPTX
Entity relationship model
PPTX
Output devices
PPTX
Concept of computer files
PPTX
Computing devices i
PPT
Logic gates i & ii
PPTX
Input devices
PPTX
Data models
PPTX
Normal forms
Systems development cycle
Data conversion
Classification of computers with respect to size
Classification of computers by type
Classification of computers by generation
File organisation
Computer system soft ware
Relational models
Handling computer files
Entity relationship model
Output devices
Concept of computer files
Computing devices i
Logic gates i & ii
Input devices
Data models
Normal forms

Recently uploaded (20)

PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Business Ethics Teaching Materials for college
PPTX
Pharma ospi slides which help in ospi learning
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Cell Types and Its function , kingdom of life
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Cell Structure & Organelles in detailed.
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Institutional Correction lecture only . . .
PPTX
PPH.pptx obstetrics and gynecology in nursing
VCE English Exam - Section C Student Revision Booklet
Business Ethics Teaching Materials for college
Pharma ospi slides which help in ospi learning
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Renaissance Architecture: A Journey from Faith to Humanism
O5-L3 Freight Transport Ops (International) V1.pdf
Cell Types and Its function , kingdom of life
Week 4 Term 3 Study Techniques revisited.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Cell Structure & Organelles in detailed.
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Anesthesia in Laparoscopic Surgery in India
Institutional Correction lecture only . . .
PPH.pptx obstetrics and gynecology in nursing

Algorithms and flowcharts

  • 2. LEARNING OUTCOMES At the end of the lesson, I should be able to: a. -Define algorithm, Pseudo codes and flowchart b. -State characteristics of Algorithms c. -Outline functions of Algorithm d. -Write algorithm for solving a given problem e. -Flowchart symbols and their uses f. -Translating algorithms to flowchart programs g. -Draw flowcharts for solving given problems
  • 3. 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
  • 4. STEPS IN PROBLEM SOLVING 1. First produce a general algorithm: (one can use pseudo code) 2. Refine the algorithm successively to get step by step detailed algorithm that is very close to a computer language. 3. Pseudo code is an artificial and informal language that helps programmers develop algorithms. Pseudo code is very similar to everyday English.
  • 5. PSEUDOCODE & ALGORITHM 1. Example 1: 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.
  • 6. PSEUDOCODE & ALGORITHM Pseudo code: 1. Input a set of 4 marks 2. Calculate their average by summing and dividing by 4 3. if average is below 50 Print “FAIL” else Print “PASS”
  • 7. PSEUDOCODE & ALGORITHM Detailed Algorithm: 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
  • 8. THE FLOWCHART A Flowchart is a graphical representation of the sequence of operations in an information system or program. Flowchart Characteristics: 1. shows the sequence of instructions in a single program or subroutine 2. shows logic of an algorithm from start to finish 3. emphasizes individual steps and their interconnections 4. control flow from one action to the next 5. Different symbols are used to draw each type of flowchart 6. The start symbol indicates the beginning of a program 7. The end symbol indicate the end of a program.
  • 9. FLOWCHART SYMBOLS Oval Parallelogram Rectangle Diamond Hybrid Name Symbol Use in Flowchart Denotes the beginning or end of the program Denotes an input operation Denotes an output operation Denotes a decision (or branch) to be made. The program should continue along one of two routes. (e.g. IF/THEN/ELSE) Denotes a process to be carried out e.g. addition, subtraction, division etc. Flow line Denotes the direction of logic flow in the program Oval Parallelogram Rectangle Diamond Hybrid Name Symbol Use in Flowchart Denotes the beginning or end of the program Denotes an input operation Denotes an output operation Denotes a decision (or branch) to be made. The program should continue along one of two routes. (e.g. IF/THEN/ELSE) Denotes a process to be carried out e.g. addition, subtraction, division etc. Flow line Denotes the direction of logic flow in the program
  • 10. FLOWCHART SOLUTION TO EXAMPLE 1 PRINT “PASS” Algorithm: 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 START Input M1,M2,M3,M4 GRADE(M1+M2+M3+M4)/4 IS GRADE<5 0 PRINT “FAIL” STOP YN
  • 11. EXAMPLE 2 Write an algorithm and draw a flowchart to convert the length in feet to centimeter. Pseudo code: 1. Input the length in feet (Lft) 2. Calculate the length in cm (Lcm) by multiplying LFT with 30 3. Print length in cm (LCM)
  • 12. Algorithm Step 1: Input Lft Step 2: Lcm  Lft x 30 Step 3: Print Lcm START Input Lft Lcm  Lft x 30 Print Lcm STOP Flowchart
  • 13. EXAMPLE 3 Write an algorithm and draw a flowchart that will read the two sides of a rectangle and calculate its area. Pseudocode 1. Input the width (W) and Length (L) of a rectangle 2. Calculate the area (A) by multiplying L with W 3. Print A
  • 14. Algorithm Step 1: Input W,L Step 2: A  L x W Step 3: Print A START Input W, L A  L x W Print A STOP
  • 15. EXAMPLE 4 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 2 0ax bx c   2 4b ac
  • 16. Pseudo code: 1. Input the coefficients (a, b, c) of the quadratic equation 2. Calculate d 3. Calculate x1 4. Calculate x2 5. Print x1 and x2
  • 17. Algorithm: 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 4b b a 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)
  • 18. ASSIGNMENT Provide the answer to question number 4 on page 109 of your HiiT textbook.
  • 19. TERMINOLOGIES An algorithm is a step by step procedure in solving a problem Pseudo code is an artificial and informal language that helps programmers develop algorithms. Pseudo code is very similar to everyday English. Flowchart is a graphical representation of the sequence of operations in an information system or program.
  • 23. DECISION STRUCTURES  The expression A>B is a logical expression  it describes a condition we want to test  if A>B is true (if A is greater than B) we take the action on left  print the value of A  if A>B is false (if A is not greater than B) we take the action on right  print the value of B
  • 25. IF–THEN–ELSE STRUCTURE  The structure is as follows: If condition then true alternative else false alternative endif
  • 26. IF–THEN–ELSE STRUCTURE  The algorithm for the flowchart is as follows: If A>B then print A else print B endif is A>B Print B Print A Y N
  • 27. RELATIONAL OPERATORS Relational Operators Operator Description > Greater than < Less than = Equal to  Greater than or equal to  Less than or equal to  Not equal to
  • 28. EXAMPLE 5  Write an algorithm that reads two values, determines the largest value and prints the largest value with an identifying message. ALGORITHM 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
  • 29. MAX  VALUE1 Print “The largest value is”, MAX STOP Y N START Input VALUE1,VALUE2 MAX  VALUE2 is VALUE1>VALUE2
  • 30. NESTED IFS  One of the alternatives within an IF–THEN–ELSE statement  may involve further IF–THEN–ELSE statement
  • 31. EXAMPLE 6  Write an algorithm that reads three numbers and prints the value of the largest number.
  • 32. Step 1: Input N1, N2, N3 Step 2: if (N1>N2) then if (N1>N3) then MAX  N1 [N1>N2, N1>N3] else MAX  N3 [N3>N1>N2] endif else if (N2>N3) then MAX  N2 [N2>N1, N2>N3] else MAX  N3 [N3>N2>N1] endif endif Step 3: Print “The largest number is”, MAX
  • 33. EXAMPLE 7  Write and algorithm and draw a flowchart to a) read an employee name (NAME), overtime hours worked (OVERTIME), hours absent (ABSENT) and b) determine the bonus payment (PAYMENT).
  • 34. Step 1: Input NAME,OVERTIME,ABSENT Step 2: if (OVERTIME–(2/3)*ABSENT > 40) then PAYMENT  50 else if (OVERTIME–(2/3)*ABSENT > 30) then PAYMENT  40 else if (OVERTIME–(2/3)*ABSENT > 20) then PAYMENT  30 else if (OVERTIME–(2/3)*ABSENT > 10) then PAYMENT 20 else PAYMENT  10 endif Step 3: Print “Bonus for”, NAME “is $”, PAYMENT
  • 35. Bonus Schedule OVERTIME – (2/3)*ABSENT Bonus Paid >40 hours >30 but  40 hours >20 but  30 hours >10 but  20 hours  10 hours $50 $40 $30 $20 $10