SlideShare a Scribd company logo
Introduction to Algorithms
Solving Problems (1)
When faced with a problem:
1. We first clearly define the problem
2. Think of possible solutions
3. Select the one that we think is the best
under the prevailing circumstances
4. And then apply that solution
5. If the solution works as desired, fine;
else we go back to step 2
Solving Problems (2)
 It is quite common to first solve a problem for a particular case
 Then for another
 And, possibly another
 And watch for patterns and trends that emerge
 And to use the knowledge form those patterns and trends in coming up with
a general solution
Solving Problems (3)
 It helps if we have experienced that problem or similar ones before
 Generally, there are many ways of solving a given problem; the best problem-
solvers come-up with the most appropriate solution more often than not!
 The process that can be used to solve a problem is termed as the “algorithm”
Examples
 Addition
 Conversion from decimal to binary
 The process of boiling an egg
 The process of mailing a letter
 Sorting
 Searching
Let us write down the algorithm for a problem
that is familiar to us
Converting a decimal number into binary
Convert 75 to Binary
752
37 12
18 12
9 02
4 12
2 02
1 02
0 1
1001011
remainder
Algorithm for Decimal-to-Binary Conversion
1. Write the decimal number
2. Divide by 2; write quotient and remainder
3. Repeat step 2 on the quotient; keep on repeating until the quotient becomes
zero
4. Write all remainder digits in the reverse order (last remainder first) to form the
final result
Points to Note:
1. The process consists of repeated application of simple steps
2. All steps are unambiguous (clearly defined)
3. We are capable of doing all those steps
4. Only a limited no. of steps needs to be taken
5. Once all those steps are taken according to the prescribed sequence, the
required result will be found
6. Moreover, the process will stop at that point
Algorithm (Better Definition)
1st Definition:
Sequence of steps that can be taken to solve a problem
Better Definition:
A precise sequence of a limited number of unambiguous, executable
steps that terminates in the form of a solution
Three Requirements:
1. Sequence is:
a. Precise
b. Consists of a limited number of steps
2. Each step is:
a. Unambiguous
b. Executable
3. The sequence of steps terminates in the form of a solution
Why Algorithms are Useful?
 Once we find an algorithm for solving a problem, we do not need to re-
discover it the next time we are faced with that problem
 Once an algorithm is known, the task of solving the problem reduces to
following (almost blindly and without thinking) the instructions precisely
 All the knowledge required for solving the problem is present in the algorithm
Analysis of Algorithms
 Analysis in the context of algorithms is concerned with predicting the resources
that are requires:
 Computational time
 Memory
 Bandwidth
 Logic functions
 However, Time – generally measured in terms of the number of steps required to
execute an algorithm - is the resource of most interest
 By analyzing several candidate algorithms, the most efficient one(s) can be
identified
Selecting Among Algorithms
When choosing among competing, successful solutions to a problem, choose the
one which is the least complex
This principle is called the “Ockham’s Razor,” after William of Ockham - famous
13-th century English philosopher
Syntax & Semantics
An algorithm is “correct” if its:
 Semantics are correct
 Syntax is correct
Semantics:
The concept embedded in an
algorithm (the soul!)
Syntax:
The actual representation of an
algorithm (the body!)
WARNINGS:
1. An algorithm can be
syntactically correct, yet
semantically incorrect –
very dangerous situation!
2. Syntactic correctness is
easier to check as
compared with semantic
Now onto Algorithm Representation
 We have said enough about algorithms – their definition, their types, etc.
 But, how do we actually represent them?
 Generally, SW developers represent them in one of three forms:
 Pseudo code
 Flowcharts
 Actual code
Pseudo Code
 Language that is typically used for writing algorithms
 Similar to a programming language, but not as rigid
 The method of expression most suitable for a given situation is used:
 At times, plain English
 At others, a programming language like syntax
Flowchart
 A graphical representation of a process (e.g. an algorithm), in which graphic
