0% found this document useful (0 votes)
5 views

Design and Analysis of Algorithms

The document provides an overview of algorithms, including their definition, importance, characteristics, and design techniques. It emphasizes the significance of algorithms in problem-solving, efficiency, and decision-making, while detailing various design approaches such as Divide and Conquer and Dynamic Programming. Additionally, it discusses algorithm analysis, including time and space complexity, and introduces computational models like RAM and PRAM for evaluating algorithm performance.

Uploaded by

hibanahm12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Design and Analysis of Algorithms

The document provides an overview of algorithms, including their definition, importance, characteristics, and design techniques. It emphasizes the significance of algorithms in problem-solving, efficiency, and decision-making, while detailing various design approaches such as Divide and Conquer and Dynamic Programming. Additionally, it discusses algorithm analysis, including time and space complexity, and introduces computational models like RAM and PRAM for evaluating algorithm performance.

Uploaded by

hibanahm12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

DESIGN AND ANALYSIS

OF ALGORITHMS
INTRODUCTION
● A finite set of instruction that specifies a sequence of operation is to be
carried out in order to solve a specific problem or class of problems is
called an Algorithm.
● That is algorithm is transformation from input to output
● Algorithm design is all about mathematical entities which leads to good
programmes.
● Algorithm does not depend upon the programming languages and for a
particular environment
● An algorithm is the best way to represent the solution of a particular
problem in a very simple and efficient way. If we have an algorithm for a
specific problem, then we can implement it in any programming language
IMPORTANCE OF ALGORITHM
● It helps in problem-solving by providing efficient solutions to complex
problems. It makes the code faster by optimizing it.
● It helps determine the computational complexity of a problem statement and
helps quantify these difficulties.
● It is used for sorting and searching large datasets efficiently. Some of the
significant sorting algorithms are quick sort and merge sort.
● It helps in finding meaningful patterns and information from a large dataset
quickly.
● A practical algorithm ensures that with the growth of input size, processing
time or resources are minimal. This is important for handling large datasets.
● It is used in decision-making processes.
NEED OF ALGORITHM
1. To understand the basic idea of the problem.
2. To find an approach to solve the problem.
3. To improve the efficiency of existing techniques.
4. To understand the basic principles of designing the algorithms.
5. To compare the performance of the algorithm with respect to other
techniques.
6. It is the best method of description without describing the
implementation detail.
NEED OF ALGORITHM
7. The Algorithm gives a clear description of requirements and goal of
the problem to the designer.
8. A good design can produce a good solution.
9. To understand the flow of the problem.
10. To measure the behavior (or performance) of the methods in all
cases (best cases, worst cases, average cases)
11. With the help of an algorithm, we can also identify the resources
(memory, input-output) cycles required by the algorithm.
12.To understand the principle of designing.
Characteristics of Algorithms
● Input: It should externally supply zero or more quantities.
● Output: It results in at least one quantity.
● Definiteness: Each instruction should be clear and ambiguous.
● Finiteness: An algorithm should terminate after executing a finite
number of steps.
● Effectiveness: Every instruction should be fundamental to be carried
out, in principle, by a person using only pen and paper.
● Feasible: It must be feasible enough to produce each instruction.
Characteristics of Algorithms
● Flexibility: It must be flexible enough to carry out desired changes with no
efforts.
● Efficient: an algorithm must ensure that it takes little time and less memory
space meeting the acceptable limit of development time.
● Independent: An algorithm must be language independent, which means
that it should mainly focus on the input and the procedure required to derive
the output instead of depending upon the language.
SPECIFICATION OF ALGORITHMS
There are three ways to specify an algorithm
1.by using Natural language
2.Pseudocode
3.Flowchart
Natural language
It is very simple easy to specify an algorithm using natural language.
Eg:- To perform addition of 2 numbers
Step 1 :Read the first number say a
Step 2 :Read the second number say b
Step3 :Add the two numbers and store the result in a variable C
Step4 : Display the result.
PSEUDOCODE:-It is the combination of natural language and
programming language constructs. it is more precisely than a natural
language.
Algorithm sum(a,b)
//perform addition of two numbers
//input : two integers a and b
//output :addition of two integers
C←a+b
Return C
FLOWCHART:- It is the graphical representation of an algorithm
EXAMPLE OF FLOWCHART
PSEUDOCODE
Pseudocode refers to an informal high-level description of the
operating principle of a computer program or other algorithm. It uses
structural conventions of a standard programming language intended
for human reading rather than the machine reading.
Advantages of Pseudocode
● Since it is similar to a programming language, it can be quickly
transformed into the actual programming language than a
flowchart.
● The layman can easily understand it.
● Easily modifiable as compared to the flowcharts.
● Its implementation is beneficial for structured, designed elements.
● It can easily detect an error before transforming it into a code.
PSEUDOCODE

Disadvantages of Pseudocode

● Since it does not incorporate any standardized style or format, it can


vary from one company to another.
● Error possibility is higher while transforming into a code.
● It may require a tool for extracting out the Pseudocode and facilitate
drawing flowcharts.
● It does not depict the design.
UNDERSTANDING THE PROBLEM & DECISION MAKING
➢ Understand the problem clearly.
➢ Determine what are the inputs to the problem and desired output.
➢ Decide the range of inputs.
➢ Good description of the problem should necessary.
DECISION MAKING:-
➢ We have to make decision about computational device, data
structure used for a particular problem,whether the problem
needs exact solution or approximate solution.
➢ Select appropriate algorithmic strategies according to the
problem.
ALGORITHM DESIGN TECHNIQUES
1. Brute-force or exhaustive search
2. Divide and Conquer
3. Greedy Algorithms
4. Dynamic Programming
5. Branch and Bound Algorithm
6. Randomized Algorithm
7. Backtracking
ALGORITHM DESIGN TECHNIQUES
1. Divide and Conquer Approach: It is a top-down approach. The algorithms
which follow the divide & conquer techniques involve three steps:

