SlideShare a Scribd company logo
1 of 22
Chapter 2 Algorithm
Representation
Pseudocode and flow chart
Introduction
Performing a Task on The Computer
• The first step in writing instructions to carry out a task is to
determine what the output should be—that is, exactly
what the task should produce.
• The second step is to identify the data, or input, necessary
to obtain the output.
• The last step is to determine how to process the input to
obtain the desired output, that is, to determine what
formulas or ways of doing things can be used to obtain the
output.
Introduction
Programming Tools
• Tools used to convert algorithms into computer
programs:
• Pseudocode: An informal high-level description of the
operating principle of a computer program. It uses the
structural conventions of a programming language, but
is intended for human reading rather than machine
reading.
• Flowcharts: Graphically depict the logical steps to carry
out a task and show how the steps relate to each other.
How to write Pseudocode and draw
Flowcharts for a given algorithm
Pseudocode
•Artificial and Informal
language
•Helps programmers to
plan an algorithm
•Similar to everyday
English
•Not an actual
programming language
Flowcharts
•A graphical way of writing
pseudocode
•Rounded rectangle –
terminal
•Parallelogram – input /
output
•Rectangle – actions
•Diamonds – decision /
conditional
•Circles – connector
Example 1 - Pseudocode
-Start
-Read A, B
-Calculate
C = A*B
-Display C
-Stop
-Start
-Use variables A,B and C
-Display “write two
numbers”
-Read A, B
-Calculate C = A*B
-Display “multiplication of
numbers” , C
-Stop
Example – Flow chart
Decisions (selections)
If
If – else
Switch
Decisions (selections)
Loops (repetition)
While
Do – while
For
Loops (repetition)
Example - 2
• Write an algorithm to determine a student’s
average grade and indicate whether he is
successful or not.
• The average grade is calculated as the average
of mid-term and final marks.
• Student will be successful if his average grade
is grater or equals to 60.
Cont…
Pseudocode
- Start
- Use variables mid term , final and average
- Input mid term and final
- Calculate the average by summing mid term and
final and dividing by 2
- if average is below 60
Print “FAIL”
else
Print “SUCCESS”
- Stop
Cont…
• Detailed Algorithm
1. Step: Input mid-term and final
2. Step: average = (mid-term + final)/2
3. Step: if (average < 60) then
Print “FAIL”
else
Print “SUCCESS”
endif
Cont…
• Flow chart
Cont…
• Nested If Simply, if structure in if structure
Example - 3: Both final and average grades must
be grater than or equals to 2.0 for calculation in
DBU.
if (final >= 35) then
{ if (average >= 35) then
execute calculation commands
endif }
else
Print “F grade”
endif
Example - 3
• Write an algorithm which calculates the average exam
grade for a class of 5 students.
• What are the program inputs?
 The exam grades
• Processing:
 Find the sum of the grades;
 Count the number of students; (counter controlled)
 Calculate average grade = sum of grades / number of
students.
• What is the program output?
 The average exam grade
Cont…
Pseudocode
-Start
-Use variables total, counter, grade, average
-Initialize total = 0
-Initialize counter = 1
-While (counter <= 5)
Input grade
Calculate total = total + grade
Calculate counter = counter + 1
-End-while
Calculate average = total / 5
Display average
-Stop
Cont…
• Flow chart
Example 4
• Write an algorithm which calculates the average exam
grade for a class of unknown number of students.
• What are the program inputs?
 The exam grades
 Number of students
• Processing:
 Find the sum of the grades
 Calculate average grade = sum of grades / number of
students.
• What is the program output?
 The average exam grade
Cont…
Pseudocode
-Start
-Use variables total, counter, grade, average,
number_of_students
-Initialize total = 0 , number_of_students = 0 , counter = 1
-Display “write number of students”
-Input number_of_students
-While (counter <= number_of_students)
Input grade
Calculate total = total + grade
Calculate counter = counter + 1
-End-while
Calculate average = total / number_of_students
Display average
-Stop
Question
• Please try to draw the flow chart for the
above problem (example 4).

More Related Content

Similar to 2. Algorithms Representations (C++).pptx

Flowcharts and pseudocodes
Flowcharts and pseudocodesFlowcharts and pseudocodes
Flowcharts and pseudocodesDr Piyush Charan
 
learn computer science.ppt
learn computer science.pptlearn computer science.ppt
learn computer science.pptfaithola1
 
Algorithm defination, design & Implementation
Algorithm defination, design & ImplementationAlgorithm defination, design & Implementation
Algorithm defination, design & ImplementationBilal Maqbool ツ
 
Itc lec5-24+sep+2012
Itc lec5-24+sep+2012Itc lec5-24+sep+2012
Itc lec5-24+sep+2012Rehan Qadri
 