objects are used to indicate the steps & decisions that are taken as the process
moves along from start to finish
 Individual steps are represented by boxes and other shapes on the flowchart, with
arrows between those shapes indicating the order in which the steps are taken
Start or stop
Process
Input or output
Connector
Decision
Flow line
Off-page connector
Flowchart
Elements
Algorithm Building Blocks
All problems can be solved by employing any one of the following
building blocks or their combinations
1. Sequences
2. Conditionals
3. Loops
Sequences
A sequence of instructions that are executed in the precise order they
are written in:
statement block 1
statement block 2
statement block 3
statement block 1
statement block 2
statement block 3
Conditionals
Select between alternate courses of action depending upon the evaluation of a
condition
If ( condition = true )
statement block 1
Else
statement block 2
End if statement
block 1
condition
True False
statement
block 2
Loops
Loop through a set of statements as long as a condition is true
Loop while ( condition = true )
statement block
End Loop
condition
True
False
statement
block
Problem Statement
Convert a decimal number into binary
Convert 75 to Binary
752
37 12
18 12
9 02
4 12
2 02
1 02
0 1
1001011
remainder
Solution in Pseudo Code
1. Let the decimal number be an integer x, x > 0
2. Let the binary equivalent be an empty string y
3. Repeat while x > 0 {
Determine the quotient & remainder of x ÷ 2
y = CONCATENATE( remainder, y )
x = quotient
}
4. Print y
5. Stop
Start
Find quotient
& remainder
of x ÷ 2
Get x
x>0 ?
Print y
Stop
y = CONC(remainder, x)
x = quotient
x is the decimal number
y is the binary equivalent
Flowchart of Decimal
to Binary Conversion
Yes
No
Another Example: Sorting
Sort the following objects w.r.t. their heights
Expected Result
Strategy
There are many strategies for solving this problem. We demonstrate a simple one:
Repeat the following steps while the list is un-
sorted:
Start with the first object in the list
Swap it with the one next to it if they are in the wrong
order
Repeat the same with the next to the first object
Keep on repeating until you reach the last object in the
list
Back to the Objects to be Sorted
Sorting: Step A1
Sorting: Step A1
Swap? Yes
Sorting: Step A2
Sorting: Step A2
Swap? Yes
Sorting: Step A3
Sorting: Step A3
Swap? No
Sorting: After Step A7
Q: Is the list sorted?
A: No
Sorting: Step B1
Sorting: Step B1
Swap? Yes
Sorting: Step B2
Sorting: Step B2
Swap? No
Sorting: After Step B7
Q: Is the list sorted?
A: No
Sorting: Step C1
Sorting: Step C1
Swap? No
Sorting: After Step C7
Q: Is the list sorted?
A: Yes
Algorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo code
 A number is even if it can be divided by 2 without remainder. Such numbers
are 2, 4, 6, 8.. and so on. The numbers that leave a remainder are called
odd. They are 1, 3, 5, 7.. and so on.
 In programming we find the remainder of a division with the operator %. Also
we use the double equals “==” to compare values for equality.
Algorithm and flowchart with pseudo code
 Summing two numbers was easy – the calculation was one block from the flow
chart. But how about 50? Do you have to write 50 blocks to solve this task?
Happily – no.
 You can automate this process by repeatedly incrementing the value of a
variable and checking it every time if it exceeds the last value – 50. Then sum
that number every step and... there you go! This construction is called loop.
Algorithm and flowchart with pseudo code
Find the biggest of 100 prices and reduce it
by 10%

More Related Content

What's hot (20)

Basic Computer Organization and Design
Basic  Computer  Organization  and  DesignBasic  Computer  Organization  and  Design
Basic Computer Organization and Design
Aksum Institute of Technology(AIT, @Letsgo)
 
Binary Arithmetic
Binary ArithmeticBinary Arithmetic
Binary Arithmetic
gavhays
 
Nested loops
Nested loopsNested loops
Nested loops
Neeru Mittal
 
Floating point representation
Floating point representationFloating point representation
Floating point representation
missstevenson01
 
python conditional statement.pptx
python conditional statement.pptxpython conditional statement.pptx
python conditional statement.pptx
Dolchandra
 
What is an algorithm?
What is an algorithm?What is an algorithm?
What is an algorithm?
Angela DeHart
 
10. switch case
10. switch case10. switch case
10. switch case
Way2itech
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
 
Parallel processing
Parallel processingParallel processing
Parallel processing
rajshreemuthiah
 
Excel
ExcelExcel
Excel
DrMohdIqbalSheikh
 
BOOLEAN ALGEBRA AND LOGIC GATE
BOOLEAN ALGEBRA AND LOGIC GATE BOOLEAN ALGEBRA AND LOGIC GATE
BOOLEAN ALGEBRA AND LOGIC GATE
Tamim Tanvir
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
Rabin BK
 
Assembly Language and microprocessor
Assembly Language and microprocessorAssembly Language and microprocessor
Assembly Language and microprocessor
Khaled Sany
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
Kamal Acharya
 
13 Boolean Algebra
13 Boolean Algebra13 Boolean Algebra
13 Boolean Algebra
Praveen M Jigajinni
 
Introduction to algorithms
Introduction to algorithmsIntroduction to algorithms
Introduction to algorithms
subhashchandra197
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis
Dr. Pankaj Agarwal
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
amber chaudary
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
Bishal Sharma
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 
Binary Arithmetic
Binary ArithmeticBinary Arithmetic
Binary Arithmetic
gavhays
 
Floating point representation
Floating point representationFloating point representation
Floating point representation
missstevenson01
 
python conditional statement.pptx
python conditional statement.pptxpython conditional statement.pptx
python conditional statement.pptx
Dolchandra
 
What is an algorithm?
What is an algorithm?What is an algorithm?
What is an algorithm?
Angela DeHart
 
10. switch case
10. switch case10. switch case
10. switch case
Way2itech
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
 
BOOLEAN ALGEBRA AND LOGIC GATE
BOOLEAN ALGEBRA AND LOGIC GATE BOOLEAN ALGEBRA AND LOGIC GATE
BOOLEAN ALGEBRA AND LOGIC GATE
Tamim Tanvir
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
Rabin BK
 
Assembly Language and microprocessor
Assembly Language and microprocessorAssembly Language and microprocessor
Assembly Language and microprocessor
Khaled Sany
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
Kamal Acharya
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis
Dr. Pankaj Agarwal
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
amber chaudary
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
Bishal Sharma
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 

Similar to Algorithm and flowchart with pseudo code (20)

Algo_Lecture01.pptx
Algo_Lecture01.pptxAlgo_Lecture01.pptx
Algo_Lecture01.pptx
ShaistaRiaz4
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
AOA Week 01.ppt
AOA Week 01.pptAOA Week 01.ppt
AOA Week 01.ppt
INAM352782
 
Algorithms 1
Algorithms 1Algorithms 1
Algorithms 1
Muhammad Uzair Rasheed
 
Algorithm for computational problematic sit
Algorithm for computational problematic sitAlgorithm for computational problematic sit
Algorithm for computational problematic sit
Saurabh846965
 
Ic lecture6 architecture and algo
Ic lecture6 architecture and algoIc lecture6 architecture and algo
Ic lecture6 architecture and algo
AttaullahRahimoon
 
Logic Development and Algorithm.
Logic Development and Algorithm.Logic Development and Algorithm.
Logic Development and Algorithm.
NandiniSidana
 
Lecture 2 role of algorithms in computing
Lecture 2   role of algorithms in computingLecture 2   role of algorithms in computing
Lecture 2 role of algorithms in computing
jayavignesh86
 
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHESC LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
HarshJha34
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithm
rajkumar1631010038
 
Algorithm.pdf
Algorithm.pdfAlgorithm.pdf
Algorithm.pdf
MIT,Imphal
 
Architecture Algorithm Definition
Architecture Algorithm DefinitionArchitecture Algorithm Definition
Architecture Algorithm Definition
Gaditek
 
Chapter 3 introduction to algorithms handouts (with notes)
Chapter 3 introduction to algorithms handouts (with notes)Chapter 3 introduction to algorithms handouts (with notes)
Chapter 3 introduction to algorithms handouts (with notes)
mailund
 
Algorithm & data structure lec2
Algorithm & data structure lec2Algorithm & data structure lec2
Algorithm & data structure lec2
Abdul Khan
 
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffdPROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
dinesh620610
 
Systems in the small - Introduction to Algorithms
Systems in the small - Introduction to AlgorithmsSystems in the small - Introduction to Algorithms
Systems in the small - Introduction to Algorithms
David Millard
 
Ds03 part i algorithms by jyoti lakhani
Ds03 part i algorithms   by jyoti lakhaniDs03 part i algorithms   by jyoti lakhani
Ds03 part i algorithms by jyoti lakhani
jyoti_lakhani
 
Design and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit oneDesign and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit one
ssuserb7c8b8
 
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPTANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
AIET
 
Algorithms notes 2 tutorials duniya
Algorithms notes 2   tutorials duniyaAlgorithms notes 2   tutorials duniya
Algorithms notes 2 tutorials duniya
TutorialsDuniya.com
 
Algo_Lecture01.pptx
Algo_Lecture01.pptxAlgo_Lecture01.pptx
Algo_Lecture01.pptx
ShaistaRiaz4
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
AOA Week 01.ppt
AOA Week 01.pptAOA Week 01.ppt
AOA Week 01.ppt
INAM352782
 
Algorithm for computational problematic sit
Algorithm for computational problematic sitAlgorithm for computational problematic sit
Algorithm for computational problematic sit
Saurabh846965
 
Ic lecture6 architecture and algo
Ic lecture6 architecture and algoIc lecture6 architecture and algo
Ic lecture6 architecture and algo
AttaullahRahimoon
 
Logic Development and Algorithm.
Logic Development and Algorithm.Logic Development and Algorithm.
Logic Development and Algorithm.
NandiniSidana
 
Lecture 2 role of algorithms in computing
Lecture 2   role of algorithms in computingLecture 2   role of algorithms in computing
Lecture 2 role of algorithms in computing
jayavignesh86
 
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHESC LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
HarshJha34
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithm
rajkumar1631010038
 
Architecture Algorithm Definition
Architecture Algorithm DefinitionArchitecture Algorithm Definition
Architecture Algorithm Definition
Gaditek
 
Chapter 3 introduction to algorithms handouts (with notes)
Chapter 3 introduction to algorithms handouts (with notes)Chapter 3 introduction to algorithms handouts (with notes)
Chapter 3 introduction to algorithms handouts (with notes)
mailund
 
Algorithm & data structure lec2
Algorithm & data structure lec2Algorithm & data structure lec2
Algorithm & data structure lec2
Abdul Khan
 
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffdPROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
dinesh620610
 
Systems in the small - Introduction to Algorithms
Systems in the small - Introduction to AlgorithmsSystems in the small - Introduction to Algorithms
Systems in the small - Introduction to Algorithms
David Millard
 
Ds03 part i algorithms by jyoti lakhani
Ds03 part i algorithms   by jyoti lakhaniDs03 part i algorithms   by jyoti lakhani
Ds03 part i algorithms by jyoti lakhani
jyoti_lakhani
 
Design and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit oneDesign and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit one
ssuserb7c8b8
 
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPTANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
AIET
 
Algorithms notes 2 tutorials duniya
Algorithms notes 2   tutorials duniyaAlgorithms notes 2   tutorials duniya
Algorithms notes 2 tutorials duniya
TutorialsDuniya.com
 
Ad

Recently uploaded (20)

Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
ManiMaran230751
 
ISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdf
ISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdfISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdf
ISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...
cyhuutjdoazdwrnubt
 
Introduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptxIntroduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptx
gunjalsachin
 
Pruebas y Solucion de problemas empresariales en redes de Fibra Optica
Pruebas y Solucion de problemas empresariales en redes de Fibra OpticaPruebas y Solucion de problemas empresariales en redes de Fibra Optica
Pruebas y Solucion de problemas empresariales en redes de Fibra Optica
OmarAlfredoDelCastil
 
HVAC Air Filter Equipment-Catalouge-Final.pdf
HVAC Air Filter Equipment-Catalouge-Final.pdfHVAC Air Filter Equipment-Catalouge-Final.pdf
HVAC Air Filter Equipment-Catalouge-Final.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning ModelEnhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
IRJET Journal
 
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
IRJET Journal
 
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
sebastianku31
 
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDINGMODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
Dr. BASWESHWAR JIRWANKAR
 
Influence line diagram for truss in a robust
Influence line diagram for truss in a robustInfluence line diagram for truss in a robust
Influence line diagram for truss in a robust
ParthaSengupta26
 
All about the Snail Power Catalog Product 2025
All about the Snail Power Catalog  Product 2025All about the Snail Power Catalog  Product 2025
All about the Snail Power Catalog Product 2025
kstgroupvn
 
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDINGMODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
Dr. BASWESHWAR JIRWANKAR
 
Software_Engineering_in_6_Hours_lyst1728638742594.pdf
Software_Engineering_in_6_Hours_lyst1728638742594.pdfSoftware_Engineering_in_6_Hours_lyst1728638742594.pdf
Software_Engineering_in_6_Hours_lyst1728638742594.pdf
VanshMunjal7
 
Axial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Axial Capacity Estimation of FRP-strengthened Corroded Concrete ColumnsAxial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Axial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Journal of Soft Computing in Civil Engineering
 
Software Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance OptimizationSoftware Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance Optimization
kiwoong (daniel) kim
 
Fresh concrete Workability Measurement
Fresh concrete  Workability  MeasurementFresh concrete  Workability  Measurement
Fresh concrete Workability Measurement
SasiVarman5
 
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her IndustryTesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia
 
Air Filter Flat Sheet Media-Catalouge-Final.pdf
Air Filter Flat Sheet Media-Catalouge-Final.pdfAir Filter Flat Sheet Media-Catalouge-Final.pdf
Air Filter Flat Sheet Media-Catalouge-Final.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
[HIFLUX] Lok Fitting&Valve Catalog 2025 (Eng)
[HIFLUX] Lok Fitting&Valve Catalog 2025 (Eng)[HIFLUX] Lok Fitting&Valve Catalog 2025 (Eng)
[HIFLUX] Lok Fitting&Valve Catalog 2025 (Eng)
하이플럭스 / HIFLUX Co., Ltd.
 
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
ManiMaran230751
 
What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...
cyhuutjdoazdwrnubt
 
Introduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptxIntroduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptx
gunjalsachin
 
Pruebas y Solucion de problemas empresariales en redes de Fibra Optica
Pruebas y Solucion de problemas empresariales en redes de Fibra OpticaPruebas y Solucion de problemas empresariales en redes de Fibra Optica
Pruebas y Solucion de problemas empresariales en redes de Fibra Optica
OmarAlfredoDelCastil
 
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning ModelEnhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
IRJET Journal
 
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
IRJET Journal
 
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
sebastianku31
 
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDINGMODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
Dr. BASWESHWAR JIRWANKAR
 
Influence line diagram for truss in a robust
Influence line diagram for truss in a robustInfluence line diagram for truss in a robust
Influence line diagram for truss in a robust
ParthaSengupta26
 
