SlideShare a Scribd company logo
2
Most read
ALGORITHM DESIGN AND PROBLEM SOLVING
-In practice, in order to solve any complex real life problems, first we have to define the
problem and then, design algorithm to solve it.
Def Algorithm is a step-by-step process of solving a well-defined computational
problem
Algorithm: a sequence of steps that can be carried out to perform a task
We use algorithms in everyday life. If you need to change a wheel on a car, you mightneed to
follow instructions (the algorithm) from a manual:
1 Take a spanner and loosen the wheel nuts.
2 Position a jack in an appropriate place.
3 Raise the car.
4 Take off the wheel nuts and the wheel.
5 Lift replacement wheel into position .
6 Replace wheel nuts and tighten by hand.
7 Lower the car.
8 Fully tighten wheel nuts.
-This mightsound all very straightforward.
-However, if the instructions are notfollowed in the correct logical sequence,the process mightbecome much more
difficult or even impossible.
-For example,if you tried to do Step 1 after Step 3, the wheel may spin and you can't loosen
the wheel nuts.
- You can't do Step 4 before Step 3.
Many problems we try to solve with a computer involve data. The solution involves inputting
data to the computer,processing the data and outputting results.
Input Process Output
Algorithm Tools
Structured English: a subset of the English language that consists of command statements used to
describe an algorithm
Pseudocode: a way of using keywords and identifiers to describe an algorithm without following the
syntax of a particular programming language
Flowchart: shapes linked together to represent the sequential steps of an algorithm
However, before writing a program, we need to write the steps to solve the problem in
simple English language.
Example
Let us take one simple day-to-day example by writing algorithm for making “SADZA”
Step 1: Start
Step 2: Take pan with water
Step 3: Put pan on the burner
Step 4: Switch on the gas/burner
Step 6: Give two minutes to boil
Step 7: Put mealie meal
Step 8: Take out the stir stick and stir it
Step 9 Allow it to simmer
Step 10 Stir again and adding mealie meal
Step 11: Put the sadza on the plate and serve it
Step 12: Stop.
Purposes of designing an Algorithm in problem-solving
1. Expresses a function starting from an initial state and initial input.
2. algorithms are used to simplify the program implementation
CONTROL STRUCTURE
In computer science, when writing algorithms, we use basic types of construct:
Sequence:
-a number of steps are performed, one after the other.
• Selection:
-under certain conditions some steps are performed, otherwise different (or no) steps are performed.
Repetition:
-a sequence of steps is performed a number of times. This is also known as iteration or looping.
1. Sequence statements:
In this program, all the instructions are executed one after another.
Example 1
Write an algorithm to print, “ Good Morning.”
Step 1: Start
Step 2: Print “Good Morning”
Step 3: Stop
Example 2
Write an algorithm to find area of a rectangle.
Step 1: Start
Step 2: Take length and breadth and store them as L and B?
Step 3: Multiply by L and B and store it in area
Step 4: Print area
Step 5: Stop
NB In the above mentioned two examples (Example II and III), all the instructions are
executed one after another. These examples are executed under sequential statement.
2.Selective Statements:
-In this program, some portion of the program is executed based upon the conditional
test.
-If the conditional test is true, compiler will execute some part of the program,
otherwise it will execute the other part of the program.
Example 3
Write an algorithm to check whether he is eligible to vote? (more than or equal to 18
years old).
Step 1: Start
Step 2: Take age and store it in age
Step 3: Check age value, if age >= 18 then go to step 4 else step 5
Step 4: Print “Eligible to vote” and go to step 6
Step 5: Print “Not eligible to vote”
Step 6: Stop
Example 4
Write an algorithm to check whether given number is +ve, -ve or zero.
Step 1: Start
Step 2: Take any number and store it in n.
Step 3: Check n value, if n > 0 then go to step 5 else go to step 4
Step 4: Check n value, if n < 0 then go to step 6 else go to step 7
Step 5: Print “Given number is +ve” and go to step 8
Step 6: Print “Given number is -ve” and go to step 8
Step 7: Print “Given number is zero”
Step 8: Stop
Example. What would be output if the numbers 7 and 18 were
input?
-In the above mentioned examples IV and V, all the statements are not executed, but
based upon the input, some portions of the algorithm are executed, because we have
“true” or „false‟ situation in the program.
//+99999999999999
3. Iterative/Repetition statements:
-In some programs, certain set of statements are executed again and again based upon
conditional test. i.e. executed more than one time.
-This type of execution is called “looping or iteration.”
Example 5
Write an algorithm to print all natural numbers up to „n‟.+9
Step 1: Start
Step 2: Take any number and store it in n.
Step 3: Store 1 in I
Step 4: Check I value, if I<=n then go to step 5 else go to step 8
Step 5: Print I
Step 6: Increment I value by 1
Step 5: Go to step 4
Step 8: Stop
In the above example, steps 4, 5, 6 and 7 are executed more than one time.
-Fin-ite and Infinite loop
-In looping statements, if some set of statements are executed „n‟ times (fixed number
of times), then it is called “finite loop”.
-At the same time, if some set of statements are executed again and again without any
end (infinite times), then it is called “infinite loop”.
+
Note: Set of statements is executed again and again without any end is called infinite
loop.
Flowchart
-we have learnt to write algorithms, i.e. step-by step process of solving a problem.
-We can also show these steps in graphical form by using some symbols.
NB: Flowchart is the graphical representation of an algorithm
-This is called flowcharting
Problem solving
• Step 1:
– Clearly specify the problem to be solved.
• Step 2:
– Draw flowchart or write algorithm.
• Step 3:
Dept. of CSE, IIT KGP
– Convert flowchart (algorithm) into program code.
• Step 4:
– Compile the program into object code.
• Step 5:
– Execute the program
Flowchart Symbols:

