All About C++

Get Pure Concepts of C++

Friday 1 July 2016

Algorithm|Algorithm Properties|Advantages|Analysis

Algorithm

An algorithm is a step by step procedure to solve a problem. Steps of an algorithm are often called instructions. Process of solving any problem becomes easier with the use of Algorithm. It is better for programmer to write algorithm before writing actual computer program. Algorithms are used for calculations and data processing.

Informal definition:

An ordered sequence of instructions that is guaranteed to solve a specific problem is called algorithm.

Properties of Algorithm

Some basic properties of an algorithm are following:
·         In Algorithm, given problem should be broken down into simple and meaningful steps.
·         These steps should be numbered sequentially.
·         These steps should be descriptive and written in simple English.

Algorithm is written in a language that is similar to English language called Pseudo Code.

There is no standard is defined to write a pseudo code. It is used to specify program logic. Pseudo code simplifies program development by separating it into two main parts, which are following: 

Logic Design

Here the logic of the program is designed. In Logic Design, coder or designer specify different steps which are required to solve the problem and moreover the sequence of these steps is defined.

Coding

Here, the defined algorithm for a specific program is converted into a program. It is the work of developer, implementer or coder. Here steps of algorithm which are defined in “Logic Design” are translated into instructions of any programming language.
Use of pseudo code allows the programmer to focus on the planning of program. And when planning is final, it can be written in any programming language.

Examples of Algorithm

Example 1
In the following algorithm, we take two inputs, find their product and display the result.
1.      Start
2.      Input a
3.      Input b
4.      Product=a*b
5.      Display product
6.      Exit
Example 2
Following algorithm, calculate the sum of first fifty natural numbers.
1.      Start
2.      Sum=1
3.      N=0
4.      Repeat step 5 and 6 While (N<=50)
5.      Sum=Sum + N
6.      N=N+1
7.      Print Sum
8.      End

Example 3
Algorithm for Merge Sorting

Analysis of Algorithm

Analysis of algorithms is the area of Computer Science that provides different tools to analyze the efficiency of different methods of solutions. To compare the time efficiency of two or more algorithms to solve same problem, Naïve Approach implements these algorithms in programming language C++ and run them to compare time requirements. Comparing the programs instead of algorithms, we have difficulties as:

How are the algorithms coded?

Comparing running times of two or more algorithms means comparing implementations. We should not compare implementations because they are very sensitive to programming style that may cloud the issue of which algorithm is inherently more efficient.

What computer should we use?

We should compare the efficiency of algorithms independently of a particular computer.

What data should the program use?

Analysis must be independent of specific data.

Advantages of Algorithm

Basic advantages of algorithm are following:

Reduced Complexity

When we write an algorithm, we just focus on solving the problem and we don’t concentrate on any particular language. Writing algorithm and program separately simplifies the overall task by dividing it into two simpler tasks.

Increased Flexibility

In algorithm we know that we just define the logic to solve a problem that is we don’t follow and focus on a particular type of language or languages. It means that using an algorithm, the program can be written in any language like Java, Visual Basic or C++ etc.

Ease of Understanding

To understand the algorithm we don’t need to understand any particular programing because it is so simple like English manner. So it is very easy to understand.






No comments:

Post a Comment