# Data Structures and Algorithms/Introduction

## Algorithm definition

editAn algorithm is a set of instructions to be done sequentially. Any work to be done can be thought as series of steps. For example, to perform an experiment, one must do some sequential tasks like

- Set up the required apparatus
- Do the process required
- Note any observations
- Summarize the results

These tasks accomplish an experiment. This is a raw example of an algorithm. Let us see where such sequential steps are employed.

A computer or other electronic device which accomplishes a logic task is not actually logical but is simply following a series of programmed, sequential instructions. A computer algorithm consists of a series of well-defined steps given to the computer to follow.

## Algorithm example

editEuclid described a recursive means for determining the greatest common divisor of two numbers, say 135 and 63.

function '''gcd'''(''x, y'') if (''y'' = 0) then gcd = ''x'' else gcd = gcd(''y, x'' modulo ''y'') end {function}

Thus, gcd(135, 63) = gcd(63, 9) = gcd(9, 0) = 9. If we divide 135 by 9, the quotient is 15; while 63 divided by 9 yields 7. Since 7 and 15 have no common factors except 1, it is clear that 9 is indeed the greatest common divisor of 135 and 63. An algorithm such as **gcd** can readily be implemented as part of a computer program and may be written as source code in a variety of computer languages.

## See also

editSubject classification: this is a technology resource. |

Educational level: this is a tertiary (university) resource. |