More Related Content

PDF
Human Computer Interaction Notes 176.pdf
PDF
Bayesian networks in AI
DOCX
Multiversion Concurrency Control Techniques
PPTX
Osi security architecture in network.pptx
PPTX
NLP_KASHK:Smoothing N-gram Models
PPTX
Deadlock dbms
Human Computer Interaction Notes 176.pdf
Bayesian networks in AI
Multiversion Concurrency Control Techniques
Osi security architecture in network.pptx
NLP_KASHK:Smoothing N-gram Models
Deadlock dbms

What's hot (20)

PPT
Binary number systems
PPTX
Turing machine-TOC
PPTX
Treebank annotation
PPTX
Introduction to backwards learning algorithm
PPTX
Wimp interface
PPTX
Making Complex Decisions(Artificial Intelligence)
PDF
Distributed Systems Concepts
PPTX
Transaction management DBMS
PPTX
Human Memory
PPTX
File Management in Operating System
PPT
BackTracking Algorithm: Technique and Examples
PPTX
Transaction Properties in database | ACID Properties
PPTX
Active database
PPTX
Concurrency control
PPT
Logic Micro Operation
PDF
R Programming: Learn To Manipulate Strings In R
PDF
Interaction design beyond human computer interaction
PPT
HCI 3e - Ch 16: Dialogue notations and design
PPT
Database concurrency control &amp; recovery (1)
Binary number systems
Turing machine-TOC
Treebank annotation
Introduction to backwards learning algorithm
Wimp interface
Making Complex Decisions(Artificial Intelligence)
Distributed Systems Concepts
Transaction management DBMS
Human Memory
File Management in Operating System
BackTracking Algorithm: Technique and Examples
Transaction Properties in database | ACID Properties
Active database
Concurrency control
Logic Micro Operation
R Programming: Learn To Manipulate Strings In R
Interaction design beyond human computer interaction
HCI 3e - Ch 16: Dialogue notations and design
Database concurrency control &amp; recovery (1)
Ad

Similar to Algorithm design and problem solving (20)

