SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Downloaden Sie, um offline zu lesen
UNITI INTRO
DUCTIO
N
19IS402 DESIGN & ANALYSIS OF
ALGORITHMS
Prepared by POORNIMA A
Discussion Outline
1.Overview of Algorithm Problem Solving
2.Fundamentals of Algorithm Problem
Solving Understanding the Problem
Decide on: computational means, exact vs.
approximate solving, algorithm design
technique
Designing an Algorithm
Prove Correctness
Analyze the Algorithm
Code the Algorithm
TODAY'S
DISCUSSIO
N
EXAMPLE1
AIRTRAVEL
Any Air travel connects several cities
Some Cities are connected by direct flights
Want to compute all pairs of cities connected by
sequence of flights
Example 1
: Air Travel
Observations
Paths
Representation of graph for manipulating it as a program with
suitable data structure
Design efficient algorithm
Efficiency
Number of cities (N) ; Number of direct flights (F)
Computing paths between N and F
Dependency
How much N and F values can be handled - Online booking
requries responses in seconds
EXAMPLE2 XERO
XSHO
P
1.When xerox shop to give some
job on schedule time (Project
report)
2.Any discounts
3.Brute force approach
4.Decomposition - Large problem
first and then smaller one next
(Includes recursion)
5.Based on some criteria - One with
number of pages, most related with
the deadline - Optimal solution
EXAMPLE2 XERO
XSHO
P
Variations
1.Types of machines (old or new)
2.Cost of ink and paper (Revenue)
3.Account for set up jobs
EXAMPLE3 DO
CUMENTSIMILARITY
1.Plagiarism detection
2.Changes in version of code
3.Web search queries more effectively
Measure of Similarity
Repeat of distance
Edit distance - How many changes we can make in
the document?
Add/ remove a letter - One change
Compute the minimum distance
EXAMPLE3 DO
CUMENTSIMILARITY
Variations
1.Only meaning of
words
2.Focus on words
EXAMPLE4
Write a program that meets the following assumption:
There is a point in the center of the screen.
In the right upper part of the screen, the program randomly draws
a geometrical figure (triangle, quadrilateral).
The player's task is to draw a figure in the lower left part of the
screen so that after turning 180 degrees it will cover as accurately
as possible with the figure drawn by the computer.
After decomposing the problem, we
get a set of sub-problems related to
the graphic part. These sub-problems
will not be more difficult
O
VERVIEWO
F
ALGORITHMIC
PRO
BLEMSO
LVING
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.
The notion of the algorithm
for w hich an
to be specified
1. The nonambiguity requirement for
each step of an algorithm cannot be
compromised.
2.The range of inputs
algorithm works has
carefully.
3.The same algorithm can be
represented in several different ways.
4.There may exist several algorithms for
solving the same problem.
5.Algorithms for the same problem
can be based on very different ideas
and can solve the problem with
dramatically different speeds.
Important Points
Clear and Unambiguous
clear and
clear in all
Well-Defined Inputs
If an algorithm says to take inputs, it
should be well-defined inputs.
Finiteness
The algorithm must be finite, i.e. it
should not end up in an infinite loops
or similar.
Language Independent
The Algorithm designed must be
language-independent hence it can
be implemented in any language, and
yet the output will be same, as
expected.
Algorithm should be
unambiguous.
Each steps should be
aspects and m ust give only one
meaning.
Well-Defined Outputs
The algorithm must clearly define what
output will be yielded and it should be
well-defined as w ell.
Feasible
The algorithm must be simple,
generic and practical, such that it can
be executed
It must not contain some future
technology
gcd(m, n) = gcd(n, m mod n)
where m mod n is the remainder of the division of m by n, until m mod n
is equal to 0.
For example,
gcd(60, 24) can be computed as follows:
gcd(60, 24)
= gcd(24, 12)
= gcd(12, 0)
= 12.
Euclid’s algorithm - Concept
Step 1
If n = 0, return the value of m as the answer and stop; otherwise,
proceed to Step 2.
Step 2
Divide m by n and assign the value of the remainder to r.
Step 3
Assign the value of n to m and the value of r to n. Go to Step 1.
Euclid’s algorithm for computing gcd(m, n)
ALGORITHM Euclid(m, n)
//Computes gcd(m, n) by Euclid’s algorithm
//Input: Two nonnegative, not-both-zero integers m and n
//Output: Greatest common divisor of m and n
while n ≠ 0 do
r ← m mod n
m← n
n← r
return m
Euclid’s algorithm - Pseudocode
In first method is based on the definition of GCD of m and n as the largest
integer that divides both numbers evenly.
Now Consider,
t = min{m, n}
1.If t divides both m and n then t is the answer
2.Else simply decrease the t by 1and try again
For example,
For numbers 60 and 24, the algorithm will try first 24, then 23, and so on,
until it reaches 1
2, where it stops.
Euclid’s algorithm - Method 2
Consecutive integer checking algorithm for computing gcd(m, n)
Step 1
Assign the value of min{m, n} to t.
Step 2
Divide m by t. If the remainder of this division is 0, go to Step 3;
otherwise, go to Step 4.
Step 3
Divide n by t. If the remainder of this division is 0, return the value of t as
the answer and stop; otherwise, proceed to Step 4.
Step 4
Decrease the value of t by 1
. Go to Step 2.
Euclid’s algorithm - Method 2
Middle-school procedure for computing gcd(m, n)
Step 1
Find the prime factors of m.
Step 2
Find the prime factors of n.
Step 3
Identify all the common factors in the two prime expansions found in Step
1and Step 2. (If p is a common factor occurring pm and pn times in m and
n, respectively, it should be repeated min{pm, pn } times.)
Step 4
Compute the product of all the common factors and return it as the
greatest common divisor of the numbers given.
Euclid’s algorithm - Method 3
Thus, for the numbers 60 and 24, we get
60 = 2 . 2 . 3 . 5
24 = 2 . 2 . 2 . 3
gcd(60, 24) = 2 . 2 . 3 = 1
2.
Euclid’s algorithm - Method 3
ADVANTAGES
O
F
AN
ALGO
RITHM
Algorithm is a step-wise
representation to a given problem -
easy to understand
An algorithm uses a definite
procedure
In Algorithm the problem is broken
down into smaller steps - easy to
convert it into an actual program.
It is not dependent on any
programming language - anyone
can understand
a logical sequence -
Every step is
easy to debug
DISADVANTAGES
O
F
AN
ALGO
RITHM
Writing an algorithm takes a long
time - time-consuming.
Branching and Looping
statements are difficult to show
in Algorithms.
Big tasks are difficult to put in
Algorithms
E X A M P LE 1:
Going to market to purchase a Pen
E X A M P LE 1:
Going to market to purchase a Pen
Step 1
: Prepare yourself to go to market
Step 2: Ckeck your wallet for money
Step 3: If there is no money in the
wallet, replenish it
Step 4: Go to the shop
Step 5: Ask for your favorite brand of
pen
Step 6: If pen is not available, go to
Step 7 else go to Step 1
0
Step 7: Give money to the shop keeper
Step 8: Keep the purchased pen safely
Step 9: Go back home
Step 10: Ask for any other brand of pen
Step 1
1
: Go to Step 7
FUNDAMENTALS
O
F ALGORITHMIC
PRO
BLEMSO
LVING
Before designing an algorithm is to understand completely the
problem given.
Read the problem’s description, do a few small examples by hand,
think about special cases, and ask questions again if needed.
For Computing applications we can use a known algorithm for solving
it.
To know its strengths and weaknesses, especially if you have to choose
among several available algorithms.
Will not find a readily available algorithm and will have to design your
own.
An input to an algorithm specifies an instance of the problem the
algorithm solves.
Very important to specify exactly the set of instances the algorithm
needs to handle.
If fails the algorithm may work correctly for a majority of inputs but
crash on some “boundary” value.
Correct algorithm is not one that works most of the time, but one that
works correctly for all legitimate inputs.
Algorithms in use today are still destined to be programmed for a
computer closely resembling the von Neumann machine
The essence of this architecture is captured by the so-called 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.
Exact algorithm
Always find the optimal solution to a given optimization problem.
Approximation algorithm
We can prove a bound on the ratio between the optimal solution and the
solution produced by the algorithm.
Important Points
1)There are important problems that cannot be solved exactly
Example:
Extracting square roots
Solving non linear equations
Evaluating definite integrals
2) Solving a problem exactly can be unacceptably slow because of problem's
a part of a more sophisticated
intrinsic complexity
3) An approximation algorithm can be
algorithm that solves a problem exactly
Some algorithms demand predicated on ingenious data structures
Data structures remain crucially important for both design and
analysis of algorithms
An design technique is a general approach to solving problems
algorithmically that is applicable to a variety of problems from different
areas of computing.
1.They provide guidance for designing algorithms for new problems,
i.e., problems for which there is no known satisfactory algorithm.
2.Algorithms are the cornerstone of computer science.
3.Make it possible to classify algorithms according to an underlying
design idea; therefore, they can serve as a natural way to both
categorize and study algorithms.
Natural Language:
Using a natural language has an obvious appeal;
However, the inherent ambiguity of any natural language makes a
succinct and clear description of algorithms surprisingly difficult.
Pseudocode:
Is a mixture of a natural language and programming language-like
constructs.
Pseudocode is usually more precise than natural language, and its
usage often yields more succinct algorithm descriptions.
Flowchart:
A method of expressing an algorithm by a collection of connected
geometric shapes containing descriptions of the algorithm’s steps.
Has proved to be inconvenient for all but very simple algorithms
Note:
Can be fed into an electronic computer directly
Have to prove that the algorithm yields a required result for every
legitimate input in a finite amount of time.
For Some algorithms, a proof of correctness is quite easy;
For others, it can be quite complex.
A common technique for proving correctness is to use mathematical
induction because an algorithm’s iterations provide a natural
sequence of steps needed for such proofs.
Even if algorithm fails for one input the algorithm has to be redesign
Approximation algorithm is less straight forward than exact
algorithms
For approximation algorithm the correctness can be proved if the
error occurred does not exceed the predefined limit
Note:
Two important types of efficiency:
1.Time efficiency - How fast the algorithm runs
2.Space efficiency - How much extra memory the algorithm used
3.Generality - Desirable characteristics of an algorithm
Example:
The problem of determining whether two integers are relatively
prime, i.e., whether their only common divisor is equal to 1.
Algorithms are destined to be ultimately implemented as computer
programs.
The important aspect is the possibility of making the transition from
an algorithm to a program either incorrectly or very inefficiently.
SO
LVABLEAND
UNSO
LVABLEPRO
BLEMS
THANKYO
U

