SlideShare a Scribd company logo
CHAPTER 3
ALGORITHMS
PROG0101
FUNDAMENTALS OF
PROGRAMMING
C H A P T E R 1
O V E R V I E W O F C O M P U T E R S A N D L O G I C
PROG0101
FUNDAMENTALS OF
PROGRAMMING
PROG0101
FUNDAMENTALS OF PROGRAMMING
CHAPTER 3
ALGORITHM
2
Introduction to Algorithms
 A sequence of instructions.
 A procedure or formula for solving a problem.
 It was created mathematician, Mohammed ibn-Musa
al-Khwarizmi.
 Often used for calculation, data processing and
programming.
 Algorithms can be expressed in any language.
3
Introduction to Algorithms
 Algorithms for making things will often be divided
into sections;
 the parts/components/ingredients (inputs) required to
accomplish the task
 actions/steps/methods (processing) to produce the
required outcome (output).
 For example to build a model car, the parts (inputs)
are needed plus instructions on how to assemble the
car (processing) and the result is the car (output).
4
Types of Algorithms
 Two types of Algorithm:
 Pseudocode
 Flow chart
5
Pseudocode
 Pseudocode (which means fake code, because its not
really programming code) specifies the steps
required to accomplish the task.
 Pseudocode is a type of structured English that is
used to specify an algorithm.
 Pseudocode cannot be compiled nor executed, and
there are no real formatting or syntax rules.
6
Pseudocode
Example of Pseudocode:
Ready and open subscriber file
Get a record
Do while more records
If current subscriber subscription count is > 3 then
Output the record
Get another record
end
7
Pseudocode
Advantages of Pseudocode
 Reduced complexity.
 Increased flexibility.
 Ease of understanding.
8
Pseudocode
Why is Pseudocode Necessary?
 The programming process is a complicated one.
 You must first understand the program specifications.
 Then you need to organize your thoughts and create the
program.
 You must break the main tasks that must be
accomplished into smaller ones in order to be able to
eventually write fully developed code.
 Writing Pseudocode will save you time later during the
construction & testing phase of a program's
development.
9
Pseudocode
How to Write Pseudocode Statements?
1. A computer can receive information
Read (information from a file)
Get (information from the keyboard)
2. A computer can put out information
Write (information to a file)
Display (information to the screen)
10
Pseudocode
How to Write Pseudocode Statements?
3. A computer can perform arithmetic
Use actual mathematical symbols or the words for the symbols
Example:
Add number to total
Total = total + number
+, -, *, /
Calculate, Compute also used
11
Pseudocode
How to Write Pseudocode Statements?
4. A computer can assign a value to a piece of data
i. to give data an initial value
Initialize, Set
ii. to assign a value as a result of some processing
*x=5+y
iii. to keep a piece of information for later use
Save, Store
12
Pseudocode
How to Write Pseudocode Statements?
5. A computer can compare two piece of information
and select one of two alternative actions
IF condition THEN
some action
ELSE
alternative action
ENDIF
13
Pseudocode
How to Write Pseudocode Statements?
6. A computer can repeat a group of actions
WHILE condition (is true)
some action
ENDWHILE
FOR a number of times
some action
ENDFOR
14
Pseudocode
Example 1:
Program Specification:
Pseudocode:
Write a program that obtains two integer numbers from the
user. It will print out the sum of those numbers.
Prompt the user to enter the first integer
Prompt the user to enter a second integer
Compute the sum of the two user inputs
Display an output prompt that explains the answer as the sum
Display the result
15
Pseudocode
Example 2:
Finding average of any three numbers.
We might usually specify the procedure of solving this
problem as “add the three numbers and divide by
three”. Here, Read (or Ask) and Write (or Say) are
implied. However in an algorithm, these steps have to
be made explicit. Thus a possible algorithm is:
16
Pseudocode
Example 2:
Step 1 Start
Step 2 Read values of X, Y, Z
Step 3 S = X + Y + Z
Step 4 A = S / 3
Step 5 Write value of A
Step 6 Stop
17
Pseudocode
Example 2:
Or you can write like this:
Step 1 Start
Step 2 Read values of X, Y, Z
Step 3 S = X + Y + Z
Step 4 A = S / 3
Step 5 Write value of A
Step 6 Stop
18
Pseudocode
Example 3:
Finding square and cube.
Step 1 Start
Step 2 Read value of N
Step 3 S = N * N
Step 4 C = S * N
Step 5 Write values of S, C
Step 6 Stop
19
Pseudocode
Example 4:
Finding biggest of two numbers.
Step 1 Start
Step 2 Read A, B
Step 3 If A > B, then BIG = A, otherwise
BIG = B
Step 4 Write BIG
Step 5 Stop
20
Pseudocode
Example 5:
Calculate pay.
Step 1 Start
Step 2 Input hours
Step 3 Input rate
Step 4 pay = hours * rate
Step 5 Print pay
Step 6 End
21
Pseudocode
Exercise:
Write a Pseudocode for these problems.
1. S = (A + B + C) / Y
2. Convert from Celsius to Fahrenheit.
3. Area of Circle (r2)
4. Volume of Sphere ( r3)
5. Average speed =
4
3
Distance traveled
Time taken
(Multiply by 9, then divide by 5, then add 32 )
22
Flowchart
 A flowchart is a graphical representation of an
algorithm.
 These flowcharts play a vital role in the
programming of a problem and are quite helpful in
understanding the logic of complicated and lengthy
problems.
 Once the flowchart is drawn, it becomes easy to
write the program in any high level language.
23
Flowchart
Flowchart
 A flowchart can therefore be used to:
 Define and analyze processes
 Build a step-by-step picture of the process for analysis,
discussion, or communication
 Define, standardize or find areas for improvement in a
process
24
Flowchart
Flowchart
25
Flowchart
Flowchart Symbols
Start and End symbols
 Represented as lozenges, ovals or rounded rectangles
 Usually containing the word "Start" or "End", or another
phrase signalling the start or end of a process, such as
"submit enquiry" or "receive product".
26
Flowchart
Flowchart Symbols
Arrows
 Showing what's called "flow of control" in computer
science.
 An arrow coming from one symbol and ending at
another symbol.
 Represents that control passes to the symbol the arrow
points to.
27
Flowchart
Flowchart Symbols
Processing steps
 Represented as rectangles.
 Examples: “Add 1 to X"; "replace identified part";
"save changes" or similar.
28
Flowchart
Flowchart Symbols
Input/Output
 Represented as a parallelogram.
 Examples: Get X from the user; display X.
29
Flowchart
Flowchart Symbols
Conditional or decision
 Represented as a diamond (rhombus).
 These typically contain a Yes/No question or
True/False test.
30
Algorithms
Flowchart Symbols
Display
 Indicates a process flow step where information is
displayed to a person (e.g., PC user, machine
operator).
31
Flowchart
Rules for Flowchart
1. Every flow chart has a START symbol and a STOP
symbol.
2. The flow of sequence is generally from the top of
the page to the bottom of the page. This can vary
with loops which need to flow back to an entry
point.
3. Use arrow-heads on connectors where flow
direction may not be obvious.
4. There is only one flow chart per page.
32
Flowchart
Rules for Flowchart
5. A page should have a page number and a title.
6. A flow chart on one page should not break and
jump to another page
7. A flow chart should have no more than around 15
symbols (not including START and STOP).
33
Flowchart
Advantages of Using Flowcharts
 Communication: Flowcharts are better way of communicating
the logic of a system to all concerned.
 Effective analysis: With the help of flowchart, problem can be
analysed in more effective way.
 Proper documentation: Program flowcharts serve as a good
program documentation, which is needed for various purposes.
 Efficient Coding: The flowcharts act as a guide or blueprint
during the systems analysis and program development phase.
34
Flowchart
Advantages of Using Flowcharts
 Proper Debugging: The flowchart helps in debugging
process.
 Efficient Program Maintenance: The maintenance of
operating program becomes easy with the help of flowchart. It
helps the programmer to put efforts more efficiently on that
part.
35
Flowchart
Basic Control Structures
 Sequence
 Selection
 Loop
36
Flowchart
Basic Control Structures
Sequence
 Steps that execute in sequence are represented by symbols that follow
each other top to bottom or left to right.
 Top to bottom is the standard.
