Algorithm Algorithm is a step-by-step procedure or formula or set of instruction for solving a problem Its written in English language or natural language Characteristic of Algorithm It has finite number of inputs It terminates aft6er a finite number of steps Instruction are precise and unambiguous Operation specified can be done exactly and in finite amount of time There might be multiple input for a single output
Factor which determines Quality of Algorithm: Algorithm should be relative fast (number of steps to be minimum) Cost consideration for implementation should be minimum
Pseudocode It is an Intermediate code Pseudo – Imitation & code – set of instruction written in programming language It emphasize the design aspects of computer program Pseudocode is also called as PDL (Program Design Language) half between English and programming language
Pseudocode Keywords Input – Read, Prompt and obtain Initialize - Set, Initialize Output – Display , Print Add one - increment
Flowcharts flowchart is a diagrammatic representation of an algorithm It illustrates the sequence of operations to be performed to get the solution of a problem It is a blue print
Flow chart symbols
Guidelines for flow chart `requirement should be in logical order It should clear, neat and easy to follow Direction (left to right, top to bottom) It should have logical start and end To reduce the flow line usage of connector is important Intersection of flow line should be avoided In process symbol only one flow line should come out of it And only one flow line should enter the decision box Only one flow line should be used in conjunction with terminal symbol
Advantages Communication Makes logic easier Effective analysis Proper documentation Efficient coding Proper debugging and testing Efficient program maintenance
Limitations Complex logic Alteration and modification Reproduction – design Cost and time factor No updating
Example Algorithm and flowchart Example . Design an algorithm and the corresponding flowchart for adding the test scores as given below: 26, 49, 98, 87, 62, 75
Algorithm Step 1. Start Step 2. Sum = 0 Step 3. Get the first testscore Step 4. Add first testscore to sum Step 5. Get the second testscore Step 6. Add to sum Step 7. Get the third testscore Step 8. Add to sum
Algorithm Step 9. Get the Forth testscore Step 10. Add to sum Step 11. Get the fifth testscore Step 12. Add to sum Step 13. Get the sixth testscore Step 14. Add to sum Step 15. Output the sum Step 16. Stop
Flow chart
Flowchart