SlideShare a Scribd company logo
1 of 32
Algorithm Design and
Problem Solving
Kaavya gaur
Introduction
In order to build a computer system that performs a
specific task or solves a given problem, the task or
problem has to be clearly defined, showing what is
going to be computed and how it is going to be
computed.
This chapter introduces the tools and techniques that
are used to design a software solution that together
with the associated computer hardware will form a
computer system.
What is a computer system?
• A COMPUTER SYSTEM is made up of software, data, hardware, communications
and people.
• each computer system can be divided up into a set of sub-systems. Each subsystem
can be further divided into sub-systems and so on until each sub-system just
performs a single action.
For example, when I wake up in the morning I use an app on my smart phone for my alarm, I then check the
weather forecast on my computer before I drive to work.
The alarm program is a very small computer system; when I check the weather forecast I
obtain information from one of the largest computer systems in the world
Activity
• Identify at least five computer systems you frequently use in your daily life.
See if you can decide the size of each system.
Tools and techniques
• In order to understand how a computer system is built up and how it works,
it is often divided up into sub-systems.
• This division can be shown using :
 Top-down design
 Sub-system
 Sub-routine
 Flowcharts or pseudocode
Top-down design
• TOP-DOWN DESIGN is the breaking down
of a computer system into a set of
subsystems, then breaking each sub-system
down into a set of smaller sub-systems, until
each sub-system just performs a single action.
• The process of breaking down into smaller
sub-systems is called ‘stepwise refinement’.
Structure diagrams
• The STRUCTURE DIAGRAM shows the design of a computer system in a
hierarchical way, with each level giving a more detailed breakdown of the
system into sub-systems.
• For eg : Alarm app for a smart phone
Structure diagram for alarm app
Flowcharts
Flowchart for checking-for-the-alarm-time sub-system
This symbol
means this
process is defined
elsewhere.
flowchart for the algorithm
to calculate the cost of
buying a given number of
tickets.
Library routines and Sub-routines
• A LIBRARY ROUTINE is a set of programming instructions for a given
task that is already available for use. It is pre-tested and usually performs a
task that is frequently required. For example, the task ‘get time’ in the
checking-for-the-alarm time algorithm would probably be readily available as
a library routine.
• A SUB-ROUTINE is a set of programming instructions for a given task
that forms a sub system, not the whole system. Sub-routines written in high-
level programming languages are called ‘procedures’ or ‘functions’ depending
on how they are used.
HOW TO WRITE PSEUDOCODE
• Always capitalize the initial word (often one of the main six constructs). (READ, WRITE, IF,
WHILE, UNTIL).
• Make only one statement per line.
• Indent to show hierarchy, improve readability, and show nested constructs.
• Always end multi-line sections using any of the END keywords (ENDIF, ENDWHILE, etc.).
• Keep your statements programming language independent.
• Use the naming domain of the problem, not that of the implementation. For instance: “Append
the last name to the first name” instead of “name = first+ last.”
• Keep it simple, concise and readable.
THE MAIN CONSTRUCTS OF
PSEUDOCODE
• SEQUENCE represents linear tasks sequentially performed one after the
other.
• WHILE a loop with a condition at its beginning.
• REPEAT-UNTIL a loop with a condition at the bottom.
• FOR another way of looping.
• IF-THEN-ELSE a conditional statement changing the flow of the
algorithm.
Conditional statements
• A condition that can be true or false:
IF … THEN … ELSE … ENDIF,
• for example
IF Age < 18
THEN PRINT "Child"
ELSE PRINT "Adult"
ENDIF
• A choice between several different values:
• CASE … OF … OTHERWISE … ENDCASE,
• for example:
CASE Grade OF
"A" : PRINT "Excellent"
"B" : PRINT "Good"
"C" : PRINT "Average”
OTHERWISE PRINT "Improvement is needed"
ENDCASE
Comparison operators
The algorithm below checks if a percentage mark is valid and a pass or a fail.
This makes use of two IF statements. The second IF statement is part of the
ELSE path of the first IF statement. This is called a nested IF.
Loop structures
FOR … TO … NEXT
REPEAT … UNTIL
• This loop structure is used
when the number of
repetitions/iterations is not
known and the actions are
repeated UNTIL a given
condition becomes true.
The actions in this loop are
always completed at least
once
WHILE … DO … ENDWHILE
• This loop structure is used when
the number of
repetitions/iterations is not
known and the actions are only
repeated WHILE a given
condition is true. If the WHILE
condition is untrue when the loop
is first entered then the actions in
the loop are never performed.
Pseudocode
• PSEUDOCODE is a simple method of showing an algorithm, using
English-like words and mathematical operators that are set out to look like a
program
Pseudocode for the
checking-for-the-
alarm-time
algorithm
Tickets are sold for a concert at $20
each. If 10 tickets are bought then the
discount is 10%; if 20 tickets are
bought the discount is 20%. No more
than 25 tickets can be bought in a single
transaction. a Use pseudocode to write
an algorithm to calculate the cost of
buying a given number of tickets.
• REPEAT
• PRINT "How many tickets would you like to buy?"
• INPUT NumberOfTickets
• UNTIL NumberOfTickets > 0 AND NumberOfTickets < 26
• IF NumberOfTickets < 10
• THEN Discount ← 0
• ELSE
• IF NumberOfTickets < 20
• THEN Discount ← 0.1
• ELSE Discount ← 0.2
• ENDIF
• ENDIF
• Cost ← NumberOfTickets * 20 * (1 – Discount)
• PRINT "Your tickets cost", Cost
Standard Method's of solution
• Totalling
• Counting
• Finding maximum , minimum and average values
• Searching using a linear search
Standard Method's of solution
• Variable Assignments
When devising an algorithm the programmer will need to use variables and assign values to them. This is indicated
in pseudocode using an arrow symbol (←). The arrow points from the value being assigned towards the variable it
is being assigned to. The following line of pseudocode should be read as 'a becomes equal to 34'.
a ← 34
• Totaling and Counting : The assignment operator can also be used when finding totals, as shown in the
following example where x becomes equal to a plus b.
x ← a + b
Similarly we can also use the assignment operator for counting, by assigning a variable to become equal to the value
of itself plus 1.
x ← x + 1
• Input and Output : Output is the act or returning some data to the user of
the program. This could be in the form of a written message, a numerical
value, an image, video or sound. This is shown in pseudocode by writing
OUTPUT followed by what the output will be. The example below shows
how we would output the message 'Hello World':
OUTPUT 'Hello World'
Read Number n and print the integers
counting upto n
BEGIN
READ n
INITIALIZE i to 1
FOR i <= n, then
DISPLAY i
INCREMENT i
END FOR
END
Psuedo code for finding max,min and average
marks from the class.
MaxMarks  StudentMarks[1]
MinMarks StudentMarks[1]
For Counter 2 TO ClassSize
IF StudentMarks[Counter] > MaxMArks
THEN
MaxMarks  StudentMarks[Counter]
End if
IF StudentMark[Counter] < MinMarks
THEN
MinMarks StudentMark[Counter]
ENDIF
NEXT Counter
Total  0
For Counter  1 TO ClassSize
Total  Total +
StudentMArks[Counter]
NEXT Counter
Average  Total / ClassSize
Pseudocode for linear search
OUTPUT: “Please enter name to find”
INPUT : Name
Found  FALSE
Counter  1
REPEAT
IF Name = StudentName[Counter]
THEN
Found  TRUE
ELSE
Counter  Counter + 1
ENDIF
UNTIL Found OR Counter > ClassSize
THEN
OUTPUT Name “ Found at
position”, Counter,” in the list.”
ELSE
OTPUT NAME ,’Not found”
ENDIF

