SlideShare uma empresa Scribd logo
1 de 31
What?
A set of Step by Step Instructions that provide a solution to a problem
Algorithm
”a finite sequence of well-defined, computer-implementable instructions”
- Wiki
“An algorithm is any well-defined computational procedure that takes some
value, or set of values, as input and produces some value, or set of values,
as output”
-Coreman
Characteristics
• Step By Step
• Un-Ambiguous
• Finite
• Feasible
• Independent
modular way means to break a complex problem in smaller problem (modules)
Advantage:
Easy to Plan
Easy to implement
Easy to understand
Easy to debug (find errors)
Easy to Test
It is important to –
plan a pathway to solve problems before implementing solutions
And
To solve such problem in modular way
This can be done using ALGORITHMS
Algorithm
INPUT OUTPUT
Question : This is a program/process also do. Then What is the Difference?
Program
INPUT OUTPUT
Process
INPUT OUTPUT
During
Planning
During
Compilation
During
Runtime
Written in
Natural Language
Written in
Programming
Language
Written in Binary
Language
Algorithm
in a general language that is easily understandable
Natural Language like English
It is a convention to use Pseudo code or Flow Charts etc.
can be written in
Diagrammatic Representation
Symbolic Instruction
8/14/2020 5
An algorithm is a sequence of unambiguous instructions for solving a problem,
i.e., for obtaining a required output for any legitimate input in a finite amount of
time.
Problem
Algorithm
Program
Input Output
8/14/2020 6
• The non ambiguity requirement for each step of an algorithm cannot be
compromised.
• The range of inputs for which an algorithm works has to be specified carefully.
• The same algorithm can be represented in several different ways.
• There may exist several algorithms for solving the same problem.
Algorithms for the same problem can be based on very different ideas and can
solve the problem with dramatically different speeds.
One Problem Many Solution
Start
1. Visit Website
2. Select Brand
3. Select Model
4. Internet Banking
End
Algorithm Name: Buy_new_TV (Brand, Model)
Input: Company name as TV Brand, Model No as Model
Output: You are a proud owner of a TV
Start
1. Visit Website
2. Select Brand
3. Select Model
4. Credit Card
End
Start
1. Visit Website
2. Select Brand
3. Select Model
4. Debit Card
End
8/14/2020 8
Problem
Algo 6
Algo 1
Algo 2
Algo 3
Algo 4
Algo 5
One Problem Many Algorithms
How to Choose Best suitable Algorithm for our problem?
Algorithm Analysis
Priori Analysis Posterior Analysis
Before actually using algorithm After actually using algorithm
Theoretical Practical
Advantage:
Fast
No extra Resources required
Disadvantage:
Based on assumptions
Advantage:
Accurate and Actual
Disadvantage:
Implementation of all algorithms
is an overhead
Empirical
Experimental
Implementation-> not Required Implementation -> Required
8/14/2020 10
Algorithm Analysis
Space Complexity Analysis Time Complexity Analysis
How much Space Required? How much Time Required?
Space Complexity (Algorithm A) =
Space Complexity (Compile Time) + Space Complexity (Run Time)
Constant (c)
SC(A) = c + SC (I)
• Variables
•Objects
• Dynamic Memory allocated
Time Complexity (Algorithm A) =
Time taken by one operation * No. of operations
8/14/2020 11
ALGO 1
Problem
ALGO 2
ALGO 3
ALGO 4
Priori Analysis / Theoretical Analysis
……………….
……………….
……………….
Algo1
……………….
……………….
……………….
Algo2
……………….
……………….
……………….
Algo3
……………….
……………….
……………….
Algo4
SC …..
TC …..
SC …..
TC …..
SC …..
TC …..
SC …..
TC
8/14/2020 12
ALGO 1
ALGO
2
ALGO 3
ALGO
4
Program 1
Program
2
Program
4
Program 3
Run
Run
Run
Run
Posterior Analysis
/ Empirical Analysis
/ Experimental Analysis
8/14/2020 13
ALGO 2
Posterior Analysis
/ Empirical Analysis
/ Experimental Analysis
PROBLEMS
Platform Dependency
Program 1
Run
SC …..
TC …..
SC …..
TC …..
32 BITS 64 BITS
8/14/2020 14
8/14/2020 15
ALGO 2
Posterior Analysis
/ Empirical Analysis
/ Experimental Analysis
PROBLEMS
OS Dependency
Program 1
Run
SC …..
TC …..
SC …..
TC …..
SC …..
TC …..
SC …..
TC …..
SC …..
TC …..
8/14/2020 16
ALGO 2
Posterior Analysis
/ Empirical Analysis
/ Experimental Analysis
PROBLEMS
Language Dependency
Program 1
Run
SC …..
TC …..
SC …..
TC …..
SC …..
TC …..
SC …..
TC …..
SC …..
TC …..
8/14/2020 17
8/14/2020 18
ALGORITHM
INPUT OUTPUT
+
10
30
20
+
Hello
Hello World
World
One Algorithm Many Instances
8/14/2020 19
ALGORITHM
INPUT OUTPUT
An input to an algorithm specifies an instance of the problem the algorithm solves
It is very important to specify exactly the set of instances the algorithm
needs to handle.
8/14/2020 20
8/14/2020 21
8/14/2020 22
Understanding the Problem Completely
First Step before designing an algorithm
• Read the problem’s description carefully
• Ask questions if you have any doubts about the problem
• Do a few small examples by hand
• think about special cases
If you fail to do this, your algorithm may work correctly for a majority of inputs
but crash on some “boundary” values.
Remember that-
“A correct algorithm is not one that works most of the time,
but one that works correctly for all legitimate inputs”
8/14/2020 23
Ascertaining the Capabilities of the Computational Device
The vast majority of algorithms in use today are still destined to be programmed
for a computer closely resembling –
“von Neumann machine”—a computer architecture outlined by the prominent
Hungarian-American mathematician John von Neumann (1903–1957), in
collaboration with A. Burks and H. Goldstine, in 1946.
Based on Random-access machine (RAM)
Its central assumption is that instructions are executed one after another, one operation
at a time. Accordingly, algorithms designed to be executed on such machines are called
sequential algorithms.
1. ***************
2. ***************
3. ***************
4. ***************
8/14/2020 24
The central assumption of the RAM model does not hold for some newer computers
that can execute operations concurrently, i.e., in parallel. Algorithms that take
advantage of this capability are called parallel algorithms.
1. ***************
2. ***************
3. ***************
4. ***************
8/14/2020 25
Choosing between Exact and Approximate Problem Solving
The next principal decision is to choose between –
Solving the problem exactly - an Exact Algorithm
Solving the problem approximately - Approximation Algorithm
First, there are important problems that simply cannot be solved exactly for most
of their instances
Extracting Square Roots
Solving Nonlinear Equations
Evaluating Definite Integrals
Second, available algorithms for solving a problem exactly can be unacceptably
slow because of the problem’s intrinsic complexity.
Why Approximate Algorithms?
8/14/2020 26
Algorithm Design Techniques
An algorithm design technique (or “strategy” or “paradigm”) is a general
approach to solving problems algorithmically that is applicable to a variety of
problems from different areas of computing.
Learning these techniques is of utmost importance for the following reason-
They provide guidance for designing algorithms for new problems, i.e., problems
for which there is no known satisfactory algorithm.
Branch and Bound Algorithms
Greedy Algorithms
Divide and Concur
8/14/2020 27
Designing an Algorithm and Data Structures
One should pay close attention to choosing data structures appropriate for the
operations performed by the algorithm
Algorithms + Data Structures = Programs
Wirth, N. Algorithms + Data Structures = Programs. Prentice-Hall, Englewood Cliffs,
NJ, 1976.
Methods of Specifying an Algorithm
Pseudo code
flowchart
8/14/2020 28
Proving an Algorithm’s Correctness
CORRECTNESS
The algorithm yields a required result for every legitimate input in a finite amount of time
Mathematical Induction
“It might be worth mentioning that although tracing the algorithm’s performance for a
few specific inputs can be a very worthwhile activity, it cannot prove the algorithm’s
correctness conclusively
But in order to show that an algorithm is incorrect, you need just one instance of its
input for which the algorithm fails”
8/14/2020 29
Analyzing an Algorithm
Efficiency
There are two kinds of algorithm efficiency:
Time Efficiency: indicating how fast the algorithm runs
Space efficiency: indicating how much extra memory it uses
Simplicity Generality
8/14/2020 30
Coding an Algorithm
Standard Tricks for Code Tuning –
Computing a loop’s invariant outside the loop
Collecting common sub expressions
Replacing expensive operations by cheap ones, and so on
An inefficient implementation can diminish your algorithm’s power
Compilers do provide “Code Optimization”
Kernighan, B.W. and Pike. R. The Practice of Programming. Addison-Wesley, 1999.
Bentley, J. Programming Pearls, 2nd ed. Addison-Wesley, 2000.
8/14/2020 31
Fundamentals of the Analysis of Algorithm Efficiency
Not everything that can be counted counts, and not everything that counts
can be counted.
—Albert Einstein (1879–1955)

Mais conteúdo relacionado

Mais procurados

02 intel v_tune_session_02
02 intel v_tune_session_0202 intel v_tune_session_02
02 intel v_tune_session_02
Vivek chan
 
Aad introduction
Aad introductionAad introduction
Aad introduction
Mr SMAK
 

Mais procurados (19)

Introduction ,characteristics, properties,pseudo code conventions
Introduction ,characteristics, properties,pseudo code conventionsIntroduction ,characteristics, properties,pseudo code conventions
Introduction ,characteristics, properties,pseudo code conventions
 
Algorithm Design Presentation
Algorithm Design PresentationAlgorithm Design Presentation
Algorithm Design Presentation
 
02 intel v_tune_session_02
02 intel v_tune_session_0202 intel v_tune_session_02
02 intel v_tune_session_02
 
Algorithm and flowchart2010
Algorithm and flowchart2010Algorithm and flowchart2010
Algorithm and flowchart2010
 
Daa presentation 97
Daa presentation 97Daa presentation 97
Daa presentation 97
 
Presentation on LabVIEW Basics
Presentation on LabVIEW BasicsPresentation on LabVIEW Basics
Presentation on LabVIEW Basics
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Introduction To Algorithms
Introduction To AlgorithmsIntroduction To Algorithms
Introduction To Algorithms
 