Weitere ähnliche Inhalte

Ähnlich wie 19IS402_LP1_LM_22-23.pdf

2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf
ishan743441
 
01 - Introduction to Algorithms.pptx
01 - Introduction to Algorithms.pptx01 - Introduction to Algorithms.pptx
01 - Introduction to Algorithms.pptx
aimeejc
 
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
 
Algorithm types performance steps working
Algorithm types performance steps workingAlgorithm types performance steps working
Algorithm types performance steps working
Saurabh846965
 

Ähnlich wie 19IS402_LP1_LM_22-23.pdf (20)

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
 
ALGO.ppt
ALGO.pptALGO.ppt
ALGO.ppt
 
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and AlgorithmsCP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
 
chapter 1
chapter 1chapter 1
chapter 1
 
DAA 1 ppt.pptx
DAA 1 ppt.pptxDAA 1 ppt.pptx
DAA 1 ppt.pptx
 
DAA ppt.pptx
DAA ppt.pptxDAA ppt.pptx
DAA ppt.pptx
 
Unit i
Unit iUnit i
Unit i
 
Design & Analysis Of Algorithm
Design & Analysis Of AlgorithmDesign & Analysis Of Algorithm
Design & Analysis Of Algorithm
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf
 
Algorithms notes 2 tutorials duniya
Algorithms notes 2   tutorials duniyaAlgorithms notes 2   tutorials duniya
Algorithms notes 2 tutorials duniya
 
