Unit 2: Algorithm (2 Hrs and Contains 3 Marks)
Unit 2: Algorithm (2 Hrs and Contains 3 Marks)
Algorithm design is identified and incorporated into many solution theories of operation
research, such as dynamic programming and divide-and-conquer. Techniques for
designing and implementing algorithm designs are algorithm design patterns,[1] such as
template method pattern and decorator pattern, and uses of data structures, and name and
sort lists. Some current day uses of algorithm design can be found in internet retrieval
processes of web crawling, packet routing and caching.
1. Problem definition
2. Development of a model
3. Specification of Algorithm
4. Designing an Algorithm
5. Checking the correctness of Algorithm
6. Analysis of Algorithm
7. Implementation of Algorithm
8. Program testing
9. Documentation Preparation
● Dynamic programming
Dynamic programming is a design technique similar to divide and conquer.
Divide-and-conquer algorithms partition the problem into independent
subproblems, solve the subproblems recursively, and then combine their solutions
to solve the original problem. Dynamic programming is applicable when the
subproblems are not independent, that is, when subproblems share
subsubproblems. A dynamic-programming algorithm solves every subsubproblem
just once and then saves its answer in a table, thereby avoiding the work of
recomputing the answer every time the subsubproblem is encountered.
1.) Top-Down : Start solving the given problem by breaking it down. If you see
that the problem has been solved already, then just return the saved answer. If it
has not been solved, solve it and save the answer. This is usually easy to think of
and very intuitive. This is referred to as Memoization.
2.) Bottom-Up : Analyze the problem and see the order in which the sub-
problems are solved and start solving from the trivial subproblem, up towards the
given problem. In this process, it is guaranteed that the subproblems are solved
before solving the problem. This is referred to as Dynamic Programming.
Note that divide and conquer is slightly a different technique. In that, we divide
the problem in to non-overlapping subproblems and solve them independently,
like in mergesort and quick sort.
Dynamic programming is typically applied to optimization problems. In such
problems there can be many possible solutions. Each solution has a value, and we
wish to find a solution with the optimal (minimum or maximum) value. We call
such a solution an optimal solution, as opposed to the optimal solution, since
there may be several solutions that achieve the optimal value.
Dynamic programming can be effectively applied to solve the longest common
subsequence (LCS) problem. The problem is stated as following: given two
sequences (or strings) x and y find a maximum-length common subsequence
(substring) of x and y.
● Greedy Paradigm
A greedy algorithm repeatedly executes a procedure which tries to maximize the
return based on examining local conditions, with the hope that the outcome will
lead to a desired outcome for the global problem. In some cases such a strategy is
guaranteed to offer optimal solutions, and in some other cases it may provide a
compromise that produces acceptable approximations.
3. Characteristics of algorithm
While designing an algorithm as a solution to a given problem, we must take care of the
following five important characteristics of an algorithm.
Finiteness:
An algorithm must terminate after a finite number of steps and further each step must be
executable in finite amount of time. In order to establish a sequence of steps as an
algorithm, it should be established
that it terminates (in finite number of steps) on all allowed inputs.
Definiteness (no ambiguity):
Each steps of an algorithm must be precisely defined; the action to be carried out must be
rigorously and unambiguously specified for each case.
Inputs:
An algorithm has zero or more but only finite, number of inputs.
Output:
An algorithm has one or more outputs. The requirement of at least one output is
obviously essential, because, otherwise we cannot know the answer/ solution provided by
the algorithm. The outputs have specific relation to the inputs, where the relation is
defined by the algorithm.
Effectiveness:
An algorithm should be effective. This means that each of the operation to be performed
in an algorithm must be sufficiently basic that it can, in principle, be done exactly and in
a finite length of time, by person using pencil and paper. It may be noted that the
‘FINITENESS’ condition is a special case of ‘EFFECTIVENESS’. If a sequence of steps
is not finite, then it cannot be effective also.