More Related Content

What's hot (20)

What is identifier c programming
What is identifier c programmingWhat is identifier c programming
What is identifier c programming
 
Python introduction
Python introductionPython introduction
Python introduction
 
Kids computer-programming
Kids computer-programmingKids computer-programming
Kids computer-programming
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Beginning Python Programming
Beginning Python ProgrammingBeginning Python Programming
Beginning Python Programming
 
Python Data-Types
Python Data-TypesPython Data-Types
Python Data-Types
 
structured programming
structured programmingstructured programming
structured programming
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
1. over view and history of c
1. over view and history of c1. over view and history of c
1. over view and history of c
 
Open source operating systems
Open source operating systemsOpen source operating systems
Open source operating systems
 
Python basics
Python basicsPython basics
Python basics
 
Programming paradigm
Programming paradigmProgramming paradigm
Programming paradigm
 
Computer repair and maintenance
Computer repair and maintenanceComputer repair and maintenance
Computer repair and maintenance
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
Normal forms
Normal formsNormal forms
Normal forms
 

Similar to Algorithm Design and Problem Solving [Autosaved].pptx

Cse115 lecture03problemsolving
Cse115 lecture03problemsolvingCse115 lecture03problemsolving
Cse115 lecture03problemsolvingMd. Ashikur Rahman
 
