ALGORITHM ESSENTIALS

The algorithm is a step-by – step procedure that specifies a series of instructions to be performed to obtain the desired output in a certain order. Algorithms are usually generated in more than one programming language, regardless of the underlying languages , i.e. an algorithm can be implemented.

From the data structure point of view, following are some important categories of algorithms:

  • Search − Algorithm to search an item in a data structure.
  • Sort − Algorithm to sort items in a certain order.
  • Insert − Algorithm to insert item in a data structure.
  • Update − Algorithm to update an existing item in a data structure.
  • Delete − Algorithm to delete an existing item from a data structure.

Algorithm Complexity

If X is an algorithm and n is the input data size, the time and space used by the X algorithm are the two key factors that determine X ‘s performance.

Time Factor: Time is calculated by counting the number of main operations in the sorting algorithm, such as comparisons.

Space Factor: Space is determined by counting the algorithm’s maximum memory space available.

1.    Space Complexity

The complexity of an algorithm f(n) gives the algorithm’s necessary runtime and/or storage space in terms of n as the input data size.

The algorithm’s space complexity reflects the amount of memory space needed by the algorithm throughout its life cycle. The space needed by an algorithm is equal to the sum of the two components that follow,

A fixed component that is a space needed to store some information and variables that is independent of the problem’s size. Easy variables and constants, for instance, used, programme size, etc.

A part of a variable is the space needed by variables, the size of which depends on the problem’s size. For instance, allocating dynamic memory, recursion stack space, etc.

In any algorithm P, space complexity S(P) is S(P) = C + SP(I), where C is the fixed part and S(I) is the variable part of the algorithm, which depends on the characteristic of instance I. Here is a brief example that helps to illustrate the notion:

2.    Time Complexity

An algorithm’s time complexity reflects the amount of time needed for the algorithm to run to completion. Time requirements can be defined as a T(n) numeric function, where T(n) can be calculated as the number of steps, given that constant time is consumed by each step.

For instance, n steps are used to add two n-bit integers. Therefore, the total computational time is T(n) = c * n, where c is the time taken for two bits to be inserted. Here, as the input size increases, we note that T(n) grows linearly.