While designing an algorithm as a solution to a given problem, we must take care of the following five important characteristics of an algorithm:
Example: Method which is effective (to be explained later) but not definite.
The following is a program fragment for the example method:
x ← 1
Toss a coin,
If the result is Head then x ←3 else x ← 4
{In the above, the symbol ‘←’ denotes that the value on its R.H.S is assigned to the variable on its L.H.S. Detailed discussion under (i) of Section 1.6.1}
All the steps, like tossing the coin etc., can be (effectively) carried out. However, the method is not definite, as two different executions may yield different outputs.
Examples of algorithms requiring zero inputs:
The outputs have specific relation to the inputs, where the relation is defined by the algorithm.
1. Finiteness
An algorithm must terminate after a finite number of steps and further each step must be executable in finite amount of time. In order to establish a sequence of steps as an algorithm, it should be established that it terminates (in finite number of steps) on all allowed inputs.2. Definiteness (no ambiguity)
Each step of an algorithm must be precisely defined; the action to be carried out must be rigorously and unambiguously specified for each case. Through the next example, we show how an instruction may not be definite.Example: Method which is effective (to be explained later) but not definite.
The following is a program fragment for the example method:
x ← 1
Toss a coin,
If the result is Head then x ←3 else x ← 4
{In the above, the symbol ‘←’ denotes that the value on its R.H.S is assigned to the variable on its L.H.S. Detailed discussion under (i) of Section 1.6.1}
All the steps, like tossing the coin etc., can be (effectively) carried out. However, the method is not definite, as two different executions may yield different outputs.
3. Inputs
An algorithm has zero or more, but only finite, number of inputs.Examples of algorithms requiring zero inputs:
- Print the largest integer, say MAX, representable in the computer system being used.
- Print the ASCII code of each of the letter in the alphabet of the computer system being used.
- Find the sum S of the form 1+2+3+…, where S is the largest integer less than or equal to MAX defined in Example (i) above.
4. Output
An algorithm has one or more outputs. The requirement of at least one output is obviously essential, because, otherwise we cannot know the answer/solution provided by the algorithm.The outputs have specific relation to the inputs, where the relation is defined by the algorithm.
0 comments:
Post a Comment