Problem-solving and design 1.pptx
Problem-solving and design 1.pptxProblem-solving and design 1.pptx
Problem-solving and design 1.pptxTadiwaMawere
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programmingSangheethaa Sukumaran
 
Introduction to programming - class 2
Introduction to programming - class 2Introduction to programming - class 2
Introduction to programming - class 2Paul Brebner
 
Unit 2 - Complete (1).pptx
Unit 2 - Complete (1).pptxUnit 2 - Complete (1).pptx
Unit 2 - Complete (1).pptxgogulram2
 
lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptSourabhPal46
 
lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptMard Geer
 
classVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxclassVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxssusere336f4
 
02 Algorithms and flowcharts - computers.pptx
02 Algorithms and flowcharts - computers.pptx02 Algorithms and flowcharts - computers.pptx
02 Algorithms and flowcharts - computers.pptxarifaqazi2
 
Problem solving and design
Problem solving and designProblem solving and design
Problem solving and designzahid785
 
Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Amr Alaa El Deen
 
Algorithm and C code related to data structure
Algorithm and C code related to data structureAlgorithm and C code related to data structure
Algorithm and C code related to data structureSelf-Employed
 
Lec-ProblemSolving.pptx
Lec-ProblemSolving.pptxLec-ProblemSolving.pptx
Lec-ProblemSolving.pptxmiansaad18
 
learn computer science.ppt
learn computer science.pptlearn computer science.ppt
learn computer science.pptfaithola1
 
Introduction to Problem Solving Techniques- Python
Introduction to Problem Solving Techniques- PythonIntroduction to Problem Solving Techniques- Python
Introduction to Problem Solving Techniques- PythonPriyankaC44
 

Similar to Algorithm Design and Problem Solving [Autosaved].pptx (20)

Qbasic notes
Qbasic notesQbasic notes
Qbasic notes
 
Cse115 lecture03problemsolving
Cse115 lecture03problemsolvingCse115 lecture03problemsolving
Cse115 lecture03problemsolving
 
Problem-solving and design 1.pptx
Problem-solving and design 1.pptxProblem-solving and design 1.pptx
Problem-solving and design 1.pptx
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
 
Introduction to programming - class 2
Introduction to programming - class 2Introduction to programming - class 2
Introduction to programming - class 2
 
Unit 2 - Complete (1).pptx
Unit 2 - Complete (1).pptxUnit 2 - Complete (1).pptx
Unit 2 - Complete (1).pptx
 
lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.ppt
 
lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.ppt
 
classVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxclassVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptx
 
02 Algorithms and flowcharts - computers.pptx
02 Algorithms and flowcharts - computers.pptx02 Algorithms and flowcharts - computers.pptx
02 Algorithms and flowcharts - computers.pptx
 
Flowcharting week 5 2019 2020
Flowcharting week 5  2019  2020Flowcharting week 5  2019  2020
Flowcharting week 5 2019 2020
 
Problem solving and design
Problem solving and designProblem solving and design
Problem solving and design
 
Flow charts week 5 2020 2021
Flow charts week 5 2020  2021Flow charts week 5 2020  2021
Flow charts week 5 2020 2021
 
Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1
 
Small Basic - Branching and Loop
Small Basic - Branching and LoopSmall Basic - Branching and Loop
Small Basic - Branching and Loop
 
