SlideShare a Scribd company logo
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

Lecture1
Lecture1Lecture1
Lecture1
Andrew Raj
 
Flowcharts and pseudocodes
Flowcharts and pseudocodesFlowcharts and pseudocodes
Flowcharts and pseudocodes
Dr Piyush Charan
 
learn computer science.ppt
learn computer science.pptlearn computer science.ppt
learn computer science.ppt
faithola1
 
Algorithm defination, design & Implementation
Algorithm defination, design & ImplementationAlgorithm defination, design & Implementation
Algorithm defination, design & Implementation
Bilal 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.pptx
Chaya64047
 
Basic Slides on Algorithms and Flowcharts
Basic Slides on Algorithms and FlowchartsBasic Slides on Algorithms and Flowcharts
Basic Slides on Algorithms and Flowcharts
moazwinner
 
Qbasic notes
Qbasic notesQbasic notes
Qbasic notes
NasirRohail1
 
Lecture1-Algorithms-and-Flowcharts-ppt.ppt
Lecture1-Algorithms-and-Flowcharts-ppt.pptLecture1-Algorithms-and-Flowcharts-ppt.ppt
Lecture1-Algorithms-and-Flowcharts-ppt.ppt
ReshuReshma8
 
Proble, Solving & Automation
Proble, Solving & AutomationProble, Solving & Automation
Proble, Solving & Automation
Janani Satheshkumar
 
UNIT- 3-FOC.ppt
UNIT- 3-FOC.pptUNIT- 3-FOC.ppt
UNIT- 3-FOC.ppt
KalaivaniRMECLectCSE
 
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
alish 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.pptx
ssuser586772
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
Trivuz ত্রিভুজ
 
Lesson 3
Lesson 3Lesson 3
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
Sachin Goyani
 
Pseudo code
Pseudo codePseudo code
Pseudo code
rija33
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
ShaswatSurya
 
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.pptx
AlinaMishra7
 

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

top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 

Recently uploaded (20)

top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 

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).