● Divide the original problem into a set of subproblems.


● Solve every subproblem individually, recursively.
● Combine the solution of the subproblems (top level) into a solution of the
whole original problem.

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.
ALGORITHM DESIGN TECHNIQUES
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.
4. Branch and Bound: In Branch & Bound algorithm a given
subproblem, which cannot be bounded, has to be divided into at least
two new restricted subproblems.
ALGORITHM DESIGN TECHNIQUES

5.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.
6.Brute force Approach:A brute force approach is an approach that
finds all the possible solutions to find a satisfactory solution to a
given problem. The brute force algorithm tries out all the
possibilities till a satisfactory solution is not found.
ALGORITHM ANALYSIS
The analysis is a process of estimating the efficiency of an algorithm. There
are two fundamental parameters based on which we can analysis the
algorithm:

● Space Complexity: The space complexity can be understood as the


amount of space required by an algorithm to run to completion.
● Time Complexity: Time complexity is a function of input size n that
refers to the amount of time needed by an algorithm to run to
completion.
ALGORITHM ANALYSIS
● TIME COMPLEXITY is denoted by T(n) is the sum of compile time and
execution Time.
● It also depends on size and behaviour of inputs.
● The limiting behaviour of the complexity as size increases is called the
Asymptotic Complexity.

● SPACE COMPLEXITY of an algorithm includes space for the code,space


for simple variables,constants etc.
A Good algorithm must take less amount of memory and less amount of
compile time.
ALGORITHM ANALYSIS
During analysis performance of an algorithm should be
evaluated by predicting how much resources the algorithm
requires.to predict the resource requirements ,we need
computational model
These are the common tools used for algorithm analysis
1.RAM model of computation (Random Access Machine)
2.PARM(Parallel Access Random Machine)
3.Message passing Model
4.Turing machine
Model of Computation
➢ Computational models are used for easy implementation of
algorithms.
➢ It hide the machine implementation details ,sothat general
results that apply to abroad class of machines to be obtained.
➢ It can analyze the achievable complexity bounds.(time,space)
➢ Analyze maximum parallelism.Models are directly related to
algorithms.
The RAM Model of Computation
The RAM (Random Access Machine) model of computation measures the run
time of an algorithm by summing up the number of steps needed to execute
the algorithm on a set of data. The RAM model operates by the following
principles:
• Basic logical or arithmetic operations (+, *, =, if, call) are considered to be
simple operations that take one time step.
• Loops and subroutines are complex operations composed of multiple time
steps.
Using the RAM model, you measure the running time of an algorithm by
counting the number of steps an algorithm takes on a given input
RAM MODEL
● Space complexity of an algorithm refer to the amount of
memory required to run.
● Time complexity of an algorithm refer to its running
time,which depends on input size.
● Primitive operations refer to the unit of operation that can be
identified in the pseudo-code.
● Memory not infinite.
RAM contains a memory unit access (MAU) that creates a path
from the processor to an arbitrary memory locations.
Sequential Algorithm Steps
1.READ PHASE in which the processor reads data from a memory
location and copies it into register.
2.COMPUTE PHASE in which a processor performs a basic
operation on data from one or two of its registers.
3.WRITE PHASE in which the processor copies the contents of an
internal register into a memory location.
PRAM MODEL
Parallel Random Access Machine, also called PRAM is a model
considered for most of the parallel algorithms.

It helps to write a parallel algorithm without any architecture


constraints and also allows parallel-algorithm designers to treat
processing power as unlimited.

It ignores the complexity of inter-process communication. Here,


multiple processors are attached to a single block of memory.

This model allows each processor to have its own algorithm and run
asynchronous.In many application all processors run the same
algorithm synchronously.
PARM MODEL
PRAM MODEL
A PRAM model contains −
● A set of similar type of processors.
● All the processors share a common memory unit. Processors
can communicate among themselves through the shared
memory only.
● A memory access unit (MAU) connects the processors with the
single shared memory.
Here, n number of processors can perform independent operations on n
number of data in a particular unit of time.
PRAM MODEL
To solve this problem, the following constraints have been enforced on PRAM
model −
Exclusive Read Exclusive Write (EREW) − Here no two processors are allowed to
read from or write to the same memory location at the same time.
Exclusive Read Concurrent Write (ERCW) − Here no two processors are allowed
to read from the same memory location at the same time, but are allowed to write
to the same memory location at the same time.
Concurrent Read Exclusive Write (CREW) − Here all the processors are allowed to
read from the same memory location at the same time, but are not allowed to write
to the same memory location at the same time.
Concurrent Read Concurrent Write (CRCW) − All the processors are allowed to
read from or write to the same memory location at the same time.
PRAM MODEL
Algorithm steps have 3 Phases:-

READ PHASE: Up to n processors read upto a memory locations


simultaneously.

COMPUTE PHASE: Up to n processors perform basic arithmetic/logical


operations on their local data.

WRITE PHASE :Up to n processors write simultaneously into up to n


memory locations.

Each processor knows its own ID and algorithm can use processor IDs
to control the actions of the processors.

You might also like