DATA STRUCTURE.pdf
DATA STRUCTURE.pdfDATA STRUCTURE.pdf
DATA STRUCTURE.pdf
 
DATA STRUCTURE
DATA STRUCTUREDATA STRUCTURE
DATA STRUCTURE
 
01 - Introduction to Algorithms.pptx
01 - Introduction to Algorithms.pptx01 - Introduction to Algorithms.pptx
01 - Introduction to Algorithms.pptx
 
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
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Notion of an algorithm
Notion of an algorithmNotion of an algorithm
Notion of an algorithm
 
Algorithm types performance steps working
Algorithm types performance steps workingAlgorithm types performance steps working
Algorithm types performance steps working
 
Notion of Algorithms.pdf
Notion of Algorithms.pdfNotion of Algorithms.pdf
Notion of Algorithms.pdf
 
Analysis and Design of Algorithms notes
Analysis and Design of Algorithms  notesAnalysis and Design of Algorithms  notes
Analysis and Design of Algorithms notes
 

Mehr von GOWTHAMR721887 (7)

19IS402_LP3.1_LM_22-23.pdf
19IS402_LP3.1_LM_22-23.pdf19IS402_LP3.1_LM_22-23.pdf
19IS402_LP3.1_LM_22-23.pdf
 
22PH102_ISE_U3_LP1_-_Notes.pdf
22PH102_ISE_U3_LP1_-_Notes.pdf22PH102_ISE_U3_LP1_-_Notes.pdf
22PH102_ISE_U3_LP1_-_Notes.pdf
 
