KEMBAR78
Design Analysis of Algorithm_Introduction-1.pptx
AD3351-DESIGN AND ANALYSIS
OF ALGORITHM
UNIT-1 INTRODUCTION
NOTION OF ALGORITHM
ALGORITHM
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.
NOTION OF ALGORITHM
Some Important Points on Algorithm
CHARACTERISTICS OF AN
ALGORITHM
 Input - Valid inputs must be clearly specified
 Output – Produces at least one output- the result or solution of the problem
 Definiteness - Each step must be clear and unambiguously specified
Finiteness - Terminates after a finite number of steps
 Effectiveness - Steps must be simple enough to be performed using basic operations.
GCD(m,n) - Definition
īļ gcd(m,n) – the largest integer that divides both m and n evenly, ie., with
a remainder of zero.
īļ General method – gcd(m,n)
Eg: Compute GCD(60,24)
â€ĸ Find common factors of 2 given numbers:
â€ĸ Product of those common factors – gcd
=> gcd(24,18)=?
To illustrate the notion of the algorithm we consider 3
methods to solve the same problem – Computing the
greatest common divisor of 2 non-negative, not-both-
zero integers m,n => gcd(m,n)
īļ Euclid’s Algorithm
īļ Consecutive Integer Checking Algorithm
īļ Middle-School Algorithm
Euclid’s Algorithm:
Compute gcd(60,24) using Euclid’s algorithm
Given: m=60 and n=24
Iteration 1:
n=24≠0 -> r=60 mod 24 -> r=12
Now, m=n=24 and n=r=12
Iteration 2:
n=12≠0 -> r=24 mod 12 -> r=0
Now, m=n=12 and n=r=0
Iteration 3:
n=0, condition fails and returns m value
Therefore, gcd(60,24)=12.
Middle-School Algorithm
GCD(24,12)
Given: m=24 and n=12
Step 1: prime factors of m => 2,2,2,3
Step 2: prime factors of n => 2,2,3
Step 3: common factors => 2,2,3
Step 4: product of common factors => 2x2x3=12
Consecutive Integer Checking Algorithm
Contd..
Eg: (i) Compute gcd(9,6) using Consecutive Integer
Checking Algorithm
(i) Compute gcd(24,12) using Consecutive Integer
Checking Algorithm
(iii) Compute gcd(60,24) using Consecutive Integer
Checking Algorithm
Drawback:
Doesn’t work properly when one of its inputs is ZERO
Sieve of Eratosthenes
īļ Simple algorithm for generating consecutive primes not exceeding
any given integer n>1
īļ Starts by initializing a list of primes from 2 to n
īļ First Iteration – eliminate all multiples of 2 except 2
īļ Next Iteration - eliminate all multiples of 3 except 3
īļ Continuous until no more elements to be eliminated
īļ Remaining integers – primes
Algorithm : Sieve of Eratosthenes
Step1: Create a list of consecutive integers from 2 through n – (1,2,3,
â€Ļ..,n).
Step 2: Initially let p=2 the smallest prime no.
Step 3: Enumerate the multiples of p by counting in increments of p from
2p to n and mark them in the list (these will be 2p,3p,4p,â€Ļ, the p itself
should not be marked).
Step 4: Find the smallest no in the list greater than p that is not marked. If
there is no such no stop. Otherwise let p now equal to this new no and
repeat from Step 3.
Step 5: When the algorithm terminates the numbers remaining not marked
in the list are all the primes below n.
FUNDAMENTALS OF ALGORITHMIC PROBLEM SOLVING
Important Problem Types
 The different problem types are
