Chapter #1 Analysis of Algorithm
Chapter #1 Analysis of Algorithm
www.1042notes.blogspot.com
[WHAT IS ALGORITHM]
Outline:
Algorithm
Why study Algorithm
Prosperities of Algorithm
Need of Algorithm
Algorithm VS. Program
Complexity of Algorithm
Time Complexity
Space Complexity
Types of Analysis
Algorithm Design Techniques
`
August 14, 1947 [WHAT IS ALGORITHM]
Algorithm
The term "analysis of algorithms" was coined by Donald Knuth.
1 www.1042notes.blogspot.com
August 14, 1947 [WHAT IS ALGORITHM]
Need of Algorithm:
1. To understand the basic idea of the problem.
2. To find an approach to solve the problem.
2 www.1042notes.blogspot.com
August 14, 1947 [WHAT IS ALGORITHM]
Algorithm vs Program:
A finite set of instructions that specifies a sequence of operations to
be carried out to solve a specific problem of a class of problem is
called an algorithm.
On the other hand, the Program doesn't have to satisfy the
finiteness condition.
For example, we can think of an operating system that continues in a
"wait" loop until more jobs are entered. Such a program doesn't
terminate unless the system crashes.
3 www.1042notes.blogspot.com
August 14, 1947 [WHAT IS ALGORITHM]
Complexity of Algorithm:
It is very convenient to classify algorithm based on the relative amount of time or
relative amount of space they required and specify the growth of time/space
requirement as a function of input size.
Time Complexity: Running time of a program as a function of the size of the
input.
Space Complexity: Some forms of analysis could be done based on how
much space an algorithm needs to complete its task.
This space complexity analysis was critical in the early days of computing when
storage space on the computer was limited. When considering this algorithm are
divided into those that need extra space to do their work and those that work in
place.
But now a day's problem of space rarely occurs because space on the computer
(internal or external) is enough.
4 www.1042notes.blogspot.com
August 14, 1947 [WHAT IS ALGORITHM]
To solve a problem:
we need to consider time as well as space complexity as the program may run on
a system where memory is limited but adequate space is available or may be vice-
versa.
In this context, if we compare bubble sort and merge sort. Bubble sort does not
require additional memory, but merge sort requires additional space. Though
time complexity of bubble sort is higher compared to merge sort, we may need to
apply bubble sort if the program needs to run in an environment, where memory
is very limited.
5 www.1042notes.blogspot.com
August 14, 1947 [WHAT IS ALGORITHM]
2. Greedy Technique:
Greedy method is used to solve the optimization problem.
An optimization problem is one in which we are given a set of input values, which
are required either to be maximized or minimized (known as objective), i.e. some
constraints or conditions.
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 sub problems is
exponentially large.
Dynamic Programming is frequently related to Optimization Problems.
6 www.1042notes.blogspot.com
August 14, 1947 [WHAT IS ALGORITHM]
7 www.1042notes.blogspot.com