Algorithm and C code related to data structure
Algorithm and C code related to data structureAlgorithm and C code related to data structure
Algorithm and C code related to data structure
 
Lec-ProblemSolving.pptx
Lec-ProblemSolving.pptxLec-ProblemSolving.pptx
Lec-ProblemSolving.pptx
 
programming.ppt
programming.pptprogramming.ppt
programming.ppt
 
learn computer science.ppt
learn computer science.pptlearn computer science.ppt
learn computer science.ppt
 
Introduction to Problem Solving Techniques- Python
Introduction to Problem Solving Techniques- PythonIntroduction to Problem Solving Techniques- Python
Introduction to Problem Solving Techniques- Python
 

Recently uploaded

Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 

Recently uploaded (20)

Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 

Algorithm Design and Problem Solving [Autosaved].pptx

  • 1. Algorithm Design and Problem Solving Kaavya gaur
  • 2. Introduction In order to build a computer system that performs a specific task or solves a given problem, the task or problem has to be clearly defined, showing what is going to be computed and how it is going to be computed. This chapter introduces the tools and techniques that are used to design a software solution that together with the associated computer hardware will form a computer system.
  • 3. What is a computer system? • A COMPUTER SYSTEM is made up of software, data, hardware, communications and people. • each computer system can be divided up into a set of sub-systems. Each subsystem can be further divided into sub-systems and so on until each sub-system just performs a single action.
  • 4. For example, when I wake up in the morning I use an app on my smart phone for my alarm, I then check the weather forecast on my computer before I drive to work. The alarm program is a very small computer system; when I check the weather forecast I obtain information from one of the largest computer systems in the world
  • 5. Activity • Identify at least five computer systems you frequently use in your daily life. See if you can decide the size of each system.
  • 6. Tools and techniques • In order to understand how a computer system is built up and how it works, it is often divided up into sub-systems. • This division can be shown using :  Top-down design  Sub-system  Sub-routine  Flowcharts or pseudocode
  • 7. Top-down design • TOP-DOWN DESIGN is the breaking down of a computer system into a set of subsystems, then breaking each sub-system down into a set of smaller sub-systems, until each sub-system just performs a single action. • The process of breaking down into smaller sub-systems is called ‘stepwise refinement’.
  • 8. Structure diagrams • The STRUCTURE DIAGRAM shows the design of a computer system in a hierarchical way, with each level giving a more detailed breakdown of the system into sub-systems. • For eg : Alarm app for a smart phone
  • 11.
  • 12. Flowchart for checking-for-the-alarm-time sub-system This symbol means this process is defined elsewhere.
  • 13. flowchart for the algorithm to calculate the cost of buying a given number of tickets.
  • 14. Library routines and Sub-routines • A LIBRARY ROUTINE is a set of programming instructions for a given task that is already available for use. It is pre-tested and usually performs a task that is frequently required. For example, the task ‘get time’ in the checking-for-the-alarm time algorithm would probably be readily available as a library routine. • A SUB-ROUTINE is a set of programming instructions for a given task that forms a sub system, not the whole system. Sub-routines written in high- level programming languages are called ‘procedures’ or ‘functions’ depending on how they are used.
  • 15. HOW TO WRITE PSEUDOCODE • Always capitalize the initial word (often one of the main six constructs). (READ, WRITE, IF, WHILE, UNTIL). • Make only one statement per line. • Indent to show hierarchy, improve readability, and show nested constructs. • Always end multi-line sections using any of the END keywords (ENDIF, ENDWHILE, etc.). • Keep your statements programming language independent. • Use the naming domain of the problem, not that of the implementation. For instance: “Append the last name to the first name” instead of “name = first+ last.” • Keep it simple, concise and readable.
  • 16. THE MAIN CONSTRUCTS OF PSEUDOCODE • SEQUENCE represents linear tasks sequentially performed one after the other. • WHILE a loop with a condition at its beginning. • REPEAT-UNTIL a loop with a condition at the bottom. • FOR another way of looping. • IF-THEN-ELSE a conditional statement changing the flow of the algorithm.
  • 17. Conditional statements • A condition that can be true or false: IF … THEN … ELSE … ENDIF, • for example IF Age < 18 THEN PRINT "Child" ELSE PRINT "Adult" ENDIF
  • 18. • A choice between several different values: • CASE … OF … OTHERWISE … ENDCASE, • for example: CASE Grade OF "A" : PRINT "Excellent" "B" : PRINT "Good" "C" : PRINT "Average” OTHERWISE PRINT "Improvement is needed" ENDCASE
  • 20. The algorithm below checks if a percentage mark is valid and a pass or a fail. This makes use of two IF statements. The second IF statement is part of the ELSE path of the first IF statement. This is called a nested IF.
  • 22. FOR … TO … NEXT
  • 23. REPEAT … UNTIL • This loop structure is used when the number of repetitions/iterations is not known and the actions are repeated UNTIL a given condition becomes true. The actions in this loop are always completed at least once
  • 24. WHILE … DO … ENDWHILE • This loop structure is used when the number of repetitions/iterations is not known and the actions are only repeated WHILE a given condition is true. If the WHILE condition is untrue when the loop is first entered then the actions in the loop are never performed.
  • 25. Pseudocode • PSEUDOCODE is a simple method of showing an algorithm, using English-like words and mathematical operators that are set out to look like a program Pseudocode for the checking-for-the- alarm-time algorithm
  • 26. Tickets are sold for a concert at $20 each. If 10 tickets are bought then the discount is 10%; if 20 tickets are bought the discount is 20%. No more than 25 tickets can be bought in a single transaction. a Use pseudocode to write an algorithm to calculate the cost of buying a given number of tickets. • REPEAT • PRINT "How many tickets would you like to buy?" • INPUT NumberOfTickets • UNTIL NumberOfTickets > 0 AND NumberOfTickets < 26 • IF NumberOfTickets < 10 • THEN Discount ← 0 • ELSE • IF NumberOfTickets < 20 • THEN Discount ← 0.1 • ELSE Discount ← 0.2 • ENDIF • ENDIF • Cost ← NumberOfTickets * 20 * (1 – Discount) • PRINT "Your tickets cost", Cost
  • 27. Standard Method's of solution • Totalling • Counting • Finding maximum , minimum and average values • Searching using a linear search
  • 28. Standard Method's of solution • Variable Assignments When devising an algorithm the programmer will need to use variables and assign values to them. This is indicated in pseudocode using an arrow symbol (←). The arrow points from the value being assigned towards the variable it is being assigned to. The following line of pseudocode should be read as 'a becomes equal to 34'. a ← 34 • Totaling and Counting : The assignment operator can also be used when finding totals, as shown in the following example where x becomes equal to a plus b. x ← a + b Similarly we can also use the assignment operator for counting, by assigning a variable to become equal to the value of itself plus 1. x ← x + 1
  • 29. • Input and Output : Output is the act or returning some data to the user of the program. This could be in the form of a written message, a numerical value, an image, video or sound. This is shown in pseudocode by writing OUTPUT followed by what the output will be. The example below shows how we would output the message 'Hello World': OUTPUT 'Hello World'
  • 30. Read Number n and print the integers counting upto n BEGIN READ n INITIALIZE i to 1 FOR i <= n, then DISPLAY i INCREMENT i END FOR END
  • 31. Psuedo code for finding max,min and average marks from the class. MaxMarks  StudentMarks[1] MinMarks StudentMarks[1] For Counter 2 TO ClassSize IF StudentMarks[Counter] > MaxMArks THEN MaxMarks  StudentMarks[Counter] End if IF StudentMark[Counter] < MinMarks THEN MinMarks StudentMark[Counter] ENDIF NEXT Counter Total  0 For Counter  1 TO ClassSize Total  Total + StudentMArks[Counter] NEXT Counter Average  Total / ClassSize
  • 32. Pseudocode for linear search OUTPUT: “Please enter name to find” INPUT : Name Found  FALSE Counter  1 REPEAT IF Name = StudentName[Counter] THEN Found  TRUE ELSE Counter  Counter + 1 ENDIF UNTIL Found OR Counter > ClassSize THEN OUTPUT Name “ Found at position”, Counter,” in the list.” ELSE OTPUT NAME ,’Not found” ENDIF