1. Sorting
2. Searching
3. String processing
4. Graph problems
5. Combinatorial problems
6. Geometric problems
7. Numerical problems
Sorting
īļ Sorting problem is one which rearranges the items of a given list in
ascending order.
īļ For example in student’s information, we can choose to sort student records
in alphabetical order of names or by student register number. Such a
specially chosen piece of information is called a key.
īļ Sorting solves many problems, the most important of them is searching:
dictionaries, telephone books, class lists, and so on are sorted.
Contd..
īļ There are two important properties of sorting algorithms.
īļ A sorting algorithm is called stable, if it preserves the relative order of any two equal
elements in its input.
īļ For example, we have a list of students sorted alphabetically and if we sort the
student list based on their GPA: a stable algorithm will yield a list in which students
with same GPA will be sorted alphabetically.
īļ The second feature of an algorithm is ‘in place’, if it does not require extra memory.
īļ There are some sorting algorithms that are in place and those that are not.
Searching
īļ The searching problem deals with finding a given value, called a search key,
in a given set.
īļ The searching can be either a straightforward sequential search algorithm or
binary search algorithm based on different forms of representing the set.
īļ Some algorithms work faster but require more memory, some are very fast
but applicable only to sorted arrays.
īļ Searching, mainly deals with addition and deletion of records.
String processing
īļ A String is a sequence of characters. It is mainly used in string handling
algorithms.
īļ Most common ones are text strings, which consists of letters, numbers
and special characters.
īļ Bit strings consist of zeroes and ones and gene sequences, which can be
modeled by strings of four-character alphabet{A,C,G,T}
Graph Problems
īļ A graph is a collection of points called vertices,some of which are connected by
line segments called edges.
īļ Graphs can be used for modeling a wide variety of real-life applications such as
transportation, communication networks, project scheduling, and games.
īļ It includes graph traversal, shortest-path and topological sorting algorithms.
īļ The most well-known examples of computationally hard problems are the
traveling salesman problem and graph-coloring problem
Contdâ€Ļ
īļ The TSP is the problem of finding the shortest tour through n cities that visits
every city exactly once.
īļ It arises in modern applications as circuit board and VLSI chip fabrication, X-
ray crystallography and genetic engineering.
īļ The graph-coloring problem is to assign the smallest number of colors to
vertices of a graph so that no two adjacent vertices are of the same color.
Combinatorial Problems
īļ The traveling salesman problem and the graph-coloring problem are examples of
combinatorial problems.
īļ These are problems that ask us to find a combinatorial object such as
permutation, combination or a subset that satisfies certain constraints and has
some desired (e.g. maximizes a value or minimizes a cost).
Geometric Problems
īļ Geometric algorithms deal with geometric objects such as points, lines and
polygons.
īļ It also includes various geometric shapes such as triangles, circles etc.
īļ The applications for these algorithms are in computer graphic, robotics etc.
īļ The two problems most widely used are the closest-pair problems, given ‘n’ points
in the plane, find the closest pair among them.
īļ The convex-hull problem is to find the smallest convex polygon that would include
all the points of a given set.
Numerical Problems
īļ This is another large special area of applications, where the problems involve
mathematical objects of continuous nature: solving equations, computing definite
integrals and evaluating functions and so on.
īļ These problems can be solved only approximately.
īļ These require real numbers, which can be represented in a computer only
approximately.
īļ It can also lead to an accumulation of round-off errors.
Video Link
īą https://youtu.be/fLYV-Z76dUM