37
Flowchart
Basic Control Structures
Sequence
38
Flowchart
Basic Control Structures
Selection/Branching
 Once the condition is evaluated, the control flows into one of two
paths.
 Once the conditional execution is finished, the flows rejoin before
leaving the structure.
39
Flowchart
Basic Control Structures
Selection/Branching
40
Flowchart
Basic Control Structures
Loop
 Either the processing repeats or the control leaves
the structure.
 Notice that the return line joins the entry line
before the question.
41
Flowchart
Basic Control Structures
Loop
42
Flowchart
Example 1:
Algorithm:
Input: two numbers x and y
Output: the average of x and y
Steps:
1. input x
2. input y
3. sum = x + y
4. average = sum /2
5. output average
43
Flowchart
Example 1:
44
Flowchart
Example 2:
Draw a flowchart to find the largest of three numbers
A, B, and C.
45
Flowchart
Example 2:
46
Flowchart
Exercise:
Draw a flowchart diagram.
1. A program that compare the first number and
second number and display which one is the biggest.
2. Login screen to check the Username and
Password.
Ad

More Related Content

What's hot (20)

Microsoft word - teaching slides
Microsoft word  - teaching slidesMicrosoft word  - teaching slides
Microsoft word - teaching slides
Miss-Short
 
Libre Office Writer Lesson 1
Libre Office Writer Lesson 1Libre Office Writer Lesson 1
Libre Office Writer Lesson 1
Smart Chicago Collaborative
 
Date and Time Module in Python | Edureka
Date and Time Module in Python | EdurekaDate and Time Module in Python | Edureka
Date and Time Module in Python | Edureka
Edureka!
 
Microsoft Powerpoint Basics
Microsoft Powerpoint BasicsMicrosoft Powerpoint Basics
Microsoft Powerpoint Basics
Pickerington Public Library
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
Neeru Mittal
 
Programming Fundamentals lecture 2
Programming Fundamentals lecture 2Programming Fundamentals lecture 2
Programming Fundamentals lecture 2
REHAN IJAZ
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming Concepts
Jussi Pohjolainen
 
Programming fundamentals lecture 4
Programming fundamentals lecture 4Programming fundamentals lecture 4
Programming fundamentals lecture 4
Raja Hamid
 
Introduction to problem solving in c++
Introduction to problem solving in c++Introduction to problem solving in c++
Introduction to problem solving in c++
Online
 
Visual Programming
Visual ProgrammingVisual Programming
Visual Programming
Bagzzz
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
Sachin Goyani
 
Programming
ProgrammingProgramming
Programming
Leo Simon Anfone
 
Pseudocode
PseudocodePseudocode
Pseudocode
Harsha Madushanka
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis
Dr. Pankaj Agarwal
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languages
Varun Garg
 
Chapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to ProgrammingChapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to Programming
mshellman
 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
Mohammed Sikander
 
Compiler Design Lecture Notes
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture Notes
FellowBuddy.com
 
Word processing
Word processingWord processing
Word processing
jones brandes
 
Microsoft word - teaching slides
Microsoft word  - teaching slidesMicrosoft word  - teaching slides
Microsoft word - teaching slides
Miss-Short
 
Date and Time Module in Python | Edureka
Date and Time Module in Python | EdurekaDate and Time Module in Python | Edureka
Date and Time Module in Python | Edureka
Edureka!
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
Neeru Mittal
 
Programming Fundamentals lecture 2
Programming Fundamentals lecture 2Programming Fundamentals lecture 2
Programming Fundamentals lecture 2
REHAN IJAZ
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming Concepts
Jussi Pohjolainen
 
Programming fundamentals lecture 4
Programming fundamentals lecture 4Programming fundamentals lecture 4
Programming fundamentals lecture 4
Raja Hamid
 
Introduction to problem solving in c++
Introduction to problem solving in c++Introduction to problem solving in c++
Introduction to problem solving in c++
Online
 
Visual Programming
Visual ProgrammingVisual Programming
Visual Programming
Bagzzz
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
Sachin Goyani
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis
Dr. Pankaj Agarwal
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languages
Varun Garg
 
Chapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to ProgrammingChapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to Programming
mshellman
 
