Introduction To Algorithms: What Is An Algorithm?
Introduction To Algorithms: What Is An Algorithm?
What is an algorithm?
An algorithm is a step by step procedure to solve a problem. In normal language, the algorithm is
defined as a sequence of statements which are used to perform a task. In computer science, an
Algorithms are used to convert our problem solution into step by step statements. These statements
can be converted into computer programming instructions which form a program. This program is
executed by a computer to produce a solution. Here, the program takes required data as input,
processes data according to the program instructions and finally produces a result as shown in the
following picture.
Specifications of Algorithms
4. Finiteness - For all different cases, the algorithm must produce result within a finite number
of steps.
5. Effectiveness - Every instruction must be basic enough to be carried out and it also must be
feasible.
Let us consider the following problem for finding the largest value in a given list of values.
Problem Statement : Find the largest number in the given list of numbers?
Input : A list of positive integer numbers. (List must contain at least one number).
Output : The largest number in the given list of positive integer numbers.
Consider the given list of numbers as 'L' (input), and the largest number as 'max' (Output).
Algorithm
2. Step 2: Compare first number (say 'x') in the list 'L' with 'max', if 'x' is larger than 'max', set
'max' to 'x'.
Recursive Algorithm
In computer science, all algorithms are implemented with programming language functions. We can
view a function as something that is invoked (called) by another function. It executes its code and
then returns control to the calling function. Here, a function can be called by itself or it may call
another function which in turn call the same function inside it is known as recursion. A recursive
The function which is called by itself is known as Direct Recursive function (or Recursive
function)
The function which calls a function and that function calls its called function is known
Most of the computer science students think that recursive is a technique useful for only a few
special problems like computing factorials, Ackermann's function, etc., This is unfortunate because
the function implemented using assignment or if-else or while or looping statements can also be
implemented using recursive functions. This recursive function is very easier to understand when