Design Analysis of Algorithm_Introduction-1.pptx

  • 1.
    AD3351-DESIGN AND ANALYSIS OFALGORITHM UNIT-1 INTRODUCTION
  • 2.
    NOTION OF ALGORITHM ALGORITHM Analgorithm 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.
  • 3.
  • 4.
  • 5.
    CHARACTERISTICS OF AN ALGORITHM Input - Valid inputs must be clearly specified  Output – Produces at least one output- the result or solution of the problem  Definiteness - Each step must be clear and unambiguously specified Finiteness - Terminates after a finite number of steps  Effectiveness - Steps must be simple enough to be performed using basic operations.
  • 6.
    GCD(m,n) - Definition īļgcd(m,n) – the largest integer that divides both m and n evenly, ie., with a remainder of zero. īļ General method – gcd(m,n) Eg: Compute GCD(60,24) â€ĸ Find common factors of 2 given numbers: â€ĸ Product of those common factors – gcd => gcd(24,18)=?
  • 7.
    To illustrate thenotion of the algorithm we consider 3 methods to solve the same problem – Computing the greatest common divisor of 2 non-negative, not-both- zero integers m,n => gcd(m,n) īļ Euclid’s Algorithm īļ Consecutive Integer Checking Algorithm īļ Middle-School Algorithm
  • 8.
  • 10.
    Compute gcd(60,24) usingEuclid’s algorithm Given: m=60 and n=24 Iteration 1: n=24≠0 -> r=60 mod 24 -> r=12 Now, m=n=24 and n=r=12 Iteration 2: n=12≠0 -> r=24 mod 12 -> r=0 Now, m=n=12 and n=r=0 Iteration 3: n=0, condition fails and returns m value Therefore, gcd(60,24)=12.
  • 11.
  • 12.
    GCD(24,12) Given: m=24 andn=12 Step 1: prime factors of m => 2,2,2,3 Step 2: prime factors of n => 2,2,3 Step 3: common factors => 2,2,3 Step 4: product of common factors => 2x2x3=12
  • 13.
  • 14.
    Contd.. Eg: (i) Computegcd(9,6) using Consecutive Integer Checking Algorithm (i) Compute gcd(24,12) using Consecutive Integer Checking Algorithm (iii) Compute gcd(60,24) using Consecutive Integer Checking Algorithm Drawback: Doesn’t work properly when one of its inputs is ZERO
  • 15.
    Sieve of Eratosthenes īļSimple algorithm for generating consecutive primes not exceeding any given integer n>1 īļ Starts by initializing a list of primes from 2 to n īļ First Iteration – eliminate all multiples of 2 except 2 īļ Next Iteration - eliminate all multiples of 3 except 3 īļ Continuous until no more elements to be eliminated īļ Remaining integers – primes
  • 16.
    Algorithm : Sieveof Eratosthenes Step1: Create a list of consecutive integers from 2 through n – (1,2,3, â€Ļ..,n). Step 2: Initially let p=2 the smallest prime no. Step 3: Enumerate the multiples of p by counting in increments of p from 2p to n and mark them in the list (these will be 2p,3p,4p,â€Ļ, the p itself should not be marked). Step 4: Find the smallest no in the list greater than p that is not marked. If there is no such no stop. Otherwise let p now equal to this new no and repeat from Step 3. Step 5: When the algorithm terminates the numbers remaining not marked in the list are all the primes below n.
  • 19.
  • 20.
    Important Problem Types The different problem types are 1. Sorting 2. Searching 3. String processing 4. Graph problems 5. Combinatorial problems 6. Geometric problems 7. Numerical problems
  • 21.
    Sorting īļ Sorting problemis one which rearranges the items of a given list in ascending order. īļ For example in student’s information, we can choose to sort student records in alphabetical order of names or by student register number. Such a specially chosen piece of information is called a key. īļ Sorting solves many problems, the most important of them is searching: dictionaries, telephone books, class lists, and so on are sorted.
  • 22.
    Contd.. īļ There aretwo important properties of sorting algorithms. īļ A sorting algorithm is called stable, if it preserves the relative order of any two equal elements in its input. īļ For example, we have a list of students sorted alphabetically and if we sort the student list based on their GPA: a stable algorithm will yield a list in which students with same GPA will be sorted alphabetically. īļ The second feature of an algorithm is ‘in place’, if it does not require extra memory. īļ There are some sorting algorithms that are in place and those that are not.
  • 23.
    Searching īļ The searchingproblem deals with finding a given value, called a search key, in a given set. īļ The searching can be either a straightforward sequential search algorithm or binary search algorithm based on different forms of representing the set. īļ Some algorithms work faster but require more memory, some are very fast but applicable only to sorted arrays. īļ Searching, mainly deals with addition and deletion of records.
  • 24.
    String processing īļ AString is a sequence of characters. It is mainly used in string handling algorithms. īļ Most common ones are text strings, which consists of letters, numbers and special characters. īļ Bit strings consist of zeroes and ones and gene sequences, which can be modeled by strings of four-character alphabet{A,C,G,T}
  • 25.
    Graph Problems īļ Agraph is a collection of points called vertices,some of which are connected by line segments called edges. īļ Graphs can be used for modeling a wide variety of real-life applications such as transportation, communication networks, project scheduling, and games. īļ It includes graph traversal, shortest-path and topological sorting algorithms. īļ The most well-known examples of computationally hard problems are the traveling salesman problem and graph-coloring problem
  • 26.
    Contdâ€Ļ īļ The TSPis the problem of finding the shortest tour through n cities that visits every city exactly once. īļ It arises in modern applications as circuit board and VLSI chip fabrication, X- ray crystallography and genetic engineering. īļ The graph-coloring problem is to assign the smallest number of colors to vertices of a graph so that no two adjacent vertices are of the same color.
  • 27.
    Combinatorial Problems īļ Thetraveling salesman problem and the graph-coloring problem are examples of combinatorial problems. īļ These are problems that ask us to find a combinatorial object such as permutation, combination or a subset that satisfies certain constraints and has some desired (e.g. maximizes a value or minimizes a cost).
  • 28.
    Geometric Problems īļ Geometricalgorithms deal with geometric objects such as points, lines and polygons. īļ It also includes various geometric shapes such as triangles, circles etc. īļ The applications for these algorithms are in computer graphic, robotics etc. īļ The two problems most widely used are the closest-pair problems, given ‘n’ points in the plane, find the closest pair among them. īļ The convex-hull problem is to find the smallest convex polygon that would include all the points of a given set.
  • 29.
    Numerical Problems īļ Thisis another large special area of applications, where the problems involve mathematical objects of continuous nature: solving equations, computing definite integrals and evaluating functions and so on. īļ These problems can be solved only approximately. īļ These require real numbers, which can be represented in a computer only approximately. īļ It can also lead to an accumulation of round-off errors.
  • 30.