Pseudo code.pptx
Pseudo code.pptxPseudo code.pptx
Pseudo code.pptxChaya64047
 
Basic Slides on Algorithms and Flowcharts
Basic Slides on Algorithms and FlowchartsBasic Slides on Algorithms and Flowcharts
Basic Slides on Algorithms and Flowchartsmoazwinner
 
Lecture1-Algorithms-and-Flowcharts-ppt.ppt
Lecture1-Algorithms-and-Flowcharts-ppt.pptLecture1-Algorithms-and-Flowcharts-ppt.ppt
Lecture1-Algorithms-and-Flowcharts-ppt.pptReshuReshma8
 
Copy of dti2143/dam31303 chap 1 problem solving and program design
Copy of dti2143/dam31303 chap 1 problem solving and program designCopy of dti2143/dam31303 chap 1 problem solving and program design
Copy of dti2143/dam31303 chap 1 problem solving and program designalish sha
 
01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptxssuser586772
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchartSachin Goyani
 
Pseudo code
Pseudo codePseudo code
Pseudo coderija33
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)praveena p
 
Lesson 1 of c programming algorithms and flowcharts.pptx
Lesson 1 of c programming algorithms and flowcharts.pptxLesson 1 of c programming algorithms and flowcharts.pptx
Lesson 1 of c programming algorithms and flowcharts.pptxAlinaMishra7
 

Similar to 2. Algorithms Representations (C++).pptx (20)

Lecture1
Lecture1Lecture1
Lecture1
 
Flowcharts and pseudocodes
Flowcharts and pseudocodesFlowcharts and pseudocodes
Flowcharts and pseudocodes
 
learn computer science.ppt
learn computer science.pptlearn computer science.ppt
learn computer science.ppt
 
Algorithm defination, design & Implementation
Algorithm defination, design & ImplementationAlgorithm defination, design & Implementation
Algorithm defination, design & Implementation
 
Itc lec5-24+sep+2012
Itc lec5-24+sep+2012Itc lec5-24+sep+2012
Itc lec5-24+sep+2012
 
Pseudo code.pptx
Pseudo code.pptxPseudo code.pptx
Pseudo code.pptx
 
Basic Slides on Algorithms and Flowcharts
Basic Slides on Algorithms and FlowchartsBasic Slides on Algorithms and Flowcharts
Basic Slides on Algorithms and Flowcharts
 
Qbasic notes
Qbasic notesQbasic notes
Qbasic notes
 
Lecture1-Algorithms-and-Flowcharts-ppt.ppt
Lecture1-Algorithms-and-Flowcharts-ppt.pptLecture1-Algorithms-and-Flowcharts-ppt.ppt
Lecture1-Algorithms-and-Flowcharts-ppt.ppt
 
Proble, Solving & Automation
Proble, Solving & AutomationProble, Solving & Automation
Proble, Solving & Automation
 
UNIT- 3-FOC.ppt
UNIT- 3-FOC.pptUNIT- 3-FOC.ppt
UNIT- 3-FOC.ppt
 
Copy of dti2143/dam31303 chap 1 problem solving and program design
Copy of dti2143/dam31303 chap 1 problem solving and program designCopy of dti2143/dam31303 chap 1 problem solving and program design
Copy of dti2143/dam31303 chap 1 problem solving and program design
 
01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
Lesson 3
Lesson 3Lesson 3
Lesson 3
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
Pseudo code
Pseudo codePseudo code
Pseudo code
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)
 
Lesson 1 of c programming algorithms and flowcharts.pptx
Lesson 1 of c programming algorithms and flowcharts.pptxLesson 1 of c programming algorithms and flowcharts.pptx
Lesson 1 of c programming algorithms and flowcharts.pptx
 

Recently uploaded

Test Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfTest Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfkalichargn70th171
 
Incident handling is a clearly defined set of procedures to manage and respon...
Incident handling is a clearly defined set of procedures to manage and respon...Incident handling is a clearly defined set of procedures to manage and respon...
Incident handling is a clearly defined set of procedures to manage and respon...Varun Mithran
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)Roberto Bettazzoni
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletAndrea Goulet
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Henry Schreiner
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConNatan Silnitsky
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanNeo4j
 
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
Auto Affiliate  AI Earns First Commission in 3 Hours..pdfAuto Affiliate  AI Earns First Commission in 3 Hours..pdf
Auto Affiliate AI Earns First Commission in 3 Hours..pdfSelfMade bd
 
BusinessGPT - Security and Governance for Generative AI
BusinessGPT  - Security and Governance for Generative AIBusinessGPT  - Security and Governance for Generative AI
BusinessGPT - Security and Governance for Generative AIAGATSoftware
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAShane Coughlan
 
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4jGraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4jNeo4j
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationElement34
 
Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Maxim Salnikov
 
Encryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key ConceptsEncryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key Conceptsthomashtkim
 
Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14VMware Tanzu
 
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Flutter Agency
 

Recently uploaded (20)

Test Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfTest Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdf
 
Incident handling is a clearly defined set of procedures to manage and respon...
Incident handling is a clearly defined set of procedures to manage and respon...Incident handling is a clearly defined set of procedures to manage and respon...
Incident handling is a clearly defined set of procedures to manage and respon...
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea Goulet
 
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
 
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeCon
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
 
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
Auto Affiliate  AI Earns First Commission in 3 Hours..pdfAuto Affiliate  AI Earns First Commission in 3 Hours..pdf
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
 
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
 
BusinessGPT - Security and Governance for Generative AI
BusinessGPT  - Security and Governance for Generative AIBusinessGPT  - Security and Governance for Generative AI
BusinessGPT - Security and Governance for Generative AI
 
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4jGraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test Automation
 
Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?
 
Encryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key ConceptsEncryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key Concepts
 
Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14
 
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
 

2. Algorithms Representations (C++).pptx

  • 2. Introduction Performing a Task on The Computer • The first step in writing instructions to carry out a task is to determine what the output should be—that is, exactly what the task should produce. • The second step is to identify the data, or input, necessary to obtain the output. • The last step is to determine how to process the input to obtain the desired output, that is, to determine what formulas or ways of doing things can be used to obtain the output.
  • 3. Introduction Programming Tools • Tools used to convert algorithms into computer programs: • Pseudocode: An informal high-level description of the operating principle of a computer program. It uses the structural conventions of a programming language, but is intended for human reading rather than machine reading. • Flowcharts: Graphically depict the logical steps to carry out a task and show how the steps relate to each other.
  • 4. How to write Pseudocode and draw Flowcharts for a given algorithm Pseudocode •Artificial and Informal language •Helps programmers to plan an algorithm •Similar to everyday English •Not an actual programming language Flowcharts •A graphical way of writing pseudocode •Rounded rectangle – terminal •Parallelogram – input / output •Rectangle – actions •Diamonds – decision / conditional •Circles – connector
  • 5.
  • 6. Example 1 - Pseudocode -Start -Read A, B -Calculate C = A*B -Display C -Stop -Start -Use variables A,B and C -Display “write two numbers” -Read A, B -Calculate C = A*B -Display “multiplication of numbers” , C -Stop
  • 12. Example - 2 • Write an algorithm to determine a student’s average grade and indicate whether he is successful or not. • The average grade is calculated as the average of mid-term and final marks. • Student will be successful if his average grade is grater or equals to 60.
  • 13. Cont… Pseudocode - Start - Use variables mid term , final and average - Input mid term and final - Calculate the average by summing mid term and final and dividing by 2 - if average is below 60 Print “FAIL” else Print “SUCCESS” - Stop
  • 14. Cont… • Detailed Algorithm 1. Step: Input mid-term and final 2. Step: average = (mid-term + final)/2 3. Step: if (average < 60) then Print “FAIL” else Print “SUCCESS” endif
  • 16. Cont… • Nested If Simply, if structure in if structure Example - 3: Both final and average grades must be grater than or equals to 2.0 for calculation in DBU. if (final >= 35) then { if (average >= 35) then execute calculation commands endif } else Print “F grade” endif
  • 17. Example - 3 • Write an algorithm which calculates the average exam grade for a class of 5 students. • What are the program inputs?  The exam grades • Processing:  Find the sum of the grades;  Count the number of students; (counter controlled)  Calculate average grade = sum of grades / number of students. • What is the program output?  The average exam grade
  • 18. Cont… Pseudocode -Start -Use variables total, counter, grade, average -Initialize total = 0 -Initialize counter = 1 -While (counter <= 5) Input grade Calculate total = total + grade Calculate counter = counter + 1 -End-while Calculate average = total / 5 Display average -Stop
  • 20. Example 4 • Write an algorithm which calculates the average exam grade for a class of unknown number of students. • What are the program inputs?  The exam grades  Number of students • Processing:  Find the sum of the grades  Calculate average grade = sum of grades / number of students. • What is the program output?  The average exam grade
  • 21. Cont… Pseudocode -Start -Use variables total, counter, grade, average, number_of_students -Initialize total = 0 , number_of_students = 0 , counter = 1 -Display “write number of students” -Input number_of_students -While (counter <= number_of_students) Input grade Calculate total = total + grade Calculate counter = counter + 1 -End-while Calculate average = total / number_of_students Display average -Stop
  • 22. Question • Please try to draw the flow chart for the above problem (example 4).