22PH102_ISE_U2_LP1_-_Notes.pdf
22PH102_ISE_U2_LP1_-_Notes.pdf22PH102_ISE_U2_LP1_-_Notes.pdf
22PH102_ISE_U2_LP1_-_Notes.pdf
 
19IS303_22-23_LM11.pdf
19IS303_22-23_LM11.pdf19IS303_22-23_LM11.pdf
19IS303_22-23_LM11.pdf
 
19IS305_U2_LP4_LM4-22-23.pdf
19IS305_U2_LP4_LM4-22-23.pdf19IS305_U2_LP4_LM4-22-23.pdf
19IS305_U2_LP4_LM4-22-23.pdf
 
19IS305_U1_LP3_LM3-22-23-2.pdf
19IS305_U1_LP3_LM3-22-23-2.pdf19IS305_U1_LP3_LM3-22-23-2.pdf
19IS305_U1_LP3_LM3-22-23-2.pdf
 
An Internet of Things Based Smart Waste.pptx
An Internet of Things Based Smart Waste.pptxAn Internet of Things Based Smart Waste.pptx
An Internet of Things Based Smart Waste.pptx
 

Kürzlich hochgeladen

Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
dharasingh5698
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Kürzlich hochgeladen (20)

Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 

19IS402_LP1_LM_22-23.pdf

  • 1. UNITI INTRO DUCTIO N 19IS402 DESIGN & ANALYSIS OF ALGORITHMS Prepared by POORNIMA A
  • 2. Discussion Outline 1.Overview of Algorithm Problem Solving 2.Fundamentals of Algorithm Problem Solving Understanding the Problem Decide on: computational means, exact vs. approximate solving, algorithm design technique Designing an Algorithm Prove Correctness Analyze the Algorithm Code the Algorithm TODAY'S DISCUSSIO N
  • 4. Any Air travel connects several cities Some Cities are connected by direct flights Want to compute all pairs of cities connected by sequence of flights Example 1 : Air Travel
  • 5.
  • 6. Observations Paths Representation of graph for manipulating it as a program with suitable data structure Design efficient algorithm Efficiency Number of cities (N) ; Number of direct flights (F) Computing paths between N and F Dependency How much N and F values can be handled - Online booking requries responses in seconds
  • 7. EXAMPLE2 XERO XSHO P 1.When xerox shop to give some job on schedule time (Project report) 2.Any discounts 3.Brute force approach 4.Decomposition - Large problem first and then smaller one next (Includes recursion) 5.Based on some criteria - One with number of pages, most related with the deadline - Optimal solution
  • 8. EXAMPLE2 XERO XSHO P Variations 1.Types of machines (old or new) 2.Cost of ink and paper (Revenue) 3.Account for set up jobs
  • 9. EXAMPLE3 DO CUMENTSIMILARITY 1.Plagiarism detection 2.Changes in version of code 3.Web search queries more effectively Measure of Similarity Repeat of distance Edit distance - How many changes we can make in the document? Add/ remove a letter - One change Compute the minimum distance
  • 11. EXAMPLE4 Write a program that meets the following assumption: There is a point in the center of the screen. In the right upper part of the screen, the program randomly draws a geometrical figure (triangle, quadrilateral). The player's task is to draw a figure in the lower left part of the screen so that after turning 180 degrees it will cover as accurately as possible with the figure drawn by the computer. After decomposing the problem, we get a set of sub-problems related to the graphic part. These sub-problems will not be more difficult
  • 13. 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. The notion of the algorithm
  • 14. for w hich an to be specified 1. The nonambiguity requirement for each step of an algorithm cannot be compromised. 2.The range of inputs algorithm works has carefully. 3.The same algorithm can be represented in several different ways. 4.There may exist several algorithms for solving the same problem. 5.Algorithms for the same problem can be based on very different ideas and can solve the problem with dramatically different speeds. Important Points
  • 15. Clear and Unambiguous clear and clear in all Well-Defined Inputs If an algorithm says to take inputs, it should be well-defined inputs. Finiteness The algorithm must be finite, i.e. it should not end up in an infinite loops or similar. Language Independent The Algorithm designed must be language-independent hence it can be implemented in any language, and yet the output will be same, as expected. Algorithm should be unambiguous. Each steps should be aspects and m ust give only one meaning. Well-Defined Outputs The algorithm must clearly define what output will be yielded and it should be well-defined as w ell. Feasible The algorithm must be simple, generic and practical, such that it can be executed It must not contain some future technology
  • 16. gcd(m, n) = gcd(n, m mod n) where m mod n is the remainder of the division of m by n, until m mod n is equal to 0. For example, gcd(60, 24) can be computed as follows: gcd(60, 24) = gcd(24, 12) = gcd(12, 0) = 12. Euclid’s algorithm - Concept
  • 17. Step 1 If n = 0, return the value of m as the answer and stop; otherwise, proceed to Step 2. Step 2 Divide m by n and assign the value of the remainder to r. Step 3 Assign the value of n to m and the value of r to n. Go to Step 1. Euclid’s algorithm for computing gcd(m, n)
  • 18. ALGORITHM Euclid(m, n) //Computes gcd(m, n) by Euclid’s algorithm //Input: Two nonnegative, not-both-zero integers m and n //Output: Greatest common divisor of m and n while n ≠ 0 do r ← m mod n m← n n← r return m Euclid’s algorithm - Pseudocode
  • 19. In first method is based on the definition of GCD of m and n as the largest integer that divides both numbers evenly. Now Consider, t = min{m, n} 1.If t divides both m and n then t is the answer 2.Else simply decrease the t by 1and try again For example, For numbers 60 and 24, the algorithm will try first 24, then 23, and so on, until it reaches 1 2, where it stops. Euclid’s algorithm - Method 2
  • 20. Consecutive integer checking algorithm for computing gcd(m, n) Step 1 Assign the value of min{m, n} to t. Step 2 Divide m by t. If the remainder of this division is 0, go to Step 3; otherwise, go to Step 4. Step 3 Divide n by t. If the remainder of this division is 0, return the value of t as the answer and stop; otherwise, proceed to Step 4. Step 4 Decrease the value of t by 1 . Go to Step 2. Euclid’s algorithm - Method 2
  • 21. Middle-school procedure for computing gcd(m, n) Step 1 Find the prime factors of m. Step 2 Find the prime factors of n. Step 3 Identify all the common factors in the two prime expansions found in Step 1and Step 2. (If p is a common factor occurring pm and pn times in m and n, respectively, it should be repeated min{pm, pn } times.) Step 4 Compute the product of all the common factors and return it as the greatest common divisor of the numbers given. Euclid’s algorithm - Method 3
  • 22. Thus, for the numbers 60 and 24, we get 60 = 2 . 2 . 3 . 5 24 = 2 . 2 . 2 . 3 gcd(60, 24) = 2 . 2 . 3 = 1 2. Euclid’s algorithm - Method 3
  • 23. ADVANTAGES O F AN ALGO RITHM Algorithm is a step-wise representation to a given problem - easy to understand An algorithm uses a definite procedure In Algorithm the problem is broken down into smaller steps - easy to convert it into an actual program. It is not dependent on any programming language - anyone can understand a logical sequence - Every step is easy to debug
  • 24. DISADVANTAGES O F AN ALGO RITHM Writing an algorithm takes a long time - time-consuming. Branching and Looping statements are difficult to show in Algorithms. Big tasks are difficult to put in Algorithms
  • 25. E X A M P LE 1: Going to market to purchase a Pen
  • 26. E X A M P LE 1: Going to market to purchase a Pen Step 1 : Prepare yourself to go to market Step 2: Ckeck your wallet for money Step 3: If there is no money in the wallet, replenish it Step 4: Go to the shop Step 5: Ask for your favorite brand of pen Step 6: If pen is not available, go to Step 7 else go to Step 1 0 Step 7: Give money to the shop keeper Step 8: Keep the purchased pen safely Step 9: Go back home Step 10: Ask for any other brand of pen Step 1 1 : Go to Step 7
  • 28. Before designing an algorithm is to understand completely the problem given. Read the problem’s description, do a few small examples by hand, think about special cases, and ask questions again if needed. For Computing applications we can use a known algorithm for solving it. To know its strengths and weaknesses, especially if you have to choose among several available algorithms. Will not find a readily available algorithm and will have to design your own.
  • 29. An input to an algorithm specifies an instance of the problem the algorithm solves. Very important to specify exactly the set of instances the algorithm needs to handle. If fails the algorithm may work correctly for a majority of inputs but crash on some “boundary” value. Correct algorithm is not one that works most of the time, but one that works correctly for all legitimate inputs.
  • 30. Algorithms in use today are still destined to be programmed for a computer closely resembling the von Neumann machine The essence of this architecture is captured by the so-called 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.
  • 31. Exact algorithm Always find the optimal solution to a given optimization problem. Approximation algorithm We can prove a bound on the ratio between the optimal solution and the solution produced by the algorithm.
  • 32. Important Points 1)There are important problems that cannot be solved exactly Example: Extracting square roots Solving non linear equations Evaluating definite integrals 2) Solving a problem exactly can be unacceptably slow because of problem's a part of a more sophisticated intrinsic complexity 3) An approximation algorithm can be algorithm that solves a problem exactly
  • 33. Some algorithms demand predicated on ingenious data structures Data structures remain crucially important for both design and analysis of algorithms
  • 34. An design technique is a general approach to solving problems algorithmically that is applicable to a variety of problems from different areas of computing. 1.They provide guidance for designing algorithms for new problems, i.e., problems for which there is no known satisfactory algorithm. 2.Algorithms are the cornerstone of computer science. 3.Make it possible to classify algorithms according to an underlying design idea; therefore, they can serve as a natural way to both categorize and study algorithms.
  • 35. Natural Language: Using a natural language has an obvious appeal; However, the inherent ambiguity of any natural language makes a succinct and clear description of algorithms surprisingly difficult. Pseudocode: Is a mixture of a natural language and programming language-like constructs. Pseudocode is usually more precise than natural language, and its usage often yields more succinct algorithm descriptions.
  • 36. Flowchart: A method of expressing an algorithm by a collection of connected geometric shapes containing descriptions of the algorithm’s steps. Has proved to be inconvenient for all but very simple algorithms Note: Can be fed into an electronic computer directly
  • 37. Have to prove that the algorithm yields a required result for every legitimate input in a finite amount of time. For Some algorithms, a proof of correctness is quite easy; For others, it can be quite complex. A common technique for proving correctness is to use mathematical induction because an algorithm’s iterations provide a natural sequence of steps needed for such proofs. Even if algorithm fails for one input the algorithm has to be redesign
  • 38. Approximation algorithm is less straight forward than exact algorithms For approximation algorithm the correctness can be proved if the error occurred does not exceed the predefined limit Note:
  • 39. Two important types of efficiency: 1.Time efficiency - How fast the algorithm runs 2.Space efficiency - How much extra memory the algorithm used 3.Generality - Desirable characteristics of an algorithm Example: The problem of determining whether two integers are relatively prime, i.e., whether their only common divisor is equal to 1.
  • 40. Algorithms are destined to be ultimately implemented as computer programs. The important aspect is the possibility of making the transition from an algorithm to a program either incorrectly or very inefficiently.
  • 42.
  • 43.