Ada 1
Ada 1
Designing Techniques
Subject Code:-AL-402
Subject :- Analysis of Design & Algorithm
By:- Adarsh Raushan
Asst. Professor
CSE Dept.,LNCT, Bhopal
Algorithm:- Definition
► An algorithm is a step-by-step procedure or set
of rules designed to solve a specific problem or
perform a particular task. It is a finite sequence
of well-defined instructions that can be executed
mechanically or electronically by a computing
device. Algorithms can range from simple to
complex and are used extensively in computer
science, mathematics, engineering, and various
other fields to automate processes, make
decisions, analyze data, and more. The efficiency
and effectiveness of an algorithm often depend
on its design and implementation, as well as the
problem it aims to solve.
Algorithm:- Definition
► 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 meaning that the algorithm is
implemented from any programming
language.
Need of Algorithm
► To understand the basic idea of the problem.
► To find an approach to solve the problem.
► To improve the efficiency of existing techniques.
► To understand the basic principles of designing the
algorithms.
► To compare the performance of the algorithm with respect to
other techniques.
► It is the best method of description without describing the
implementation detail.
► The Algorithm gives a clear description of requirements and
goal of the problem to the designer.
Need of Algorithm
► A good design can produce a good solution.
► To understand the flow of the problem.
► To measure the behavior (or performance) of the methods
in all cases (best cases, worst cases, average cases)
► With the help of an algorithm, we can also identify the
resources (memory, input-output) cycles required by the
algorithm.
► With the help of algorithm, we convert art into a science.
► To understand the principle of designing.
► We can measure and analyze the complexity (time and
space) of the problems concerning input size without
implementing and running it; it will reduce the cost of
design.
Example :- Write an algorithm to add two numbers
► Step 1 − START
► Step 2 − declare three integers a, b & c
► Step 3 − define values of a & b
► Step 4 − add values of a & b
► Step 5 − store output of step 4 to c
► Step 6 − print c
► Step 7 − STOP’
Alternative Algorithm
► Step 1 − START ADD
► Step 2 − get values of a & b
► Step 3 − c ← a + b
► Step 4 − display c
► Step 5 − STOP
Example :- Find the largest number among three
numbers
► Step 1: Start
► Step 2: Declare variables a,b and c.
► Step 3: Read variables a,b and c.
► Step 4: If a > b
► If a > c
Display a is the largest number.
► Else
Display c is the largest number.
► Else
If
b > c Display b is the largest number.
Else
Display c is the greatest number.
► Step 5: Stop
Write an algorithm to add two numbers We design an
algorithm to get a solution of a given problem. A problem can
be solved in more than one ways.
Problem Development Steps
► Problem Definition
► Development of a model
► Specification of Algorithm
► Designing of Algorithm
► Checking the correctness of Algorithm
► Analysis of Algorithm
► Implementation of Algorithm
► Program Testing
► Documentation
ANALYSIS OF ALGORITHM
► Definition:- Algorithm analysis is the process of evaluating the
performance of an algorithm , usually in terms of time and space
complexity . There are several ways to analyze the performance of an
algorithm including aymptotic analysis, which analyzes the behavior
of an algorithm as the size of input grows indefinitely.
OR
► Algorithm analysis is an important part of computational complexity
theory, which provides theoretical estimation for required resources
of an algorithm to solve a specific computational problem. Analysis
of algorithm is the determination of amount of time and space
resources required to it.
ASYMPTOTIC NOTATIONS
► Asymptotic Notations are mathematical tools that allow you to
analyze an algorithm’s running time by identifying its behavior
as its input size grows.
This is also referred to as an algorithm’s growth rate:-
► You can’t compare two algorithm’s head to head.
► You compare space and time complexity using asymptotic
analysis.
► It compares two algorithms based on changes in their
performance as the input size is increased or decreased.
TYPES OF ASYMPTOTIC NOTATIONS
1. Big-O Notation (O-notation)
4. Little –o Notation(o-notation)
2. Logarithmic Complexity:
It imposes a complexity of O(log(N)). It undergoes the execution of the
order of log(N) steps. To perform operations on N elements, it often
takes the logarithmic base as 2.
3. Linear Complexity:-
It imposes a complexity of O(N). It encompasses the same number of
steps as that of the total number of elements to implement an operation
on N elements.
SOME OTHER COMPLEXITIES THAT EXISTS IN
PROGRAM
4. Quadratic Complexity: -
It imposes a complexity of O(n2). For N input data size, it undergoes the
order of N2 count of operations on N number of elements for solving a
given problem.
5. Factorial Complexity: -
It imposes a complexity of O(n!). For N input data size, it executes the
order of N! steps on N elements to solve a given problem.
6. Exponential Complexity: -
It imposes a complexity of O(2N), O(N!), O(nk), …. For N elements, it
will execute the order of the count of operations that is exponentially
dependable on the input data size.
BASIC TECHNIQUES FOR DESIGNING EFFICIENT
ALGORITHM
DIVIDE &
ALGORTIHM DESIGNING
CONQUER
GREEDY
TECHNIQUES METHOD
DYNAMIC
PROGRAMMING
BACKTRACKING
BRANCH AND
BOUND
BASIC TECHNIQUES FOR DESIGNING EFFICIENT
ALGORITHM
BASIC TECHNIQUES FOR DESIGNING EFFICIENT
ALGORITHM
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 sub-problems.
-Solve every sub-problem individually, recursively.
-Combine the solution of the sub-problems (top level) into a solution of
the whole original problem.
3. Solve for Constants: If the guess is correct, solve for any constants
in the solution using the initial values of the recurrence relation.
4. Verify the Solution: Finally, verify that the solution satisfies the
original recurrence relation for all values of n.
MASTER THEORREM METHOD
MASTER THEORREM METHOD
This theorem allows for quick analysis of the time complexity of many
recursive algorithms without solving the recurrence relation explicitly.
However, it's important to note that the Master Theorem can only be
applied to recurrence relations that fit its specific form. If a recurrence
doesn't match this form, alternative methods, such as substitution or
recursion tree methods, may be required for analysis.
MASTER THEORREM METHOD
This theorem allows for quick analysis of the time complexity of many
recursive algorithms without solving the recurrence relation explicitly.
However, it's important to note that the Master Theorem can only be
applied to recurrence relations that fit its specific form. If a recurrence
doesn't match this form, alternative methods, such as substitution or
recursion tree methods, may be required for analysis.
RECURRENCE TREE METHOD
Heap sort is sorting algorithm that uses a binary heap data structure to
sort elements. It has average and worst case time complexity of
O(nlogn), making it efficient for sorting large dataset.
Max Heap:- In a max heap , the value of each parent node is greater
than or equal to the value of its children . The maximum element in the
heap is located at root.
Min Heap:- In a min, the value each parent node is less than or equal to
the values of its children . The minimum is located at root.
Heap Sort Algorithm
7 MULTIPLICATIONS OF STRASSEN’S
M1=P=(A11+A22) x(B11+B22)
M2=Q=B11(A21+A22)
M3=R=A11(B12-B22)
M4=S=A22(B21-B11)
M5=T=B22(A11+A12)
M6=U=(B11+B12)(A21-A11)
M7=V=B21+B22(A12-A22)