• An algorithm is a step by step process to solve a problem using a finite number of steps. Algorithms are used in mathematical computing etc to carry out calculations or data processing.
• The algorithm is developed using pseudocode.
• Pseudocode: It is an artificial and informal language that helps programmers to develop algorithms.
• Pseudocode programs are not executed on computers but they are used in developing algorithms.
The algorithms must satisfy the following properties
Properties of Algorithms
• Input – the algorithm must accept zero or more inputs.
• Output - must produce at least one output.
• Definiteness -Each instruction is clear.
• Finiteness -An algorithm should terminate after a finite number of steps. It should not enter into an infinite loop.
• Effectiveness – Each operation must be simple and should complete in a finite time algorithm: examples of algorithms:
1.Addition of two numbers
Step 1: Start
Step 2: Declare variables num1, num2, and sum.
Step 3: Read values into num1 and num2.
Step 4: sum = num1+num2
Step 5: print sum
Step 6: Stop
2.Algorithm: Area of a circle
Step 1: Start
Step 2: Declare variables radius and Area
Step 3: Read value into the radius
Step 4: Area = 3.14*radius*radius
Step 5: print Area
Step 6: Stop
3.Algorithm: Largest among 3 numbers
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a > b
If a > c
Display a is the largest number.
Else
Display c is the largest number.
Else
If b > c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop
4.Algorithm to print "n" natural numbers
Step 1: Start
Step 2: Declare n, i
Step 3: Assign i=1
Step 4: Read value into n
Step 5: Repeat step 5.1 and 5.2 until i<=n
5.1 Print i
5.2 Compute i=i+1
Step 7: Stop
5.Algorithm to sum "n" natural numbers
Step 1: Start
Step 2: Declare variables n, sum and i.
Step 3: Initialize variables or Assign
sum = 0
i = 1
Step 4: Read value into n
Step 5: Repeat 5.1 and 5.2 until i <= n
5.1 : sum = sum+i
5.2 : i = i+1
Step 6: Display sum
Step 7: Stop
Comments
Post a Comment