algorithm
algorithmalgorithm
algorithm
 
Algorithm and pseudocode conventions
Algorithm and pseudocode conventionsAlgorithm and pseudocode conventions
Algorithm and pseudocode conventions
 
Graphical programming
Graphical programmingGraphical programming
Graphical programming
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer
 
Problem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to CProblem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to C
 
Review on 32 bit single precision Floating point unit (FPU) Based on IEEE 754...
Review on 32 bit single precision Floating point unit (FPU) Based on IEEE 754...Review on 32 bit single precision Floating point unit (FPU) Based on IEEE 754...
Review on 32 bit single precision Floating point unit (FPU) Based on IEEE 754...
 
Aad introduction
Aad introductionAad introduction
Aad introduction
 
Labview
Labview Labview
Labview
 
Labview material
Labview materialLabview material
Labview material
 
Week10 final
Week10 finalWeek10 final
Week10 final
 
Algorithms. Basic course
Algorithms. Basic courseAlgorithms. Basic course
Algorithms. Basic course
 

Semelhante a Ds03 part i algorithms by jyoti lakhani

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
ssuser586772
 
The Principle Of Ultrasound Imaging System
The Principle Of Ultrasound Imaging SystemThe Principle Of Ultrasound Imaging System
The Principle Of Ultrasound Imaging System
Melissa Luster
 

Semelhante a Ds03 part i algorithms by jyoti lakhani (20)

Ds03 algorithms jyoti lakhani
Ds03 algorithms jyoti lakhaniDs03 algorithms jyoti lakhani
Ds03 algorithms jyoti lakhani
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis
 
Algorithm.pdf
Algorithm.pdfAlgorithm.pdf
Algorithm.pdf
 
Algorithm - Introduction
Algorithm - IntroductionAlgorithm - Introduction
Algorithm - Introduction
 
unit 2 hpc.pptx
unit 2 hpc.pptxunit 2 hpc.pptx
unit 2 hpc.pptx
 
IRJET- New Generation Multilevel based Atm Security System
IRJET- New Generation Multilevel based Atm Security SystemIRJET- New Generation Multilevel based Atm Security System
IRJET- New Generation Multilevel based Atm Security System
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
 
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
 
AOA Week 01.ppt
AOA Week 01.pptAOA Week 01.ppt
AOA Week 01.ppt
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
 
Introduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.pptIntroduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.ppt
 
Chapter 09 design and analysis of algorithms
Chapter 09  design and analysis of algorithmsChapter 09  design and analysis of algorithms
Chapter 09 design and analysis of algorithms
 
Design & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptxDesign & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptx
 
Introduction to Algorithms Introduction to Algorithms.pptx
Introduction to Algorithms Introduction to Algorithms.pptxIntroduction to Algorithms Introduction to Algorithms.pptx
Introduction to Algorithms Introduction to Algorithms.pptx
 
