Design and Analysis of Algorithms
Design and Analysis of Algorithms
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
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:-
Each processor knows its own ID and algorithm can use processor IDs
to control the actions of the processors.