Data Structures and Algorithms/Introduction

From Wikiversity
Jump to navigation Jump to search

Algorithm definition[edit | edit source]

An 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

  1. Set up the required apparatus
  2. Do the process required
  3. Note any observations
  4. 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[edit | edit source]

Euclid 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[edit | edit source]

Subject classification: this is a technology resource.
Educational level: this is a tertiary (university) resource.

Wikiversity:About Programming