PDF
Unit 1-problem solving with algorithm
PDF
GE8151 notes pdf.pdf
PPTX
Data Structures_Introduction to algorithms.pptx
PPTX
UNIT I.pptxpython unit 1 engineering full unit completed
PPT
3 algorithm-and-flowchart
PPT
Unit 1 psp
PPTX
Introduction to problem solving Techniques
PPSX
Algorithm and flowchart
PPTX
UNIT 1.pptx
PDF
Introduction to programming : flowchart, algorithm
PDF
Introduction to Problem Solving Techniques- Python
PDF
Algorithm.pdf
PPT
Proble, Solving & Automation
PPT
UNIT- 3-FOC.ppt
PPTX
Daa unit 1
PPTX
Algorithm & data structure lec2
PDF
265 ge8151 problem solving and python programming - 2 marks with answers
PDF
GE3151 PSPP _Unit 1 notes and Question bank.pdf
PPT
Unit 1 python (2021 r)
PPTX
PROBLEM SOLVING.pptx
Unit 1-problem solving with algorithm
GE8151 notes pdf.pdf
Data Structures_Introduction to algorithms.pptx
UNIT I.pptxpython unit 1 engineering full unit completed
3 algorithm-and-flowchart
Unit 1 psp
Introduction to problem solving Techniques
Algorithm and flowchart
UNIT 1.pptx
Introduction to programming : flowchart, algorithm
Introduction to Problem Solving Techniques- Python
Algorithm.pdf
Proble, Solving & Automation
UNIT- 3-FOC.ppt
Daa unit 1
Algorithm & data structure lec2
265 ge8151 problem solving and python programming - 2 marks with answers
GE3151 PSPP _Unit 1 notes and Question bank.pdf
Unit 1 python (2021 r)
PROBLEM SOLVING.pptx
Ad

Recently uploaded (20)

PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Advanced IT Governance
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Advanced IT Governance
Dropbox Q2 2025 Financial Results & Investor Presentation
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Reach Out and Touch Someone: Haptics and Empathic Computing
Spectral efficient network and resource selection model in 5G networks
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
Chapter 3 Spatial Domain Image Processing.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Understanding_Digital_Forensics_Presentation.pptx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
The Rise and Fall of 3GPP – Time for a Sabbatical?
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
MYSQL Presentation for SQL database connectivity
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
madgavkar20181017ppt McKinsey Presentation.pdf
NewMind AI Monthly Chronicles - July 2025
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)

