The document discusses algorithms as step-by-step methods for problem-solving in programming. It emphasizes the importance of measuring an algorithm's efficiency based on resource usage, such as time and memory. Two algorithms are provided as examples: one for calculating the sum, product, and average of five numbers, and another for finding the largest of three unequal numbers.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
3 views
Algorithms
The document discusses algorithms as step-by-step methods for problem-solving in programming. It emphasizes the importance of measuring an algorithm's efficiency based on resource usage, such as time and memory. Two algorithms are provided as examples: one for calculating the sum, product, and average of five numbers, and another for finding the largest of three unequal numbers.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3
CHAPTER #1:
PROGRAMMING TECHNIQUES ALGORITHMS Algorithm means step by step method, procedure, technique or plan that clearly defines a sequence of operations to understand or to follow.
ROLE OF ALGORITHM IN PROBLEM SOLVING
It plays an important role in computer programming in which a programmer taking an algorithms and coding it in programming language.
Measuring Efficiency of an Algorithm:
Property of algorithm relate to computational resources Resources usage (Time, memory space) Should be high speed with minimum memory usage Should choose an algorithm according to its efficiency Q1. Write an Algorithm to find the sum, product and average of five given numbers.
Planning The Solution:
Input: five given numbers Required Output: Sum, Product and average of five numbers Processing: Addition, multiplication and Division of numbers Algorithm: Step 1: Start Let the five numbers be A=2, B=5, C=8, D=4, E=12 Step 2: Find the sum(sum) Sum=A+B+C+D+E Step 3: Find the product (prod) PROD=A*B*C*D*E Step 4: Find the Average(AVG) AVG=SUM/5 Step 5: Output SUM, PROD, AVG Step 6: Stop Q2. Write an algorithm to find the largest of three unequal numbers.
Planning the Solution:
Input: Three unequal numbers Required Output: The largest of three numbers Processing: Comparison of each number with the other two numbers one by one Algorithm: Step 1: Start Let the three numbers be A=10, B=20, C=30 Step 2: Check if A is the largest number IF A>B and A>C THEN LARGEST=A otherwise GOTO step 4 Step 3: GOTO STEP 7 Step 4: Check if B is the largest number IF B>A and B>C THEN LARGEST=B otherwise GOTO step 6 Step 5: GOTO Step 7 Step 6: LARGEST=C Step 7: Output LARGEST Step 8: Stop