3.2 PROBLEM, ALGORITHM, PROGRAM AND PROGRAMMING LANGUAGE
A Problem is to carry out a particular task. For solving the problem, some input has to be given to the system. The system will process or manipulate the input and produce the desired output. An algorithm describes the steps required to solve a problem. Once an algorithm is obtained for solving a problem, a Program has to be written which a computer can execute so as to accomplish the given task, thereby solving the problem at hand. The program can be in any suitable programming language and is not dependent on the algorithm in any way.
Algorithm: Once a problem has been defined precisely, a procedure or process must be designed to produce the required output from the given input. Since a computer is a machine that does not possess problem-solving judgmental capabilities, this procedure must be designed as a sequence of simple and unambiguous steps. Such a procedure is known as an algorithm.
The steps that comprise an algorithm must be organized in a logical, clear manner so that the program that implements this algorithm is similarly well structured. Number of steps in the algorithm should be finite, they should be executed in finite amount of time and they should give the desired output. Algorithms are designed using three basic methods of control:
a) Sequential : Steps are performed in a strictly sequential manner, each step being executed exactly once.
b) Decision/Selection : One of several alternative actions is selected and executed.
c) Repetition : One or more steps is performed repeatedly.
Any algorithm can be constructed using basic methods of control.
Programs to implement algorithms on the computer must be written in a language that the computer can understand. It is fruitful, therefore, to describe algorithms in a language that resembles the language used to write computer programs. This is called pseudo code. It is not a programming language with a rigid syntax, but is similar to one. The idea is that it should be easy to write a program by looking at the pseudo code..
Let us take few problems to illustrate how to express the solution to a problem in the form of an algorithm. We will also see how algorithm can be diagrammatically represented using flow chart, and also how a program can be written based on the algorithm.
For providing a solution to any problem some input from the user is required. In the following examples the number n that is expected from the user should be an integer. In the program, it will be declared of the required type only, referred as data type of the variable. A Detailed description of variable and data type is given in a later section.
Flowcharting: A Flowchart is a graphical representation of an algorithm. It can be compared to the blueprint of a building. Just as a building contractor refers to a blueprint for the construction of a building, similarly a programmer refers to a flowchart for writing the program which describes what operations are to be carried out and in what sequence to solve a problem. Flowcharts are usually drawn using some standard symbols. The Basic flowchart symbols are as below:

Comments
Post a Comment