Algorithm design and problem solving

  • 1. ALGORITHM DESIGN AND PROBLEM SOLVING -In practice, in order to solve any complex real life problems, first we have to define the problem and then, design algorithm to solve it. Def Algorithm is a step-by-step process of solving a well-defined computational problem Algorithm: a sequence of steps that can be carried out to perform a task We use algorithms in everyday life. If you need to change a wheel on a car, you mightneed to follow instructions (the algorithm) from a manual: 1 Take a spanner and loosen the wheel nuts. 2 Position a jack in an appropriate place. 3 Raise the car. 4 Take off the wheel nuts and the wheel. 5 Lift replacement wheel into position . 6 Replace wheel nuts and tighten by hand. 7 Lower the car. 8 Fully tighten wheel nuts. -This mightsound all very straightforward. -However, if the instructions are notfollowed in the correct logical sequence,the process mightbecome much more difficult or even impossible. -For example,if you tried to do Step 1 after Step 3, the wheel may spin and you can't loosen the wheel nuts. - You can't do Step 4 before Step 3. Many problems we try to solve with a computer involve data. The solution involves inputting data to the computer,processing the data and outputting results. Input Process Output Algorithm Tools Structured English: a subset of the English language that consists of command statements used to describe an algorithm Pseudocode: a way of using keywords and identifiers to describe an algorithm without following the syntax of a particular programming language Flowchart: shapes linked together to represent the sequential steps of an algorithm However, before writing a program, we need to write the steps to solve the problem in simple English language. Example Let us take one simple day-to-day example by writing algorithm for making “SADZA” Step 1: Start Step 2: Take pan with water Step 3: Put pan on the burner Step 4: Switch on the gas/burner Step 6: Give two minutes to boil Step 7: Put mealie meal Step 8: Take out the stir stick and stir it Step 9 Allow it to simmer Step 10 Stir again and adding mealie meal Step 11: Put the sadza on the plate and serve it
  • 2. Step 12: Stop. Purposes of designing an Algorithm in problem-solving 1. Expresses a function starting from an initial state and initial input. 2. algorithms are used to simplify the program implementation CONTROL STRUCTURE In computer science, when writing algorithms, we use basic types of construct: Sequence: -a number of steps are performed, one after the other. • Selection: -under certain conditions some steps are performed, otherwise different (or no) steps are performed. Repetition: -a sequence of steps is performed a number of times. This is also known as iteration or looping. 1. Sequence statements: In this program, all the instructions are executed one after another. Example 1 Write an algorithm to print, “ Good Morning.” Step 1: Start Step 2: Print “Good Morning” Step 3: Stop Example 2 Write an algorithm to find area of a rectangle. Step 1: Start Step 2: Take length and breadth and store them as L and B? Step 3: Multiply by L and B and store it in area Step 4: Print area Step 5: Stop
  • 3. NB In the above mentioned two examples (Example II and III), all the instructions are executed one after another. These examples are executed under sequential statement. 2.Selective Statements: -In this program, some portion of the program is executed based upon the conditional test. -If the conditional test is true, compiler will execute some part of the program, otherwise it will execute the other part of the program. Example 3 Write an algorithm to check whether he is eligible to vote? (more than or equal to 18 years old). Step 1: Start Step 2: Take age and store it in age Step 3: Check age value, if age >= 18 then go to step 4 else step 5 Step 4: Print “Eligible to vote” and go to step 6 Step 5: Print “Not eligible to vote” Step 6: Stop Example 4
  • 4. Write an algorithm to check whether given number is +ve, -ve or zero. Step 1: Start Step 2: Take any number and store it in n. Step 3: Check n value, if n > 0 then go to step 5 else go to step 4 Step 4: Check n value, if n < 0 then go to step 6 else go to step 7 Step 5: Print “Given number is +ve” and go to step 8 Step 6: Print “Given number is -ve” and go to step 8 Step 7: Print “Given number is zero” Step 8: Stop Example. What would be output if the numbers 7 and 18 were input? -In the above mentioned examples IV and V, all the statements are not executed, but based upon the input, some portions of the algorithm are executed, because we have “true” or „false‟ situation in the program.
  • 5. //+99999999999999 3. Iterative/Repetition statements: -In some programs, certain set of statements are executed again and again based upon conditional test. i.e. executed more than one time. -This type of execution is called “looping or iteration.” Example 5 Write an algorithm to print all natural numbers up to „n‟.+9 Step 1: Start Step 2: Take any number and store it in n. Step 3: Store 1 in I Step 4: Check I value, if I<=n then go to step 5 else go to step 8 Step 5: Print I Step 6: Increment I value by 1 Step 5: Go to step 4 Step 8: Stop In the above example, steps 4, 5, 6 and 7 are executed more than one time. -Fin-ite and Infinite loop
  • 6. -In looping statements, if some set of statements are executed „n‟ times (fixed number of times), then it is called “finite loop”. -At the same time, if some set of statements are executed again and again without any end (infinite times), then it is called “infinite loop”. + Note: Set of statements is executed again and again without any end is called infinite loop. Flowchart -we have learnt to write algorithms, i.e. step-by step process of solving a problem. -We can also show these steps in graphical form by using some symbols. NB: Flowchart is the graphical representation of an algorithm -This is called flowcharting Problem solving • Step 1: – Clearly specify the problem to be solved. • Step 2: – Draw flowchart or write algorithm.
  • 7. • Step 3: Dept. of CSE, IIT KGP – Convert flowchart (algorithm) into program code. • Step 4: – Compile the program into object code. • Step 5: – Execute the program Flowchart Symbols: