- Related Questions & Answers
- Huffman Algorithm for t-ary Trees in Data Structure
- Algorithm to construct an Expression Tree in Data Structure
- Yen's k-Shortest Path Algorithm in Data Structure
- Data Over Cable Service Interface Specification (DOCSIS)
- Floyd Cycle Detection Algorithm to detect the cycle in a linear Data Structure
- Rectangle Data in Data Structure
- Halfedge data structure
- Deaps in Data Structure
- Quadtrees in Data Structure
- Display Java Specification Version
- Arrays Data Structure in Javascript
- Stack Data Structure in Javascript
- Graph Data Structure in Javascript
- Queue Data Structure in Javascript
- Set Data Structure in Javascript

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

An algorithm is defined as a finite set of instructions that, if followed, performs a particular task. All algorithms must satisfy the following criteria

Input. An algorithm has zero or more inputs, taken or collected from a specified set of objects.

Output. An algorithm has one or more outputs having a specific relation to the inputs.

Definiteness. Each step must be clearly defined; Each instruction must be clear and unambiguous.

Finiteness. The algorithm must always finish or terminate after a finite number of steps.

Effectiveness. All operations to be accomplished must be sufficiently basic that they can be done exactly and in finite length.

We can depict an algorithm in many ways.

- Natural language: implement a natural language like English
- Flow charts: Graphic representations denoted flowcharts, only if the algorithm is small and simple.
- Pseudo code: This pseudo code skips most issues of ambiguity; no particularity regarding syntax programming language.

Example 1: Algorithm for calculating factorial value of a number

Step 1: a number n is inputted Step 2: variable final is set as 1 Step 3: final<= final * n Step 4: decrease n Step 5: verify if n is equal to 0 Step 6: if n is equal to zero, goto step 8 (break out of loop) Step 7: else goto step 3 Step 8: the result final is printed

A recursive algorithm calls itself which generally passes the return value as a parameter to the algorithm again. This parameter indicates the input while the return value indicates the output.

Recursive algorithm is defined as a method of simplification that divides the problem into sub-problems of the same nature. The result of one recursion is treated as the input for the next recursion. The repletion is in the self-similar fashion manner. The algorithm calls itself with smaller input values and obtains the results by simply accomplishing the operations on these smaller values. Generation of factorial, Fibonacci number series are denoted as the examples of recursive algorithms.

Example: Writing factorial function using recursion

intfactorialA(int n) { return n * factorialA(n-1); }

Advertisements