Compiler Design Lecture Notes
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture Notes
FellowBuddy.com
 

Similar to Fundamentals of Programming Chapter 3 (20)

Lecture1-Algorithms-and-Flowcharts-ppt.ppt
Lecture1-Algorithms-and-Flowcharts-ppt.pptLecture1-Algorithms-and-Flowcharts-ppt.ppt
Lecture1-Algorithms-and-Flowcharts-ppt.ppt
ReshuReshma8
 
Lect1-Algorithms-and-Flowchart PPT presentation
Lect1-Algorithms-and-Flowchart PPT presentationLect1-Algorithms-and-Flowchart PPT presentation
Lect1-Algorithms-and-Flowchart PPT presentation
gstagra
 
Lecture1-Algorithms-and-Flowchart-ppt.ppt
Lecture1-Algorithms-and-Flowchart-ppt.pptLecture1-Algorithms-and-Flowchart-ppt.ppt
Lecture1-Algorithms-and-Flowchart-ppt.ppt
samreen82
 
Basic Slides on Algorithms and Flowcharts
Basic Slides on Algorithms and FlowchartsBasic Slides on Algorithms and Flowcharts
Basic Slides on Algorithms and Flowcharts
moazwinner
 
Algorithms and Flowchart usages in C laguage
Algorithms and Flowchart usages in C laguageAlgorithms and Flowchart usages in C laguage
Algorithms and Flowchart usages in C laguage
BalaKrishnan466
 
Lect1-Detailed description aboutAlgorithms-and-Flowchart.ppt
Lect1-Detailed description aboutAlgorithms-and-Flowchart.pptLect1-Detailed description aboutAlgorithms-and-Flowchart.ppt
Lect1-Detailed description aboutAlgorithms-and-Flowchart.ppt
gstagra
 
AlgorithmAndFlowChart.pdf
AlgorithmAndFlowChart.pdfAlgorithmAndFlowChart.pdf
AlgorithmAndFlowChart.pdf
SusieMaestre1
 
lecture 5
 lecture 5 lecture 5
lecture 5
umardanjumamaiwada
 
Introduction to computer science
Introduction to computer scienceIntroduction to computer science
Introduction to computer science
umardanjumamaiwada
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
Rohit Shrivastava
 
Lect 3-4 Zaheer Abbas
Lect 3-4 Zaheer AbbasLect 3-4 Zaheer Abbas
Lect 3-4 Zaheer Abbas
Information Technology Center
 
Software develop....
Software develop.... Software develop....
Software develop....
GCWUS
 
Python Unit 1.pdfPython Notes for Bharathiar university syllabus
Python Unit 1.pdfPython Notes for Bharathiar university syllabusPython Unit 1.pdfPython Notes for Bharathiar university syllabus
Python Unit 1.pdfPython Notes for Bharathiar university syllabus
ANUSUYA S
 
ICP - Lecture 6
ICP - Lecture 6ICP - Lecture 6
ICP - Lecture 6
Hassaan Rahman
 
Practical 01 (detailed)
Practical 01 (detailed)Practical 01 (detailed)
Practical 01 (detailed)
Muhammadalizardari
 
Psuedocode1, algorithm1, Flowchart1.pptx
Psuedocode1, algorithm1, Flowchart1.pptxPsuedocode1, algorithm1, Flowchart1.pptx
Psuedocode1, algorithm1, Flowchart1.pptx
MattFlordeliza1
 
Flowcharting and Algorithm
Flowcharting and Algorithm Flowcharting and Algorithm
Flowcharting and Algorithm
Zeinna Belle Desamito
 
GE3151 PSPP _Unit 1 notes and Question bank.pdf
GE3151 PSPP _Unit 1 notes and Question bank.pdfGE3151 PSPP _Unit 1 notes and Question bank.pdf
GE3151 PSPP _Unit 1 notes and Question bank.pdf
Guru Nanak Technical Institutions
 
Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowcharts
Samuel Igbanogu
 
Algorithm for computational problematic sit
Algorithm for computational problematic sitAlgorithm for computational problematic sit
Algorithm for computational problematic sit
Saurabh846965
 
