6 Programming and Data Structures
easy to solve a given problem. Every step is known as an instruction.
In our daily life we come across numerous algorithms for solving problems. We perform several
routine tasks, for example, riding a bike, lifting a phone, making a telephone call, switching on the
television, and so on.
Let us take an example. To establish a telephonic communication between two subscribers the
following steps are to be followed.
1) Dial the phone number
2) Phone rings at the called party
3) Caller waits for the response
4) Called party picks up the phone
5) Conversation begins between them
6) Release of connection
Another real life example is accessing the Internet through an Internet Service Provider with dial up
facility. To log on to the Internet the following steps are to be followed.
1) Choose the Internet Service Provider for accessing the Internet
2) Obtain from service provider a dial up number
3) Acquire IP address of the service provider
4) Acquire login ID and password
5) Run the Internet browsing software
Analyzing algorithm: When one writes an algorithm, it is essential to know how to analyze the
algorithm. Analyzing an algorithm refers to calculating or guessing resources needed for that
algorithm. Resources means computer memory, processing time, logic gates and so on. In all the
above factors, time is most important because the program developed should be faster in processing.
The analysis can also be made by reading the algorithm for logical accuracy, tracing the algorithm,
implementing it, checking with some data and with some mathematical technique to confirm its
accuracy.
Algorithms can also be expressed in a simple method. It will help the user to put it into operation
easily However, this approach has a few drawbacks. It requires more space and time. It is very
essential to consider factors such as time and space requirements of an algorithm. With minimum
system resources such as CPU time and memory, an efficient algorithm must be developed.
Rate of growth: In practice, it is not possible to act upon a simple analysis of an algorithm to conclude
the execution time of an algorithm. The execution time is dependent upon the machine and the way
of implementation. Timing analysis depends upon the input required. To accurately analyze the
time it is also very essential to know the exact directives executed by the hardware and the execution
time passed for each statement.
Classification of Algorithm s
Algorithm can be classified into three types. The classification of an algorithm is based on repetitive
steps and based on control transfer from one statement to another.
Based on repetitive steps, an algorithm can be classified into two types.
1) Direct algorithm
2) Indirect algorithm
1) Direct algorithm: In this type of algorithm the number of iterations is known in advance.
For example, for displaying numbers from 1 to 10, the loop variable should be initialized from