Algorithm
Algorithm Defination An Algorithm is a finite set of instructions that if followed accomplishes a particular task.
Characteristics of an Algorithm Finiteness Definiteness Effectiveness Input Output
Algorithm design tools Name of the algorithm and an introductory Comment. Steps Comments Assignments Statements Exit Statement Variable Name Operators Input and Output Statements Flow Chart
Name of the algorithm and an introductory Comment. LINEAR_SEARCH(A,N,KEY) [ ALGORITHM TO PERFORM LINEAR SEARCH]
Steps 1. …….. 2…….. 3…….
COMMENTS [ ] Comments are written in brackets
Assignments Statements Dot and equal to O= Var o= 45
Exit Statement Exit / finished / end
Variable Name In capital Eg :- VAR1 VAR2
OPERATORS LOGICAL OPERATOR (AND &&,OR ||,NOT !) RELATIONAL OPERATOR (<,>,<=,>=) ARTHEMATIC OPERATOR (+,-,*,/)
Input and Output Statements Read : VAR (SCANF() ) ---- ACCEPT DATA FROM USER Write Message (Printf() --- print data on the screen
Flow Chart
Types Of algorithm Brute Force Divide and Conquer Dynamic Programming Greedy Algorithm
Performance Analysis Space Complexity It is the amount of memory required for that particular algorithm. Time Complexity Deals with the computing time.
Space Complexity. void main() { int a; float b,c; c = a+b; printf(“Result = %d”,c) } Space Required = 2+4+4 = 10 bytes.
Time Complexity void main() { int a; --------------- 1 float b,c; --------------- 1 c = a+b; --------------- 1 printf(“Result = %d”,c); ---- 1 } Total Frequency count = 1+1+1+1 = 4
Time Complexity void main() { int a,n; --------------- 1 float b,c; --------------- 1 n = 3 for(i=0;i<=n;i++) --------- n c = a+b+i; --------------- n printf(“Result = %d”,c); ---- n } Total Frequency count = 1+1+n+n+n = 11
Big ‘O’ Notation Provides asympostotic upper bound for a given functions Max (O(1),O(n),O(n+1),O(n^2)