Lecture1-Algorithms-and-Flowcharts-ppt.ppt
Lecture1-Algorithms-and-Flowcharts-ppt.pptLecture1-Algorithms-and-Flowcharts-ppt.ppt
Lecture1-Algorithms-and-Flowcharts-ppt.ppt
ReshuReshma8
 
Lect1-Algorithms-and-Flowchart PPT presentation
Lect1-Algorithms-and-Flowchart PPT presentationLect1-Algorithms-and-Flowchart PPT presentation
Lect1-Algorithms-and-Flowchart PPT presentation
gstagra
 
Lecture1-Algorithms-and-Flowchart-ppt.ppt
Lecture1-Algorithms-and-Flowchart-ppt.pptLecture1-Algorithms-and-Flowchart-ppt.ppt
Lecture1-Algorithms-and-Flowchart-ppt.ppt
samreen82
 
Basic Slides on Algorithms and Flowcharts
Basic Slides on Algorithms and FlowchartsBasic Slides on Algorithms and Flowcharts
Basic Slides on Algorithms and Flowcharts
moazwinner
 
Algorithms and Flowchart usages in C laguage
Algorithms and Flowchart usages in C laguageAlgorithms and Flowchart usages in C laguage
Algorithms and Flowchart usages in C laguage
BalaKrishnan466
 
Lect1-Detailed description aboutAlgorithms-and-Flowchart.ppt
Lect1-Detailed description aboutAlgorithms-and-Flowchart.pptLect1-Detailed description aboutAlgorithms-and-Flowchart.ppt
Lect1-Detailed description aboutAlgorithms-and-Flowchart.ppt
gstagra
 
AlgorithmAndFlowChart.pdf
AlgorithmAndFlowChart.pdfAlgorithmAndFlowChart.pdf
AlgorithmAndFlowChart.pdf
SusieMaestre1
 
Introduction to computer science
Introduction to computer scienceIntroduction to computer science
Introduction to computer science
umardanjumamaiwada
 
Software develop....
Software develop.... Software develop....
Software develop....
GCWUS
 
Python Unit 1.pdfPython Notes for Bharathiar university syllabus
Python Unit 1.pdfPython Notes for Bharathiar university syllabusPython Unit 1.pdfPython Notes for Bharathiar university syllabus
Python Unit 1.pdfPython Notes for Bharathiar university syllabus
ANUSUYA S
 
Psuedocode1, algorithm1, Flowchart1.pptx
Psuedocode1, algorithm1, Flowchart1.pptxPsuedocode1, algorithm1, Flowchart1.pptx
Psuedocode1, algorithm1, Flowchart1.pptx
MattFlordeliza1
 
Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowcharts
Samuel Igbanogu
 
Algorithm for computational problematic sit
Algorithm for computational problematic sitAlgorithm for computational problematic sit
Algorithm for computational problematic sit
Saurabh846965
 
Ad

More from Mohd Harris Ahmad Jaal (20)

