Professional Documents
Culture Documents
Contents:
Entire PPT is divided into 13 modules:
Introduction 30 - 35 sec Definition of an Algorithm 1 - 1.2 min Criteria that an Algo must Satisfy 1 - 1.4 min Structure of a Standard Algo 1 - 1.1 min Rules of Writing an Algo ~ 1 min Various Symbol Meaning 30 - 35 sec Different Methods of Writing Algo 1 - 1.2 min Examples of Algorithm 1 - 1.5 min Space & Time Complexity of an Algo ~ 2 min Needs of Writing an Algo 45 - 55 sec Algo-Translater 3 - 5 min Algo Simulation & Conclusion References Questions ~ 2 min _________________________________________________
14 January 2012
Total ~ 15 min
14 January 2012
Definition of an Algorithm
According to Brent Daviduck of the Computer Systems Technology program at Red Deer College in Alberta, Canada, an algorithm is a Canada, sequence of instructions that are a fundamental part of computing. Another definition taken from Wikipedia, the free encyclopedia is "an algorithm is a computer program that calculates something. something. Thus a standard definition of an algorithm can be stated as: An algorithm is a step-wise method / stepprocedure to perform a specific desired task. task. The time & spaces it uses are 2 major measures of its efficiency. The complexity of an algorithm is the function which gives the running time or space in terms of the input size.
14 January 2012
Input - Zero or more quantities are externally supplied. supplied. Output - At least one quantity is produced at output. output. Effectiveness - All the statements of algorithm are clear and terminate only after a finite no. of steps. steps. Low space & time complexity- When complexityimplemented in real life, they should occupy optimal memory space & must save time. time. Datatype- An algorithm cannot contain Datatypedatatype of variables to be used into it. it. For e.g.: we cannot write Read int a,b. Here datatype int is explicitly mentioned.
5
14 January 2012
For e.g.:
If we are writing a program of printing a message on output screen, the syntax will be different for c, c++ & java.
In c, we can write: printf(\n PROGRAMMING IN C IS printf(\ FUN!); In c++, we can write: cout<<endl<<PROGRAMMING IN C++ IS FUN!; In java, we can write: System.out.println(PROGRAMMING IN JAVA IS FUN!);
However, there are no set of specific rules for writing an algorithm till date. We can write them according to our convenience in any format & style.
14 January 2012 6
First step is always start. start. Stop is used to terminate algorithm. Statements are not case-sensitive. e.g.: Read casee.g.: a & b is similar to READ A & B. Read is a function which is used to read value of variables from user. e.g.: READ A,B,C. e.g.: Write is a function which is used to write message or print value of a variable. e.g. WRITE: WRITING AN ALGO IS FUN! or WRITE C. IS THEN is used to check conditions. e.g: IS a > b, THEN: SET max := a, ELSE: SET max := b. Repeat is a function which is used to define a set of statements in a loop body. e.g.: REPEAT steps e.g.: 3-4, WHILE: SUM =/= 0.
7
14 January 2012
Symbol Meaning
In Standard algorithm, meaning of various symbols is:
== =/=
Equals Not Equals Less than Greater than Less than or equals to Greater than or equals to
In practice, the computer is presented not with a true/false statement, but with a question having a "Yes" or "No" answer, for example if A = 10, B = 20, K = 5, and SALES = 10000, then: Condition (Question) "Answer" Is A == B? No Is B > A? Yes Is K <= 25? Yes Is SALES >= $5000.00? Yes
14 January 2012 8
METHOD 2:~
STEP 0: START 0: STEP 1: GET MESSAGE 1: STEP 2: PRINT MESSAGE 2: STEP 3: RETURN 3:
METHOD 3:~
STEP 1 # Start processing. STEP 2 # Read a message from user. STEP 3 # Save this message in a temporary variable. STEP 4 # Retrieve this message from temporary variable. Retrieve STEP 5 # Print this message on output screen. Print STEP 6 # Terminate process & return. return. And so on
14 January 2012 9
Examples of Algorithm
Let us Now write algo of some specific programs using standard rules stated above: Example 1: If we are desired to write a program in c programming language whose output is simply addition of 2 variables, then we simply write: main () /*User defined function*/ /*User function*/ { int a,b,c; a,b,c; /*Declaration of variables */ /*Declaration printf(\ printf(\n ENTER values of a & b: ); /*Function to print on dos screen*/ /*Function screen*/ scanf(%d%d,&a,&b); scanf(%d%d,&a,&b); /* Function to read input from dos screen */ c=a+b /* Statement to assign value of (a + b) into (c) */ printf(\ printf(\n ADDITION of a & b is: %d,c); %d,c); } Now, let us write algo. of above program algo. STEP 1: START STEP 2: READ A& B [Step corresponding to scanf()] scanf()] STEP 3: SET C := A + B [Step corresponding to c = a + b] b] STEP 4: WRITE C [Step corresponding to printf()] printf()] STEP5: STOP
14 January 2012 10
Example 2: Program to find largest out of 2 numbers. 2: main() { int a,b; printf(\ printf(\n ENTER value of a & b: ); scanf(%d%d,&a,&b); scanf(%d%d,&a,&b); if (a > b) printf(\ printf(\n a is greater than b); b); else if (b > a) printf(\ printf(\n b is greater than a); a); else printf(\ printf(\n a & b are equal); equal); } Corresponding algorithm can be written as: STEP 1: START 1: STEP 2: READ A& B 2: [Step corresponding to scanf()] scanf()] STEP 3: IS A > B, THEN: WRITE: A IS GREATER B, 3: B, ELSE IF: B > A, THEN: WRITE: B IS GREATER THAN A, THEN: WRITE: A, ELSE: WRITE: A & B ARE EQUAL WRITE: [Step corresponding to if else] else] STEP 4: STOP 4:
14 January 2012
11
TIME COMPEXITY: This measure is used to estimate COMPEXITY: running time of algorithm in terms of size of input data. SPACE COMPLEXITY: This measure is used to COMPLEXITY: define extra space consumed by the algorithm except input data.
Space & Time Complexity are important parameters of an algorithm in deciding its efficiency. There are 3 popular notations to calculate Space & Time Complexity:
Big Oh Notation (O) It measures the upper bound of a function. Omega Notation (Omega) - It measures the lower bound of a function. Theta Notation (Theta) It measures in between bound of a function i.e. between upper & lower bound of a function.
14 January 2012
12
14 January 2012
For e.g.: If user write an algo of adding 2 integers in algodecoder IDE: Step1: Step1: Start Step2: Step2: Read a,b Step3: Step3: Set c := a + b Step4: Step4: Write c. Step5: Step5: Stop then corresponding code generated will be: main() { int a,b,c; scanf(%d%d,&a,&b); c = a + b; printf(%d,c); } in c programming language. void main() { int a,b,c; cin>>endl>>a>>b; c = a + b; cout<<c; } in c++.
14 January 2012
15
14 January 2012
16
References
Wikipedia, Wikipedia, the free encyclopedia. Brent Daviduck of the Computer Systems Technology program at Red Deer College in Alberta, Canada.( http://cst.rdc.ab.ca/) Schaum's Outline of Theory and Problems of Essential Computer Mathematics, by Dr. Seymour Lipshutz, McGraw-Hill, Inc., ISBN: Lipshutz, McGraw0-07-037990-4 Chapter 5 Algorithms 07-037990Boolos & Jeffrey 1974, 1999, p. 19. whatis.techtarget.com/definition/0,,sid9_gci21 1545,00.html www.nist.gov/dads/HTML/algorithm www.wisegeek.com/what-is-anwww.wisegeek.com/what-is-an-algorithm.htm
14 January 2012
17
Thank You
For Your Patient Listening
Questions ???
14 January 2012
18