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

What's hot

Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3Akshay Nagpurkar
 
Pseudocode flowcharts
Pseudocode flowchartsPseudocode flowcharts
Pseudocode flowchartsnicky_walters
 
Network software n othr types of software
Network software n othr types of software Network software n othr types of software
Network software n othr types of software Dhani Ahmad
 
Compiler design important questions
Compiler design   important questionsCompiler design   important questions
Compiler design important questionsakila viji
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Dr. Pankaj Agarwal
 
CS9222 Advanced Operating System
CS9222 Advanced Operating SystemCS9222 Advanced Operating System
CS9222 Advanced Operating SystemKathirvel Ayyaswamy
 
Programming fundamentals lecture 1 0f c
Programming fundamentals lecture 1 0f cProgramming fundamentals lecture 1 0f c
Programming fundamentals lecture 1 0f cRaja Hamid
 
Computer introduction
Computer introduction Computer introduction
Computer introduction mariasukhera
 
Data Structures - Lecture 1 [introduction]
Data Structures - Lecture 1 [introduction]Data Structures - Lecture 1 [introduction]
Data Structures - Lecture 1 [introduction]Muhammad Hammad Waseem
 
Proper Keyboarding Technique
Proper Keyboarding TechniqueProper Keyboarding Technique
Proper Keyboarding Techniquebrodeel
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programmingChaffey College
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming conceptssalmankhan570
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming languageVasavi College of Engg
 

What's hot (20)

Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3
 
Pseudocode flowcharts
Pseudocode flowchartsPseudocode flowcharts
Pseudocode flowcharts
 
Network software n othr types of software
Network software n othr types of software Network software n othr types of software
Network software n othr types of software
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Compiler design important questions
Compiler design   important questionsCompiler design   important questions
Compiler design important questions
 
Memory Forensics
Memory ForensicsMemory Forensics
Memory Forensics
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis
 
DAA Introduction to Algorithms & Application
DAA Introduction to Algorithms & ApplicationDAA Introduction to Algorithms & Application
DAA Introduction to Algorithms & Application
 
CS9222 Advanced Operating System
CS9222 Advanced Operating SystemCS9222 Advanced Operating System
CS9222 Advanced Operating System
 
Web technology
Web technologyWeb technology
Web technology
 
Programming fundamentals lecture 1 0f c
Programming fundamentals lecture 1 0f cProgramming fundamentals lecture 1 0f c
Programming fundamentals lecture 1 0f c
 
Computer introduction
Computer introduction Computer introduction
Computer introduction
 
Data Structures - Lecture 1 [introduction]
Data Structures - Lecture 1 [introduction]Data Structures - Lecture 1 [introduction]
Data Structures - Lecture 1 [introduction]
 
System software
System softwareSystem software
System software
 
Proper Keyboarding Technique
Proper Keyboarding TechniqueProper Keyboarding Technique
Proper Keyboarding Technique
 
Introduction to Algorithm
Introduction to AlgorithmIntroduction to Algorithm
Introduction to Algorithm
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programming
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming concepts
 
Computer Programming
Computer ProgrammingComputer Programming
Computer Programming
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming language
 

Similar to Algorithm design and problem solving

Basics of Algorithm Unit 1 part 1 algorithm
Basics of Algorithm Unit 1 part 1  algorithmBasics of Algorithm Unit 1 part 1  algorithm
Basics of Algorithm Unit 1 part 1 algorithmJIMS LAJPAT NAGAR
 
Module 2_Conditional Statements.pptx
Module 2_Conditional Statements.pptxModule 2_Conditional Statements.pptx
Module 2_Conditional Statements.pptxssuser47f7f2
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithmrajkumar1631010038
 
Nassi Shneiderman Diagrams: Algorithms Made Easier (at least a little bit)
Nassi Shneiderman Diagrams: Algorithms Made Easier (at least a little bit)Nassi Shneiderman Diagrams: Algorithms Made Easier (at least a little bit)
Nassi Shneiderman Diagrams: Algorithms Made Easier (at least a little bit)Richard Schwarz
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)praveena p
 
Programming aids- Algorithm, Flowchart, Pseudocodes and Decision table
Programming aids- Algorithm, Flowchart, Pseudocodes and Decision tableProgramming aids- Algorithm, Flowchart, Pseudocodes and Decision table
Programming aids- Algorithm, Flowchart, Pseudocodes and Decision tableAnjali Technosoft
 
Nassi shneiderman diagrams
Nassi shneiderman diagramsNassi shneiderman diagrams
Nassi shneiderman diagramshccit
 
01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptxssuser586772
 
more loops lecture by Professor Evan korth
more loops  lecture by Professor Evan korth more loops  lecture by Professor Evan korth
more loops lecture by Professor Evan korth hammad ali
 
White boxvsblackbox
White boxvsblackboxWhite boxvsblackbox
White boxvsblackboxsanerjjd
 
Lecture 6.1 flow control selection
Lecture 6.1  flow control selectionLecture 6.1  flow control selection
Lecture 6.1 flow control selectionalvin567
 

Similar to Algorithm design and problem solving (20)

UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Introducing Scratch
Introducing ScratchIntroducing Scratch
Introducing Scratch
 
03b loops
03b   loops03b   loops
03b loops
 
Lesson 3
Lesson 3Lesson 3
Lesson 3
 
Basics of Algorithm Unit 1 part 1 algorithm
Basics of Algorithm Unit 1 part 1  algorithmBasics of Algorithm Unit 1 part 1  algorithm
Basics of Algorithm Unit 1 part 1 algorithm
 
Module 2_Conditional Statements.pptx
Module 2_Conditional Statements.pptxModule 2_Conditional Statements.pptx
Module 2_Conditional Statements.pptx
 
Java chapter 3
Java chapter 3Java chapter 3
Java chapter 3
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithm
 
Lect 3-4 Zaheer Abbas
Lect 3-4 Zaheer AbbasLect 3-4 Zaheer Abbas
Lect 3-4 Zaheer Abbas
 
Nassi Shneiderman Diagrams: Algorithms Made Easier (at least a little bit)
Nassi Shneiderman Diagrams: Algorithms Made Easier (at least a little bit)Nassi Shneiderman Diagrams: Algorithms Made Easier (at least a little bit)
Nassi Shneiderman Diagrams: Algorithms Made Easier (at least a little bit)
 
Looping
LoopingLooping
Looping
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)
 
Programming aids- Algorithm, Flowchart, Pseudocodes and Decision table
Programming aids- Algorithm, Flowchart, Pseudocodes and Decision tableProgramming aids- Algorithm, Flowchart, Pseudocodes and Decision table
Programming aids- Algorithm, Flowchart, Pseudocodes and Decision table
 
Nassi shneiderman diagrams
Nassi shneiderman diagramsNassi shneiderman diagrams
Nassi shneiderman diagrams
 
01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx
 
more loops lecture by Professor Evan korth
more loops  lecture by Professor Evan korth more loops  lecture by Professor Evan korth
more loops lecture by Professor Evan korth
 
GE8151 notes pdf.pdf
GE8151 notes pdf.pdfGE8151 notes pdf.pdf
GE8151 notes pdf.pdf
 
White boxvsblackbox
White boxvsblackboxWhite boxvsblackbox
White boxvsblackbox
 
Lecture 6.1 flow control selection
Lecture 6.1  flow control selectionLecture 6.1  flow control selection
Lecture 6.1 flow control selection
 

Recently uploaded

Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 

Recently uploaded (20)

Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 

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: