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)

Algorithm Design and Complexity - Course 1&2
Algorithm Design and Complexity - Course 1&2Algorithm Design and Complexity - Course 1&2
Algorithm Design and Complexity - Course 1&2
Traian Rebedea
 
Daa chapter4
Daa chapter4Daa chapter4
Daa chapter4
B.Kirron Reddi
 
Algorithms notes 2 tutorials duniya
Algorithms notes 2   tutorials duniyaAlgorithms notes 2   tutorials duniya
Algorithms notes 2 tutorials duniya
TutorialsDuniya.com
 
Algorithms and how to write an algorithms
Algorithms and how to write an algorithmsAlgorithms and how to write an algorithms
Algorithms and how to write an algorithms
Ahmed Nobi
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
jinalgoti
 
Types of Algorithms.ppt
Types of Algorithms.pptTypes of Algorithms.ppt
Types of Algorithms.ppt
ALIZAIB KHAN
 
Visual Problem Solving (Lecture)
Visual Problem Solving (Lecture)Visual Problem Solving (Lecture)
Visual Problem Solving (Lecture)
Lawrence Wachs
 
Algorithm for computational problematic sit
Algorithm for computational problematic sitAlgorithm for computational problematic sit
Algorithm for computational problematic sit
Saurabh846965
 
01 Notes Introduction Analysis of Algorithms Notes
01 Notes Introduction Analysis of Algorithms Notes01 Notes Introduction Analysis of Algorithms Notes
01 Notes Introduction Analysis of Algorithms Notes
Andres Mendez-Vazquez
 
Ic lecture6 architecture and algo
Ic lecture6 architecture and algoIc lecture6 architecture and algo
Ic lecture6 architecture and algo
AttaullahRahimoon
 
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
 
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
 
Study Material for Problem Solving Techniques
Study Material for Problem Solving TechniquesStudy Material for Problem Solving Techniques
Study Material for Problem Solving Techniques
Bobby Murugesan
 
Practical 01 (detailed)
Practical 01 (detailed)Practical 01 (detailed)
Practical 01 (detailed)
Muhammadalizardari
 
Architecture Algorithm Definition
Architecture Algorithm DefinitionArchitecture Algorithm Definition
Architecture Algorithm Definition
Gaditek
 
Lesson 3
Lesson 3Lesson 3
Lesson 3
Dr. Rupinder Singh
 
Algorithms 1
Algorithms 1Algorithms 1
Algorithms 1
Muhammad Uzair Rasheed
 
Introduction to Programming
Introduction to ProgrammingIntroduction to Programming
Introduction to Programming
Prof Ansari
 
1. Solving a Problem With a Computer.pptx
1. Solving a Problem With a Computer.pptx1. Solving a Problem With a Computer.pptx
1. Solving a Problem With a Computer.pptx
SharjeelFaisal4
 
Algorithm Design and Complexity - Course 1&2
Algorithm Design and Complexity - Course 1&2Algorithm Design and Complexity - Course 1&2
Algorithm Design and Complexity - Course 1&2
Traian Rebedea
 
Algorithms notes 2 tutorials duniya
Algorithms notes 2   tutorials duniyaAlgorithms notes 2   tutorials duniya
Algorithms notes 2 tutorials duniya
TutorialsDuniya.com
 
Algorithms and how to write an algorithms
Algorithms and how to write an algorithmsAlgorithms and how to write an algorithms
Algorithms and how to write an algorithms
Ahmed Nobi
 
Types of Algorithms.ppt
Types of Algorithms.pptTypes of Algorithms.ppt
Types of Algorithms.ppt
ALIZAIB KHAN
 
Visual Problem Solving (Lecture)
Visual Problem Solving (Lecture)Visual Problem Solving (Lecture)
Visual Problem Solving (Lecture)
Lawrence Wachs
 
Algorithm for computational problematic sit
Algorithm for computational problematic sitAlgorithm for computational problematic sit
Algorithm for computational problematic sit
Saurabh846965
 
01 Notes Introduction Analysis of Algorithms Notes
01 Notes Introduction Analysis of Algorithms Notes01 Notes Introduction Analysis of Algorithms Notes
01 Notes Introduction Analysis of Algorithms Notes
Andres Mendez-Vazquez
 
Ic lecture6 architecture and algo
Ic lecture6 architecture and algoIc lecture6 architecture and algo
Ic lecture6 architecture and algo
AttaullahRahimoon
 
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
 
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
 
Study Material for Problem Solving Techniques
Study Material for Problem Solving TechniquesStudy Material for Problem Solving Techniques
Study Material for Problem Solving Techniques
Bobby Murugesan
 
Architecture Algorithm Definition
Architecture Algorithm DefinitionArchitecture Algorithm Definition
Architecture Algorithm Definition
Gaditek
 
Introduction to Programming
Introduction to ProgrammingIntroduction to Programming
Introduction to Programming
Prof Ansari
 
1. Solving a Problem With a Computer.pptx
1. Solving a Problem With a Computer.pptx1. Solving a Problem With a Computer.pptx
1. Solving a Problem With a Computer.pptx
SharjeelFaisal4
 
Ad

Recently uploaded (20)

Proposed EPA Municipal Waste Combustor Rule
Proposed EPA Municipal Waste Combustor RuleProposed EPA Municipal Waste Combustor Rule
Proposed EPA Municipal Waste Combustor Rule
AlvaroLinero2
 
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
gerogepatton
 
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
 
"The Enigmas of the Riemann Hypothesis" by Julio Chai
"The Enigmas of the Riemann Hypothesis" by Julio Chai"The Enigmas of the Riemann Hypothesis" by Julio Chai
"The Enigmas of the Riemann Hypothesis" by Julio Chai
Julio Chai
 
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdfKevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Medicoz Clinic
 
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
 
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
 
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
RishabhGupta578788
 
Application Security and Secure Software Development Lifecycle
Application  Security and Secure Software Development LifecycleApplication  Security and Secure Software Development Lifecycle
Application Security and Secure Software Development Lifecycle
DrKavithaP1
 
Electrical and Electronics Engineering: An International Journal (ELELIJ)
Electrical and Electronics Engineering: An International Journal (ELELIJ)Electrical and Electronics Engineering: An International Journal (ELELIJ)
Electrical and Electronics Engineering: An International Journal (ELELIJ)
elelijjournal653
 
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 / HIFLUX Co., Ltd.
 
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
 
ISO 4548-9 Oil Filter Anti Drain Catalogue.pdf
ISO 4548-9 Oil Filter Anti Drain Catalogue.pdfISO 4548-9 Oil Filter Anti Drain Catalogue.pdf
ISO 4548-9 Oil Filter Anti Drain Catalogue.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
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
 
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
 
UNIT-4-PPT UNIT COMMITMENT AND ECONOMIC DISPATCH
UNIT-4-PPT UNIT COMMITMENT AND ECONOMIC DISPATCHUNIT-4-PPT UNIT COMMITMENT AND ECONOMIC DISPATCH
UNIT-4-PPT UNIT COMMITMENT AND ECONOMIC DISPATCH
Sridhar191373
 
UNIT-1-PPT-Introduction about Power System Operation and Control
UNIT-1-PPT-Introduction about Power System Operation and ControlUNIT-1-PPT-Introduction about Power System Operation and Control
UNIT-1-PPT-Introduction about Power System Operation and Control
Sridhar191373
 
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
 
Video Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptxVideo Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptx
HadiBadri1
 
Proposed EPA Municipal Waste Combustor Rule
Proposed EPA Municipal Waste Combustor RuleProposed EPA Municipal Waste Combustor Rule
Proposed EPA Municipal Waste Combustor Rule
AlvaroLinero2
 
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
gerogepatton
 
"The Enigmas of the Riemann Hypothesis" by Julio Chai
"The Enigmas of the Riemann Hypothesis" by Julio Chai"The Enigmas of the Riemann Hypothesis" by Julio Chai
"The Enigmas of the Riemann Hypothesis" by Julio Chai
Julio Chai
 
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdfKevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Medicoz Clinic
 
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
 
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
 
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
RishabhGupta578788
 
Application Security and Secure Software Development Lifecycle
Application  Security and Secure Software Development LifecycleApplication  Security and Secure Software Development Lifecycle
Application Security and Secure Software Development Lifecycle
DrKavithaP1
 
Electrical and Electronics Engineering: An International Journal (ELELIJ)
Electrical and Electronics Engineering: An International Journal (ELELIJ)Electrical and Electronics Engineering: An International Journal (ELELIJ)
Electrical and Electronics Engineering: An International Journal (ELELIJ)
elelijjournal653
 
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 / HIFLUX Co., Ltd.
 
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
 
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
 
UNIT-4-PPT UNIT COMMITMENT AND ECONOMIC DISPATCH
UNIT-4-PPT UNIT COMMITMENT AND ECONOMIC DISPATCHUNIT-4-PPT UNIT COMMITMENT AND ECONOMIC DISPATCH
UNIT-4-PPT UNIT COMMITMENT AND ECONOMIC DISPATCH
Sridhar191373
 
UNIT-1-PPT-Introduction about Power System Operation and Control
UNIT-1-PPT-Introduction about Power System Operation and ControlUNIT-1-PPT-Introduction about Power System Operation and Control
UNIT-1-PPT-Introduction about Power System Operation and Control
Sridhar191373
 
Video Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptxVideo Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptx
HadiBadri1
 
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%