Algorithms in data structure

An algorithm is a series of finite steps carried out in a sequence for solving a problem. In other words, an algorithm defines a series of steps that leads to some desired result.
Properties of algorithm are:
  • Finiteness: An algorithm should be terminated after finite number of steps.
  • Definiteness: Each step of the algorithm is precisely defined (e.g. if x > 10 then goto Step:5 this is well defined.
  • Generality (completeness): The rule of the algorithm is complete so that it can solve all problems of a particular type (for any input type) for which it is designed.
  • Effectiveness: All the operations used in the algorithm are basic and are capable of being performed mathematically.
For Example:
Now let us write an algorithm to find the sum of two number s X and Y:
  • Step 1: Input the values of X and Y.
  • Step 2: Calculate Sum, X+Y.
  • Step 3: Print the Result.
  • Step 4: Exit.

Complexity of an algorithm:

The complexity of an algorithm is a function f(n) which measures the time and/or space used by algorithm in terms of the input size n. To obtain the complexity of an algorithm, we generally find the following cases:
  • Worst Case: The maximum value of f(n) for any possible input.
  • Average Case: The expected value of f(n).
  • Best Case: The minimum value of f(n).

Powered by Blogger.