DAA Module-1-2
DAA Module-1-2
DAA Module-1-2
Algorithm
Dr. Rajesh I S
Assistant Professor
BMSIT&M
Time Analysis
X=5*a+6*b (1)
Space Analysis
S(n)=3 Words
Frequency Count Method
n+1
1 n+1 n
n
Space Complexity
n+1
n
n
n+1
n (n+1)
n*n
Time Complexity #1
i--
i=i+2
Compare Class of Functions
n=1
n=2
n=4
n=8
Asymptotic Notations:
Asymptotic Notation is a way of comparing function that ignores constant
factors and small input sizes.
The time required for the execution of an algorithm is categorized into three
types:
In general, the choice of asymptotic notation depends on the problem and the specific
algorithm used to solve it. It is important to note that asymptotic notation does not
provide an exact running time or space usage for an algorithm, but rather a description
of how the algorithm scales with respect to input size. It is a useful tool for comparing
the efficiency of different algorithms and for predicting how they will perform on large
input sizes.
Little o Notations
Little o notation is used to describe an upper bound that cannot be tight. In
other words, loose upper bound of f(n).
Little ω Notations
Another asymptotic notation is little omega notation. it is denoted by (ω).
Little omega (ω) notation is used to describe a loose lower bound of f(n).
What is the need for Asymptotic analysis?
Since n > log n, linear search takes more time to execute than binary search. But what
if Linear search is executed on a very faster system.
The way to study the efficiency of an algorithm is to implement it and
experiment by running the program on various test inputs while recording the
time spent during each execution
Given two algorithms for a task, how do we find out which one is better?
One way of doing this is – to implement both the algorithms and run the two programs on your
computer for different inputs and see which one takes less time. There are many problems with
this approach for the analysis of algorithms.
It might be possible that for some inputs, the first algorithm performs better than the second.
And for some inputs second performs better.
It might also be possible that for some inputs, the first algorithm performs better on one
machine, and the second works better on another machine for some other inputs.
Asymptotic Analysis is the big idea that handles the above issues in analyzing algorithms. In
Asymptotic Analysis, we evaluate the performance of an algorithm in terms of input size (we
don’t measure the actual running time). We calculate, how the time (or space) taken by an
algorithm increases with the input size.
Let there be ‘n' items to be searched, After the first search the list is divided into two,
each of length n/2 . After the next search, 2 lists, each of length n/4 and so on. This
successive division has to stop when the length of list becomes 1. Let it happen after k
steps.
•Greedy Algorithm always makes the choice (greedy criteria) looks best at the
moment, to optimize a given objective.
•The greedy algorithm doesn't always guarantee the optimal solution however it
generally produces a solution that is very close in value to the optimal.
3. Dynamic Programming: Dynamic Programming is a bottom-up approach we solve all possible small
problems and then combine them to obtain solutions for bigger problems. This is particularly helpful when
the number of copying subproblems is exponentially large. Dynamic Programming is frequently related
to Optimization Problems.
6. Backtracking Algorithm: Backtracking Algorithm tries each possibility until they find the right one. It is
a depth-first search of the set of possible solution. During the search, if an alternative doesn't work, then
backtrack to the choice point, the place which presented different alternatives, and tries the next
alternative.
Properties of Asymptotic Notations
Following Asymptotic Notations Properties.
1.General Properties
2.Reflexive Properties
3.Transitive Properties
4.Symmetric Properties
5.Transpose Symmetric Properties
Selection Sort
The selection sort enhances the bubble sort by making only a single swap for each
pass through the rundown. In order to do this, a selection sort searches for the
biggest value as it makes a pass and, after finishing the pass, places it in the best
possible area. Similarly, as with a bubble sort, after the first pass, the biggest item is
in the right place. After the second pass, the following biggest is set up. This
procedure proceeds and requires n-1 goes to sort n item since the last item must be
set up after the (n-1) th pass.
Sequential Search Algorithm