The Principle Of Ultrasound Imaging System
The Principle Of Ultrasound Imaging SystemThe Principle Of Ultrasound Imaging System
The Principle Of Ultrasound Imaging System
 
11 Unit 1 Problem Solving Techniques
11  Unit 1 Problem Solving Techniques11  Unit 1 Problem Solving Techniques
11 Unit 1 Problem Solving Techniques
 
IRJET - New Generation Multilevel based Atm Security System
IRJET - New Generation Multilevel based Atm Security SystemIRJET - New Generation Multilevel based Atm Security System
IRJET - New Generation Multilevel based Atm Security System
 
Software Testing: Test Design and the Project Life Cycle
Software Testing: Test Design and the Project Life CycleSoftware Testing: Test Design and the Project Life Cycle
Software Testing: Test Design and the Project Life Cycle
 
Python algorithm
Python algorithmPython algorithm
Python algorithm
 

Mais de jyoti_lakhani

Ds06 linked list- insert a node after a given node
Ds06   linked list-  insert a node after a given nodeDs06   linked list-  insert a node after a given node
Ds06 linked list- insert a node after a given node
jyoti_lakhani
 
Ds01 data structure introduction - by jyoti lakhani
Ds01 data structure  introduction - by jyoti lakhaniDs01 data structure  introduction - by jyoti lakhani
Ds01 data structure introduction - by jyoti lakhani
jyoti_lakhani
 

Mais de jyoti_lakhani (20)

CG02 Computer Graphic Systems.ppsx
CG02 Computer Graphic Systems.ppsxCG02 Computer Graphic Systems.ppsx
CG02 Computer Graphic Systems.ppsx
 
Projections.pptx
Projections.pptxProjections.pptx
Projections.pptx
 
CG04 Color Models.ppsx
CG04 Color Models.ppsxCG04 Color Models.ppsx
CG04 Color Models.ppsx
 
CG03 Random Raster Scan displays and Color CRTs.ppsx
CG03 Random Raster Scan displays and Color CRTs.ppsxCG03 Random Raster Scan displays and Color CRTs.ppsx
CG03 Random Raster Scan displays and Color CRTs.ppsx
 
CG02 Computer Graphic Systems.pptx
CG02 Computer Graphic Systems.pptxCG02 Computer Graphic Systems.pptx
CG02 Computer Graphic Systems.pptx
 
CG01 introduction.ppsx
CG01 introduction.ppsxCG01 introduction.ppsx
CG01 introduction.ppsx
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
Double ended queue
Double ended queueDouble ended queue
Double ended queue
 
Tree terminology and introduction to binary tree
Tree terminology and introduction to binary treeTree terminology and introduction to binary tree
Tree terminology and introduction to binary tree
 
Priority queue
Priority queuePriority queue
Priority queue
 
Ds006 linked list- delete from front
Ds006   linked list- delete from frontDs006   linked list- delete from front
Ds006 linked list- delete from front
 
Ds06 linked list- insert a node after a given node
Ds06   linked list-  insert a node after a given nodeDs06   linked list-  insert a node after a given node
Ds06 linked list- insert a node after a given node
 
Ds06 linked list- insert a node at end
Ds06   linked list- insert a node at endDs06   linked list- insert a node at end
Ds06 linked list- insert a node at end
 
Ds06 linked list- insert a node at beginning
Ds06   linked list- insert a node at beginningDs06   linked list- insert a node at beginning
Ds06 linked list- insert a node at beginning
 
Ds06 linked list- intro and create a node
Ds06   linked list- intro and create a nodeDs06   linked list- intro and create a node
Ds06 linked list- intro and create a node
 
Ds04 abstract data types (adt) jyoti lakhani
Ds04 abstract data types (adt) jyoti lakhaniDs04 abstract data types (adt) jyoti lakhani
Ds04 abstract data types (adt) jyoti lakhani
 
Ds02 flow chart and pseudo code
Ds02 flow chart and pseudo codeDs02 flow chart and pseudo code
Ds02 flow chart and pseudo code
 
Ds01 data structure introduction - by jyoti lakhani
Ds01 data structure  introduction - by jyoti lakhaniDs01 data structure  introduction - by jyoti lakhani
Ds01 data structure introduction - by jyoti lakhani
 
Ids 016 cooperative intrusion detection
Ids 016 cooperative intrusion detectionIds 016 cooperative intrusion detection
Ids 016 cooperative intrusion detection
 