Fundamentals of Programming Chapter 7
Fundamentals of Programming Chapter 7Fundamentals of Programming Chapter 7
Fundamentals of Programming Chapter 7
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 6
Fundamentals of Programming Chapter 6Fundamentals of Programming Chapter 6
Fundamentals of Programming Chapter 6
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 4
Fundamentals of Programming Chapter 4Fundamentals of Programming Chapter 4
Fundamentals of Programming Chapter 4
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 2
Fundamentals of Programming Chapter 2Fundamentals of Programming Chapter 2
Fundamentals of Programming Chapter 2
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 1
Fundamentals of Programming Chapter 1Fundamentals of Programming Chapter 1
Fundamentals of Programming Chapter 1
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 8
Web Application Development using PHP Chapter 8Web Application Development using PHP Chapter 8
Web Application Development using PHP Chapter 8
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 7
Web Application Development using PHP Chapter 7Web Application Development using PHP Chapter 7
Web Application Development using PHP Chapter 7
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 6
Web Application Development using PHP Chapter 6Web Application Development using PHP Chapter 6
Web Application Development using PHP Chapter 6
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 4
Web Application Development using PHP Chapter 4Web Application Development using PHP Chapter 4
Web Application Development using PHP Chapter 4
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 1
Web Application Development using PHP Chapter 1Web Application Development using PHP Chapter 1
Web Application Development using PHP Chapter 1
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 10
Fundamentals of Computing Chapter 10Fundamentals of Computing Chapter 10
Fundamentals of Computing Chapter 10
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 9
Fundamentals of Computing Chapter 9Fundamentals of Computing Chapter 9
Fundamentals of Computing Chapter 9
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 8
Fundamentals of Computing Chapter 8Fundamentals of Computing Chapter 8
Fundamentals of Computing Chapter 8
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 7
Fundamentals of Computing Chapter 7Fundamentals of Computing Chapter 7
Fundamentals of Computing Chapter 7
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 6
Fundamentals of Computing Chapter 6Fundamentals of Computing Chapter 6
Fundamentals of Computing Chapter 6
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 5
Fundamentals of Computing Chapter 5Fundamentals of Computing Chapter 5
Fundamentals of Computing Chapter 5
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 8
Web Application Development using PHP Chapter 8Web Application Development using PHP Chapter 8
Web Application Development using PHP Chapter 8
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 7
Web Application Development using PHP Chapter 7Web Application Development using PHP Chapter 7
Web Application Development using PHP Chapter 7
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 6
Web Application Development using PHP Chapter 6Web Application Development using PHP Chapter 6
Web Application Development using PHP Chapter 6
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 4
Web Application Development using PHP Chapter 4Web Application Development using PHP Chapter 4
Web Application Development using PHP Chapter 4
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 1
Web Application Development using PHP Chapter 1Web Application Development using PHP Chapter 1
Web Application Development using PHP Chapter 1
Mohd Harris Ahmad Jaal
 
Ad

Recently uploaded (20)

03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdfRanking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Rafael Villas B
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Link your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRMLink your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRM
Celine George
 
Grade 3 - English - Printable Worksheet (PDF Format)
Grade 3 - English - Printable Worksheet  (PDF Format)Grade 3 - English - Printable Worksheet  (PDF Format)
Grade 3 - English - Printable Worksheet (PDF Format)
Sritoma Majumder
 
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
TechSoup
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptxLecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Arshad Shaikh
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Lecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptxLecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptx
Arshad Shaikh
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18
Celine George
 
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
Dr. Nasir Mustafa
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
Tax evasion, Tax planning & Tax avoidance.pptx
Tax evasion, Tax  planning &  Tax avoidance.pptxTax evasion, Tax  planning &  Tax avoidance.pptx
Tax evasion, Tax planning & Tax avoidance.pptx
manishbaidya2017
 
Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)
GS Virdi
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdfRanking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Rafael Villas B
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Link your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRMLink your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRM
Celine George
 
Grade 3 - English - Printable Worksheet (PDF Format)
Grade 3 - English - Printable Worksheet  (PDF Format)Grade 3 - English - Printable Worksheet  (PDF Format)
Grade 3 - English - Printable Worksheet (PDF Format)
Sritoma Majumder
 
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
TechSoup
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptxLecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Arshad Shaikh
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Lecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptxLecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptx
Arshad Shaikh
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18
Celine George
 
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
Dr. Nasir Mustafa
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
Tax evasion, Tax planning & Tax avoidance.pptx
Tax evasion, Tax  planning &  Tax avoidance.pptxTax evasion, Tax  planning &  Tax avoidance.pptx
Tax evasion, Tax planning & Tax avoidance.pptx
manishbaidya2017
 
Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)
GS Virdi
 

