Algorithm Algorithm Defination An Algorithm is a finite

  • Slides: 20
Download presentation
Algorithm

Algorithm

Algorithm Defination An Algorithm is a finite set of instructions that if followed accomplishes

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

Characteristics of an Algorithm Finiteness Definiteness Effectiveness Input Output

Algorithm design tools Name of the algorithm and an introductory Comment. Steps Comments Assignments

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

Name of the algorithm and an introductory Comment. LINEAR_SEARCH(A, N, KEY) [ ALGORITHM TO PERFORM LINEAR SEARCH]

COMMENTS [ ] Comments are written in brackets

COMMENTS [ ] Comments are written in brackets

Assignments Statements Dot and equal to O= Var o= 45

Assignments Statements Dot and equal to O= Var o= 45

Exit Statement Exit / finished / end

Exit Statement Exit / finished / end

Variable Name In capital Eg : - VAR 1 VAR 2

Variable Name In capital Eg : - VAR 1 VAR 2

OPERATORS LOGICAL OPERATOR (AND &&, OR ||, NOT !) RELATIONAL OPERATOR (<, >, <=,

OPERATORS LOGICAL OPERATOR (AND &&, OR ||, NOT !) RELATIONAL OPERATOR (<, >, <=, >=) ARTHEMATIC OPERATOR (+, -, *, /)

Input and Output Statements Read : VAR (SCANF() ) ---- ACCEPT DATA FROM USER

Input and Output Statements Read : VAR (SCANF() ) ---- ACCEPT DATA FROM USER Write Message (Printf() --- print data on the screen

Flow Chart

Flow Chart

Types Of algorithm Brute Force Divide and Conquer Dynamic Programming Greedy Algorithm

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

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

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; --------

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,

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+1),

Big ‘O’ Notation Provides asympostotic upper bound for a given functions Max (O(1), O(n+1), O(n^2)