Ids 015 architecture and implementation of ids
Ids 015 architecture and implementation of idsIds 015 architecture and implementation of ids
Ids 015 architecture and implementation of ids
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Ds03 part i algorithms by jyoti lakhani

  • 1. What? A set of Step by Step Instructions that provide a solution to a problem Algorithm ”a finite sequence of well-defined, computer-implementable instructions” - Wiki “An algorithm is any well-defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values, as output” -Coreman Characteristics • Step By Step • Un-Ambiguous • Finite • Feasible • Independent
  • 2. modular way means to break a complex problem in smaller problem (modules) Advantage: Easy to Plan Easy to implement Easy to understand Easy to debug (find errors) Easy to Test It is important to – plan a pathway to solve problems before implementing solutions And To solve such problem in modular way This can be done using ALGORITHMS
  • 3. Algorithm INPUT OUTPUT Question : This is a program/process also do. Then What is the Difference? Program INPUT OUTPUT Process INPUT OUTPUT During Planning During Compilation During Runtime Written in Natural Language Written in Programming Language Written in Binary Language
  • 4. Algorithm in a general language that is easily understandable Natural Language like English It is a convention to use Pseudo code or Flow Charts etc. can be written in Diagrammatic Representation Symbolic Instruction
  • 5. 8/14/2020 5 An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate input in a finite amount of time. Problem Algorithm Program Input Output
  • 6. 8/14/2020 6 • The non ambiguity requirement for each step of an algorithm cannot be compromised. • The range of inputs for which an algorithm works has to be specified carefully. • The same algorithm can be represented in several different ways. • There may exist several algorithms for solving the same problem. Algorithms for the same problem can be based on very different ideas and can solve the problem with dramatically different speeds.
  • 7. One Problem Many Solution Start 1. Visit Website 2. Select Brand 3. Select Model 4. Internet Banking End Algorithm Name: Buy_new_TV (Brand, Model) Input: Company name as TV Brand, Model No as Model Output: You are a proud owner of a TV Start 1. Visit Website 2. Select Brand 3. Select Model 4. Credit Card End Start 1. Visit Website 2. Select Brand 3. Select Model 4. Debit Card End
  • 8. 8/14/2020 8 Problem Algo 6 Algo 1 Algo 2 Algo 3 Algo 4 Algo 5 One Problem Many Algorithms
  • 9. How to Choose Best suitable Algorithm for our problem? Algorithm Analysis Priori Analysis Posterior Analysis Before actually using algorithm After actually using algorithm Theoretical Practical Advantage: Fast No extra Resources required Disadvantage: Based on assumptions Advantage: Accurate and Actual Disadvantage: Implementation of all algorithms is an overhead Empirical Experimental Implementation-> not Required Implementation -> Required
  • 10. 8/14/2020 10 Algorithm Analysis Space Complexity Analysis Time Complexity Analysis How much Space Required? How much Time Required? Space Complexity (Algorithm A) = Space Complexity (Compile Time) + Space Complexity (Run Time) Constant (c) SC(A) = c + SC (I) • Variables •Objects • Dynamic Memory allocated Time Complexity (Algorithm A) = Time taken by one operation * No. of operations
  • 11. 8/14/2020 11 ALGO 1 Problem ALGO 2 ALGO 3 ALGO 4 Priori Analysis / Theoretical Analysis ………………. ………………. ………………. Algo1 ………………. ………………. ………………. Algo2 ………………. ………………. ………………. Algo3 ………………. ………………. ………………. Algo4 SC ….. TC ….. SC ….. TC ….. SC ….. TC ….. SC ….. TC
  • 12. 8/14/2020 12 ALGO 1 ALGO 2 ALGO 3 ALGO 4 Program 1 Program 2 Program 4 Program 3 Run Run Run Run Posterior Analysis / Empirical Analysis / Experimental Analysis
  • 13. 8/14/2020 13 ALGO 2 Posterior Analysis / Empirical Analysis / Experimental Analysis PROBLEMS Platform Dependency Program 1 Run SC ….. TC ….. SC ….. TC ….. 32 BITS 64 BITS
  • 15. 8/14/2020 15 ALGO 2 Posterior Analysis / Empirical Analysis / Experimental Analysis PROBLEMS OS Dependency Program 1 Run SC ….. TC ….. SC ….. TC ….. SC ….. TC ….. SC ….. TC ….. SC ….. TC …..
  • 16. 8/14/2020 16 ALGO 2 Posterior Analysis / Empirical Analysis / Experimental Analysis PROBLEMS Language Dependency Program 1 Run SC ….. TC ….. SC ….. TC ….. SC ….. TC ….. SC ….. TC ….. SC ….. TC …..
  • 18. 8/14/2020 18 ALGORITHM INPUT OUTPUT + 10 30 20 + Hello Hello World World One Algorithm Many Instances
  • 19. 8/14/2020 19 ALGORITHM INPUT OUTPUT An input to an algorithm specifies an instance of the problem the algorithm solves It is very important to specify exactly the set of instances the algorithm needs to handle.
  • 22. 8/14/2020 22 Understanding the Problem Completely First Step before designing an algorithm • Read the problem’s description carefully • Ask questions if you have any doubts about the problem • Do a few small examples by hand • think about special cases If you fail to do this, your algorithm may work correctly for a majority of inputs but crash on some “boundary” values. Remember that- “A correct algorithm is not one that works most of the time, but one that works correctly for all legitimate inputs”
  • 23. 8/14/2020 23 Ascertaining the Capabilities of the Computational Device The vast majority of algorithms in use today are still destined to be programmed for a computer closely resembling – “von Neumann machine”—a computer architecture outlined by the prominent Hungarian-American mathematician John von Neumann (1903–1957), in collaboration with A. Burks and H. Goldstine, in 1946. Based on Random-access machine (RAM) Its central assumption is that instructions are executed one after another, one operation at a time. Accordingly, algorithms designed to be executed on such machines are called sequential algorithms. 1. *************** 2. *************** 3. *************** 4. ***************
  • 24. 8/14/2020 24 The central assumption of the RAM model does not hold for some newer computers that can execute operations concurrently, i.e., in parallel. Algorithms that take advantage of this capability are called parallel algorithms. 1. *************** 2. *************** 3. *************** 4. ***************
  • 25. 8/14/2020 25 Choosing between Exact and Approximate Problem Solving The next principal decision is to choose between – Solving the problem exactly - an Exact Algorithm Solving the problem approximately - Approximation Algorithm First, there are important problems that simply cannot be solved exactly for most of their instances Extracting Square Roots Solving Nonlinear Equations Evaluating Definite Integrals Second, available algorithms for solving a problem exactly can be unacceptably slow because of the problem’s intrinsic complexity. Why Approximate Algorithms?
  • 26. 8/14/2020 26 Algorithm Design Techniques An algorithm design technique (or “strategy” or “paradigm”) is a general approach to solving problems algorithmically that is applicable to a variety of problems from different areas of computing. Learning these techniques is of utmost importance for the following reason- They provide guidance for designing algorithms for new problems, i.e., problems for which there is no known satisfactory algorithm. Branch and Bound Algorithms Greedy Algorithms Divide and Concur
  • 27. 8/14/2020 27 Designing an Algorithm and Data Structures One should pay close attention to choosing data structures appropriate for the operations performed by the algorithm Algorithms + Data Structures = Programs Wirth, N. Algorithms + Data Structures = Programs. Prentice-Hall, Englewood Cliffs, NJ, 1976. Methods of Specifying an Algorithm Pseudo code flowchart
  • 28. 8/14/2020 28 Proving an Algorithm’s Correctness CORRECTNESS The algorithm yields a required result for every legitimate input in a finite amount of time Mathematical Induction “It might be worth mentioning that although tracing the algorithm’s performance for a few specific inputs can be a very worthwhile activity, it cannot prove the algorithm’s correctness conclusively But in order to show that an algorithm is incorrect, you need just one instance of its input for which the algorithm fails”
  • 29. 8/14/2020 29 Analyzing an Algorithm Efficiency There are two kinds of algorithm efficiency: Time Efficiency: indicating how fast the algorithm runs Space efficiency: indicating how much extra memory it uses Simplicity Generality
  • 30. 8/14/2020 30 Coding an Algorithm Standard Tricks for Code Tuning – Computing a loop’s invariant outside the loop Collecting common sub expressions Replacing expensive operations by cheap ones, and so on An inefficient implementation can diminish your algorithm’s power Compilers do provide “Code Optimization” Kernighan, B.W. and Pike. R. The Practice of Programming. Addison-Wesley, 1999. Bentley, J. Programming Pearls, 2nd ed. Addison-Wesley, 2000.
  • 31. 8/14/2020 31 Fundamentals of the Analysis of Algorithm Efficiency Not everything that can be counted counts, and not everything that counts can be counted. —Albert Einstein (1879–1955)