Saturday 13 April 2019

what is an Algorithm?

what is an Algorithm?


Firstly think about algorith computer scientist Niklaus Wirths stated that
Computer program =Algorithms+Data
An algorithm is a basic part of computer programs when any one solve problem with a computer programs
then think many solution of these problems an algorithm is a good procedure for solving a problem in many steps.

it is very effective, it  means that an answer is found and it has a finite number of steps.
A well-designed algorithm will always provide an answer; it may not be the desired answer but there will be an answer. It may be
that the answer is that there is no answer. A well- designed algorithm is also guaranteed to terminate.

 Ways of Stating Algorithms
Algorithms may be represented in various ways. There are four ways of stating algorithms.
These are as follows:
1.Step-form
2.Pseudo-code
3.Flowchart
4.Nassi-Schneiderman
 An algorithm is an effective procedure for solving a problem in a fi nite number of steps.
2. A program is composed of algorithm and data.
3. The four common ways of representing an algorithm are the Step-form, Pseudo-code, Flowchart and Nassi-Schneiderman.

Key Features of an Algorithm and the Step-form
Here is an example of an algorithm, for making a pot of tea.
1. If the kettle does not contain water, then fill the kettle.
2. Plug the kettle into the power point and switch it on.
3. If the teapot is not empty, then empty the teapot.
4. Place tea leaves in the teapot.
5. If the water in the kettle is not boiling, then go to step 5.
6. Switch off the kettle.
7. Pour water from the kettle into the teapot.

Q.Write the algorithm for finding the sum of any two numbers.

Solution :Let the two numbers be A and B and let their sum be equal to C. Then, the desired algorithm is given as follows:

Q.Write the algorithm for determining the remainder of a division operation where the dividend and divisor are both integers.

Solution: Let N and D be the dividend and divisor, respectively.Assume Q to be the quotient, which is an integer, and R to be the remainder. The algorithm for the given problem is as follows.

Q.Construct the algorithm for interchanging the numeric values of two variables.

Solution: Let the two variables be A and B. Consider C to be a third variable that is used to store the value of one of the variables during the process of interchanging the values.
The algorithm for the given problem is as follows.

Q.Write an algorithm that compares two numbers and prints either the message identifying the greater number or the message stating that both numbers are equal.

Solution :This example demonstrates how the process of selection or decision making is implemented in an algorithm using the step form.Here, two variables, A and B, are assumed to represent the two numbers that are being compared. The algorithm for this problem is given as follows.

Q.Write an algorithm to check whether a number given by the user is odd or even.

Solution: Let the number to be checked be represented by N. The number N is divided by 2 to give an integer quotient, denoted by Q. If the remainder, designated as R, is zero, N is even; otherwise N is odd. This logic has been applied in the following algorithm.

Q.Print the largest number among three numbers.

Solution Let the three numbers be represented by A, B, and C. There can be three ways of solving the problem. The three algorithms, with some differences, are given below.

Q.Take three sides of a triangle as input and check whether the triangle can be drawn or not. If possible, classify the triangle as equilateral, isosceles, or scalene.

Solution: Let the length of three sides of the triangle be represented by A, B, and C. Two alternative algorithms for solving the problem are given, with explanations after each step, as follows:

Q.In an academic institution, grades have to be printed for students who appeared in the final exam. The criteria for allocating the grades against the percentage of total marks obtained are as follows.

Marks Grade Marks Grade
91–100 O 61–70 B
81–90 E 51–60 C
71–80 A <= 50 F
The percentage of total marks obtained by each student in the
final exam is to be given as input to get a printout of the grade the student is awarded.

Solution The percentage of marks obtained by a student is represented by N. The algorithm for the given problem is as follows.

Q.Construct an algorithm for incrementing the value of a variable that starts with an initial value of 1 and stops when the value becomes 5.

Solution :This problem illustrates the use of iteration or loop construct. Let the variable be represented by C. The algorithm for the said problem is given as follows.

0 comments:

Post a Comment