A step-by-step procedure, defining set of instructions to be executed in a particular order to obtain a desired result is an Algorithm. They are usually created independent of the languages, in more than one programming languages, an algorithm can be implemented.
Some of the important categories of algorithms from data structure point of view are:
An algorithm should have the following characteristics −
There are no specific standard for writing algorithms. Algorithm completely depends on the problem and the resources. They are never written in favour of a particular programming Language.
The common code constructs like loops (do, for, while), flow-control (if-else), which are shared by all the programming languages are used to write an algorithm.
It is not mandatory that algorithms are written in a step-by-step manner. It is a process which is executed after defining the problem domain. Hence, it is essential to understand the problem domain, for which an algorithm is written.
An algorithm is written by using an example.
Problem − Design an algorithm to add two numbers and display the result.
The programmers are told by the algorithm on how to code the program. Alternatively, the algorithm can be written as −
The second method is usually used to design and analyze algorithms. The analyzing is made easy to the analysts, by ignoring the unwanted definitions. The analyst can observe the operations used and the process flow.Writing step numbers, is optional.
To get a solution of the given problem, an algorithm is designed, as a problem can be solved in more than one ways.
For a given problem, many algorithm solutions can be derived. Analyze the proposed algorithm solutions and the best suitable solution needs to be implemented.
Efficiency of an algorithm can be analyzed at two different stages, before implementation and after implementation. They are the following −
Basically the analysis of the algorithm deals with the execution or running time of various operations involved. The running time of an operation can be defined as the number of computer instructions executed per operation.
Suppose X is an algorithm and n is the size of input data, the time and space used by the algorithm X are the two main factors, which decide the efficiency of X.
The complexity of an algorithm f(n) gives the running time and/or the storage space required by the algorithm in terms of n as the size of input data.
The amount of the memory space required by an algorithm in its life cycle is represented by Space complexity. The algorithm space is measured by adding the following two components -
Space complexity S(P) of any algorithm 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 instance characteristic I. A simple example that tries to explain the concept is as follows:
It is observed that there are three variables A, B and C and one constant. Hence S(P) = 1 + 3. Now, space depends on data types of given variables and constant types and it will be multiplied accordingly.
The amount of time required by an algorithm to run till completion is represented by Time complexity. The time requirements are defined as a numerical function T(n), where T(n) can be measured as the number of steps, provided each step consumes constant time.
For instance, addition of two n-bit integers takes n steps. Consequently, the total computational time is T(n) = c ∗ n, where c is the time taken for the addition of two bits. Here, it is observed that as the size of the input increases, the T(n) grows linearly.
Data Structure & Algorithms Related Interview Questions
|RDBMS Interview Questions||DBMS Interview Questions|
|Adv Java Interview Questions||Core Java Interview Questions|
|C Interview Questions||Database Administration Interview Questions|
|CSS Advanced Interview Questions||Maven Interview Questions|
|Computer architecture Interview Questions||Object Oriented Analysis and Design Interview Questions|
|Standard Template Library (STL) Interview Questions||Xml Publisher Interview Questions|
Data Structure & Algorithms Tutorial
Data Structure & Algorithms
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.