All about the Snail Power Catalog Product 2025
All about the Snail Power Catalog  Product 2025All about the Snail Power Catalog  Product 2025
All about the Snail Power Catalog Product 2025
kstgroupvn
 
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDINGMODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
Dr. BASWESHWAR JIRWANKAR
 
Software_Engineering_in_6_Hours_lyst1728638742594.pdf
Software_Engineering_in_6_Hours_lyst1728638742594.pdfSoftware_Engineering_in_6_Hours_lyst1728638742594.pdf
Software_Engineering_in_6_Hours_lyst1728638742594.pdf
VanshMunjal7
 
Software Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance OptimizationSoftware Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance Optimization
kiwoong (daniel) kim
 
Fresh concrete Workability Measurement
Fresh concrete  Workability  MeasurementFresh concrete  Workability  Measurement
Fresh concrete Workability Measurement
SasiVarman5
 
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her IndustryTesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia
 
Ad

Algorithm and flowchart with pseudo code

  • 2. Solving Problems (1) When faced with a problem: 1. We first clearly define the problem 2. Think of possible solutions 3. Select the one that we think is the best under the prevailing circumstances 4. And then apply that solution 5. If the solution works as desired, fine; else we go back to step 2
  • 3. Solving Problems (2)  It is quite common to first solve a problem for a particular case  Then for another  And, possibly another  And watch for patterns and trends that emerge  And to use the knowledge form those patterns and trends in coming up with a general solution
  • 4. Solving Problems (3)  It helps if we have experienced that problem or similar ones before  Generally, there are many ways of solving a given problem; the best problem- solvers come-up with the most appropriate solution more often than not!  The process that can be used to solve a problem is termed as the “algorithm”
  • 5. Examples  Addition  Conversion from decimal to binary  The process of boiling an egg  The process of mailing a letter  Sorting  Searching
  • 6. Let us write down the algorithm for a problem that is familiar to us Converting a decimal number into binary
  • 7. Convert 75 to Binary 752 37 12 18 12 9 02 4 12 2 02 1 02 0 1 1001011 remainder
  • 8. Algorithm for Decimal-to-Binary Conversion 1. Write the decimal number 2. Divide by 2; write quotient and remainder 3. Repeat step 2 on the quotient; keep on repeating until the quotient becomes zero 4. Write all remainder digits in the reverse order (last remainder first) to form the final result
  • 9. Points to Note: 1. The process consists of repeated application of simple steps 2. All steps are unambiguous (clearly defined) 3. We are capable of doing all those steps 4. Only a limited no. of steps needs to be taken 5. Once all those steps are taken according to the prescribed sequence, the required result will be found 6. Moreover, the process will stop at that point
  • 10. Algorithm (Better Definition) 1st Definition: Sequence of steps that can be taken to solve a problem Better Definition: A precise sequence of a limited number of unambiguous, executable steps that terminates in the form of a solution
  • 11. Three Requirements: 1. Sequence is: a. Precise b. Consists of a limited number of steps 2. Each step is: a. Unambiguous b. Executable 3. The sequence of steps terminates in the form of a solution
  • 12. Why Algorithms are Useful?  Once we find an algorithm for solving a problem, we do not need to re- discover it the next time we are faced with that problem  Once an algorithm is known, the task of solving the problem reduces to following (almost blindly and without thinking) the instructions precisely  All the knowledge required for solving the problem is present in the algorithm
  • 13. Analysis of Algorithms  Analysis in the context of algorithms is concerned with predicting the resources that are requires:  Computational time  Memory  Bandwidth  Logic functions  However, Time – generally measured in terms of the number of steps required to execute an algorithm - is the resource of most interest  By analyzing several candidate algorithms, the most efficient one(s) can be identified
  • 14. Selecting Among Algorithms When choosing among competing, successful solutions to a problem, choose the one which is the least complex This principle is called the “Ockham’s Razor,” after William of Ockham - famous 13-th century English philosopher
  • 15. Syntax & Semantics An algorithm is “correct” if its:  Semantics are correct  Syntax is correct Semantics: The concept embedded in an algorithm (the soul!) Syntax: The actual representation of an algorithm (the body!) WARNINGS: 1. An algorithm can be syntactically correct, yet semantically incorrect – very dangerous situation! 2. Syntactic correctness is easier to check as compared with semantic
  • 16. Now onto Algorithm Representation  We have said enough about algorithms – their definition, their types, etc.  But, how do we actually represent them?  Generally, SW developers represent them in one of three forms:  Pseudo code  Flowcharts  Actual code
  • 17. Pseudo Code  Language that is typically used for writing algorithms  Similar to a programming language, but not as rigid  The method of expression most suitable for a given situation is used:  At times, plain English  At others, a programming language like syntax
  • 18. Flowchart  A graphical representation of a process (e.g. an algorithm), in which graphic objects are used to indicate the steps & decisions that are taken as the process moves along from start to finish  Individual steps are represented by boxes and other shapes on the flowchart, with arrows between those shapes indicating the order in which the steps are taken
  • 19. Start or stop Process Input or output Connector Decision Flow line Off-page connector Flowchart Elements
  • 20. Algorithm Building Blocks All problems can be solved by employing any one of the following building blocks or their combinations 1. Sequences 2. Conditionals 3. Loops
  • 21. Sequences A sequence of instructions that are executed in the precise order they are written in: statement block 1 statement block 2 statement block 3 statement block 1 statement block 2 statement block 3
  • 22. Conditionals Select between alternate courses of action depending upon the evaluation of a condition If ( condition = true ) statement block 1 Else statement block 2 End if statement block 1 condition True False statement block 2
  • 23. Loops Loop through a set of statements as long as a condition is true Loop while ( condition = true ) statement block End Loop condition True False statement block
  • 24. Problem Statement Convert a decimal number into binary
  • 25. Convert 75 to Binary 752 37 12 18 12 9 02 4 12 2 02 1 02 0 1 1001011 remainder
  • 26. Solution in Pseudo Code 1. Let the decimal number be an integer x, x > 0 2. Let the binary equivalent be an empty string y 3. Repeat while x > 0 { Determine the quotient & remainder of x ÷ 2 y = CONCATENATE( remainder, y ) x = quotient } 4. Print y 5. Stop
  • 27. Start Find quotient & remainder of x ÷ 2 Get x x>0 ? Print y Stop y = CONC(remainder, x) x = quotient x is the decimal number y is the binary equivalent Flowchart of Decimal to Binary Conversion Yes No
  • 28. Another Example: Sorting Sort the following objects w.r.t. their heights
  • 30. Strategy There are many strategies for solving this problem. We demonstrate a simple one: Repeat the following steps while the list is un- sorted: Start with the first object in the list Swap it with the one next to it if they are in the wrong order Repeat the same with the next to the first object Keep on repeating until you reach the last object in the list
  • 31. Back to the Objects to be Sorted
  • 39. Q: Is the list sorted? A: No
  • 45. Q: Is the list sorted? A: No
  • 49. Q: Is the list sorted? A: Yes
  • 52.  A number is even if it can be divided by 2 without remainder. Such numbers are 2, 4, 6, 8.. and so on. The numbers that leave a remainder are called odd. They are 1, 3, 5, 7.. and so on.  In programming we find the remainder of a division with the operator %. Also we use the double equals “==” to compare values for equality.
  • 54.  Summing two numbers was easy – the calculation was one block from the flow chart. But how about 50? Do you have to write 50 blocks to solve this task? Happily – no.  You can automate this process by repeatedly incrementing the value of a variable and checking it every time if it exceeds the last value – 50. Then sum that number every step and... there you go! This construction is called loop.
  • 56. Find the biggest of 100 prices and reduce it by 10%