Fundamentals of Programming Chapter 3

  • 1. CHAPTER 3 ALGORITHMS PROG0101 FUNDAMENTALS OF PROGRAMMING C H A P T E R 1 O V E R V I E W O F C O M P U T E R S A N D L O G I C PROG0101 FUNDAMENTALS OF PROGRAMMING PROG0101 FUNDAMENTALS OF PROGRAMMING CHAPTER 3 ALGORITHM
  • 2. 2 Introduction to Algorithms  A sequence of instructions.  A procedure or formula for solving a problem.  It was created mathematician, Mohammed ibn-Musa al-Khwarizmi.  Often used for calculation, data processing and programming.  Algorithms can be expressed in any language.
  • 3. 3 Introduction to Algorithms  Algorithms for making things will often be divided into sections;  the parts/components/ingredients (inputs) required to accomplish the task  actions/steps/methods (processing) to produce the required outcome (output).  For example to build a model car, the parts (inputs) are needed plus instructions on how to assemble the car (processing) and the result is the car (output).
  • 4. 4 Types of Algorithms  Two types of Algorithm:  Pseudocode  Flow chart
  • 5. 5 Pseudocode  Pseudocode (which means fake code, because its not really programming code) specifies the steps required to accomplish the task.  Pseudocode is a type of structured English that is used to specify an algorithm.  Pseudocode cannot be compiled nor executed, and there are no real formatting or syntax rules.
  • 6. 6 Pseudocode Example of Pseudocode: Ready and open subscriber file Get a record Do while more records If current subscriber subscription count is > 3 then Output the record Get another record end
  • 7. 7 Pseudocode Advantages of Pseudocode  Reduced complexity.  Increased flexibility.  Ease of understanding.
  • 8. 8 Pseudocode Why is Pseudocode Necessary?  The programming process is a complicated one.  You must first understand the program specifications.  Then you need to organize your thoughts and create the program.  You must break the main tasks that must be accomplished into smaller ones in order to be able to eventually write fully developed code.  Writing Pseudocode will save you time later during the construction & testing phase of a program's development.
  • 9. 9 Pseudocode How to Write Pseudocode Statements? 1. A computer can receive information Read (information from a file) Get (information from the keyboard) 2. A computer can put out information Write (information to a file) Display (information to the screen)
  • 10. 10 Pseudocode How to Write Pseudocode Statements? 3. A computer can perform arithmetic Use actual mathematical symbols or the words for the symbols Example: Add number to total Total = total + number +, -, *, / Calculate, Compute also used
  • 11. 11 Pseudocode How to Write Pseudocode Statements? 4. A computer can assign a value to a piece of data i. to give data an initial value Initialize, Set ii. to assign a value as a result of some processing *x=5+y iii. to keep a piece of information for later use Save, Store
  • 12. 12 Pseudocode How to Write Pseudocode Statements? 5. A computer can compare two piece of information and select one of two alternative actions IF condition THEN some action ELSE alternative action ENDIF
  • 13. 13 Pseudocode How to Write Pseudocode Statements? 6. A computer can repeat a group of actions WHILE condition (is true) some action ENDWHILE FOR a number of times some action ENDFOR
  • 14. 14 Pseudocode Example 1: Program Specification: Pseudocode: Write a program that obtains two integer numbers from the user. It will print out the sum of those numbers. Prompt the user to enter the first integer Prompt the user to enter a second integer Compute the sum of the two user inputs Display an output prompt that explains the answer as the sum Display the result
  • 15. 15 Pseudocode Example 2: Finding average of any three numbers. We might usually specify the procedure of solving this problem as “add the three numbers and divide by three”. Here, Read (or Ask) and Write (or Say) are implied. However in an algorithm, these steps have to be made explicit. Thus a possible algorithm is:
  • 16. 16 Pseudocode Example 2: Step 1 Start Step 2 Read values of X, Y, Z Step 3 S = X + Y + Z Step 4 A = S / 3 Step 5 Write value of A Step 6 Stop
  • 17. 17 Pseudocode Example 2: Or you can write like this: Step 1 Start Step 2 Read values of X, Y, Z Step 3 S = X + Y + Z Step 4 A = S / 3 Step 5 Write value of A Step 6 Stop
  • 18. 18 Pseudocode Example 3: Finding square and cube. Step 1 Start Step 2 Read value of N Step 3 S = N * N Step 4 C = S * N Step 5 Write values of S, C Step 6 Stop
  • 19. 19 Pseudocode Example 4: Finding biggest of two numbers. Step 1 Start Step 2 Read A, B Step 3 If A > B, then BIG = A, otherwise BIG = B Step 4 Write BIG Step 5 Stop
  • 20. 20 Pseudocode Example 5: Calculate pay. Step 1 Start Step 2 Input hours Step 3 Input rate Step 4 pay = hours * rate Step 5 Print pay Step 6 End
  • 21. 21 Pseudocode Exercise: Write a Pseudocode for these problems. 1. S = (A + B + C) / Y 2. Convert from Celsius to Fahrenheit. 3. Area of Circle (r2) 4. Volume of Sphere ( r3) 5. Average speed = 4 3 Distance traveled Time taken (Multiply by 9, then divide by 5, then add 32 )
  • 22. 22 Flowchart  A flowchart is a graphical representation of an algorithm.  These flowcharts play a vital role in the programming of a problem and are quite helpful in understanding the logic of complicated and lengthy problems.  Once the flowchart is drawn, it becomes easy to write the program in any high level language.
  • 23. 23 Flowchart Flowchart  A flowchart can therefore be used to:  Define and analyze processes  Build a step-by-step picture of the process for analysis, discussion, or communication  Define, standardize or find areas for improvement in a process
  • 25. 25 Flowchart Flowchart Symbols Start and End symbols  Represented as lozenges, ovals or rounded rectangles  Usually containing the word "Start" or "End", or another phrase signalling the start or end of a process, such as "submit enquiry" or "receive product".
  • 26. 26 Flowchart Flowchart Symbols Arrows  Showing what's called "flow of control" in computer science.  An arrow coming from one symbol and ending at another symbol.  Represents that control passes to the symbol the arrow points to.
  • 27. 27 Flowchart Flowchart Symbols Processing steps  Represented as rectangles.  Examples: “Add 1 to X"; "replace identified part"; "save changes" or similar.
  • 28. 28 Flowchart Flowchart Symbols Input/Output  Represented as a parallelogram.  Examples: Get X from the user; display X.
  • 29. 29 Flowchart Flowchart Symbols Conditional or decision  Represented as a diamond (rhombus).  These typically contain a Yes/No question or True/False test.
  • 30. 30 Algorithms Flowchart Symbols Display  Indicates a process flow step where information is displayed to a person (e.g., PC user, machine operator).
  • 31. 31 Flowchart Rules for Flowchart 1. Every flow chart has a START symbol and a STOP symbol. 2. The flow of sequence is generally from the top of the page to the bottom of the page. This can vary with loops which need to flow back to an entry point. 3. Use arrow-heads on connectors where flow direction may not be obvious. 4. There is only one flow chart per page.
  • 32. 32 Flowchart Rules for Flowchart 5. A page should have a page number and a title. 6. A flow chart on one page should not break and jump to another page 7. A flow chart should have no more than around 15 symbols (not including START and STOP).
  • 33. 33 Flowchart Advantages of Using Flowcharts  Communication: Flowcharts are better way of communicating the logic of a system to all concerned.  Effective analysis: With the help of flowchart, problem can be analysed in more effective way.  Proper documentation: Program flowcharts serve as a good program documentation, which is needed for various purposes.  Efficient Coding: The flowcharts act as a guide or blueprint during the systems analysis and program development phase.
  • 34. 34 Flowchart Advantages of Using Flowcharts  Proper Debugging: The flowchart helps in debugging process.  Efficient Program Maintenance: The maintenance of operating program becomes easy with the help of flowchart. It helps the programmer to put efforts more efficiently on that part.
  • 35. 35 Flowchart Basic Control Structures  Sequence  Selection  Loop
  • 36. 36 Flowchart Basic Control Structures Sequence  Steps that execute in sequence are represented by symbols that follow each other top to bottom or left to right.  Top to bottom is the standard.
  • 38. 38 Flowchart Basic Control Structures Selection/Branching  Once the condition is evaluated, the control flows into one of two paths.  Once the conditional execution is finished, the flows rejoin before leaving the structure.
  • 40. 40 Flowchart Basic Control Structures Loop  Either the processing repeats or the control leaves the structure.  Notice that the return line joins the entry line before the question.
  • 42. 42 Flowchart Example 1: Algorithm: Input: two numbers x and y Output: the average of x and y Steps: 1. input x 2. input y 3. sum = x + y 4. average = sum /2 5. output average
  • 44. 44 Flowchart Example 2: Draw a flowchart to find the largest of three numbers A, B, and C.
  • 46. 46 Flowchart Exercise: Draw a flowchart diagram. 1. A program that compare the first number and second number and display which one is the biggest. 2. Login screen to check the Username and Password.