2. ๏ผ An algorithm is finite set of instructions which is followed, accomplish
particular task or it is a sequential steps of instruction of programs.
๏ผ An algorithm is a sequence of computational steps that transform the input
into the output.
๏ผ An algorithm is sequence of operations performed on data that have to be
organized in data structure.
3. Every algorithm must satisfy the following criteria-
1. Input- There are zero or more quantities which are externally
supplied.
2. Output โ At least one quantity is produced.
3. Definiteness โ Each instruction must be clear and easy to understand.
4. Finiteness- Algorithm will terminate after finite number of steps.
5. Effectiveness- Every instruction must be roughly work out using
pencil and paper. More effectively generated.
4. ๏ฝ This is the technique to measure the performance of algorithm.
๏ฝ It provides user friendliness, security, maintainability and usage
space that determines the quality of algorithm.
๏ฝ Efficiency of algorithm can be analysis at two different stages
before implementation and after implementation.
๏ฝ Algorithm analysis deals with execution running time of various
operations are involved.
๏ฝ The running time of an operations can be defined as number of
computer instructions executed per operations.
5. ๏ฝ 1. Priori analysis-
This is the theoretical analysis of algorithm before
implementation. Efficiency of algorithm measured by speed,
constant have no effects on implementation.
๏ฝ 2. Posterior analysis-
The selected algorithm implemented using programming
language. This is executed on target computer machine. In this
analysis actual statistics like running time and space calculated after
implementation.
6. ๏ผ Algorithms help us to understand scalability.
๏ผ Performance often draws the line between what is feasible and what is impossible.
๏ผ Algorithmic mathematics provides a language for talking about program behavior.
๏ผ The lessons of program performance generalize to other computing resources.
๏ผ Modularity, Correctness, Maintainability, Correctness, Robustness, User
friendliness, Programming time, Simplicity, Reliability etc. Its important for good
performance.
7. 1. Time complexity-
๏ผ This is a function describing the amount of time an algorithm takes in
terms of amount of input to the algorithm.
๏ผ Time can means no. of comparisons between data types, inner loops are
executed.
๏ผ Time also can be calculated which language, hardware, program or
compiler is used.
๏ผ Time complexity = Compile time + Run or Execution Time.
8. 2. Space Complexity-
๏ผ Space complexity of an algorithm represents amount of memory space
required by the algorithm in its life cycle.
๏ผ Two types of spaces are required-
๏ง Fixed part- It required to store certain data and variables that are
independent size of problem. For e.g. Constants, Program size etc.
๏ง Variable part- It required by variables whose size depends on size of
problem. For e.g. Dynamic memory allocation.
9. ๏ฝ Algorithm: SUM(A,B)
Step 1 - START
Step 2 - C <- A+B+10
Step 3 โ Stop 1
๏ผ Space complexity S(P) of any algorithm P is S(P) = C+SP(I). Where, C is
fixed part and S(I) is variable part of algorithm.
๏ผ There are three variables A,B,C and Constant.
๏ผ Space depends on data types of given variables and constant types of data.
10. Asymptotic analysis of an algorithm refers to define the mathematical
foundation of its run time performance. For this purpose we used Best,
Average and Worst cases.
๏ฑ Asymptotic Notations-
1. Big O Notation, O โ
The notation O(n) is the way to express the upper bound of an algorithm
running time. Its measure the worst case time complexity or longest
amount of time an algorithm can possibly take to complete.
f(n) (- O(g(n))
11. 2. Omega Notation, ฮฉ โ
The notation ฮฉ(n) is the way to express lower bound of an algorithm running
time. It measure the best case time or minimum amount of time an algorithm
can possible take to complete.
f(n) (- ฮฉ(g(n))
3. Theta Notation, ฮธ โ
The notation ฮธ(n) is the formal way to express both the lower bound and
upper bound of an algorithm running time can possible take to complete.
f(n) (- ฮธ(g(n))
12.
13. 1. Best case analysis-
Best case is that input to the algorithm which takes minimum time for
execution of it.
Example - Binary Search algorithm
1 2 3 4 5 6 7 8 9
Best case to search element at first position.
It required O(1) time.
14. 2. Average case analysis-
For average case analysis all possible sequence of size โnโ are input to the
algorithm and average asymptotic time of algorithm is computed.
Example - Binary Search algorithm
1 2 3 4 5 6 7 8 9
All elements of sorted array of size โnโ are searched one by one and total
number of comparisons are computed.
Average computation time = Total time/2.
It requires O(log n) time.
15. 3. Worst case analysis-
Worst case is that input to the algorithm which takes maximum time for
execution of it.
Example - Binary Search algorithm
1 2 3 4 5 6 7 8 9
Worst case search the last element of the list in O(n) time is required. If the
element is absent then O(log n) time is required.
16. Input
1 ms
2 ms
3 ms
4 ms
5 ms
A B C D E F G
worst-case
best-case
}average-case?
17. 1. O(1) โ Constant eg. Doing a null check
2. O(n) โ Logarithmic eg. Searching sorted data
3. O(n) โ Linear eg. Adding values in data set
4. O(n log n) โ Linearithmic eg. Quick sort
5. O(n2) โ Quadratic eg. Two nested loops
6. O(n^k) โ Polynomial eg. Calculations of polynomials
7. O(2n) โ Exponential eg. Brute force attacking a password
8. O(n!) โ Factorial eg. Calculate Fibonacci series
18.
19. The key take away here is that if you are working with large
datasets you need to be careful when selecting proper data
structure, algorithms you use.