Steps Included In building an algorithm

 

What is an Algorithm?



 

Algorithm is a very important part of computer science and programming.

Algorithms play an essential and supportive role while writing long, efficient and high quality programs.

Definition of an Algorithm

Algorithm is a step-by-step set of instructions designed to perform a specific task.

Algorithms are step by step manifestation of how the program will precede performing important operations.

Before writing a program a programmer must start with an algorithm of the program following with flowchart and pseudo code.

Purpose of Algorithm

What is an Algorithm?

Writing Algorithms of the program before start coding is a very beneficial habit in computer programming. It resolves various errors, confusion while programming for big projects.

Algorithms provide a better understanding towards programming and helps in building better problem solving logic. Algorithms help the programmer to write code faster by following steps in Algorithm.

Types of Algorithms

 

Algorithms are classified into many types according to its functionality and use. Here are some of the most important Algorithms.

 

  1. Divide and Conquer Algorithm

Divide and Conquer is an algorithm design paradigm. A Divide and conquer algorithm repeatedly breaks down a problem into-sub problems and solves the sub-problem.

The sub-problems are same or related to the original problem. The solution to the sub-problems is merged to provide solution to the original problem.

 

  1. Dynamic Programming Algorithm

Dynamic Programming is an algorithm design paradigm. It is mainly used in problems involving optimization and overlapping.

 

  1. Greedy Algorithm

Greedy Algorithm is a simple and effective algorithm. It is mainly used in problems involving optimization.

Greedy Algorithm is using whichever strategy to solve the problem that seems best.

 

  1. Backtracking Algorithm

Backtracking Algorithm is a general algorithm used for solving computational problems. It uses recursion to solve the problem.

 How to write an effective Algorithm?

 

types of algorithms

 
Step – 1 : Obtain detailed information on the problem.

It is a very important step in writing an algorithm. Before starting with an algorithm the programmer must obtain maximum information about the problem that needs to be solved.

This step will help the programmer to get a better understanding of the problem which will surely prove to be useful while solving the problem.

 

Step – 2 : Analyze the problem.

Proper Analysis of the problem must be done including the data that must be gained, processed and retrieved for generating a valid output.

This step helps the programmer with various processes that must be attained while generating the output along with structure and type of data.

 

Step – 3 : Think of a problem solving approach.

This is a very important and the most difficult step in writing an algorithm. The programmer has to come up with a problem solving approach that will help us to build the model to solve the given problem.

Experience and practice is an important factor in thinking the problem solving approach. So make sure you try writing different algorithm and reading algorithms that will assist you for better understanding.

 

Step – 4 : Review the problem solving approach and try to think of a better Alternative.

A high quality Algorithm must contain the best approach to solve a problem which will help in reducing the effort in coding as well as decrease time complexity and size of the program.

Therefore, when you think of a problem solving approach try thinking of a better alternative with better results, this will help you generate a finer programming logic.

Also review the problem solving approach, and make sure the problem will be solved through it.

 

Step – 5 : Develop a basic structure of the Algorithm.

Develop a basic structure of the problem solving approach; explain the approach step-by-step with short and effective description.

 

Step – 6 : Optimize, Improve and refine.

After developing an Algorithm try optimizing the explanation to increase readability and accessibility of it.

Also try Improving and refining the algorithm for better understanding and efficient for use.

Characteristics of a good algorithm

  1. Input and Output must be specified

An Input is the data transferred by the user to the program to produce certain output.

An Algorithm can have 0 to more inputs from the user. If Inputs must be taken from user the details of the data must be specified in the algorithm.

An Output is the data transferred by the program to the user results the computations.

An Algorithm must have at least 1 well-defined and desired output.

 

  1. All important steps must be mentioned

An Algorithm comprises of all short step-by-step processes that is performed in a program, thus every important step must be present in the Algorithm in considerate details.

The steps mentioned in an algorithm must lack grammatical mistakes to avoid misunderstanding and confusion. 

 

  1. Instructions must be perfectly ordered

An Algorithm is a very important step in programming thus, it must be perfectly ordered to lack severe errors and confusion while coding.

An Algorithm helps and supports a programmer while coding to avoid errors, therefore a well ordered algorithm will provide better assistance.

 

  1. Short and effective descriptions

An Algorithm must contain short but effective description of the process meant to be conducted, to increase reliability and efficiency of it.

 

  1. The Algorithm must contain finite number of steps

An Algorithm must conclude after performing certain operation and generating an output. The loops mentioned in the algorithm must terminate after performing the operations.

The Algorithm must contain finite amount of steps to generate a valid output.


THE IMPORTANCE OF KNOWING ALGORITHMS

As a computer scientist, it is important to understand all of these types of algorithms so that one can use them properly. If you are working on an important piece of software, you will likely need to be able to estimate how fast it is going to run. Such an estimate will be less accurate without an understanding of runtime analysis. Furthermore, you need to understand the details of the algorithms involved so that you’ll be able to predict if there are special cases in which the software won’t work quickly, or if it will produce unacceptable results.

Of course, there are often times when you’ll run across a problem that has not been previously studied. In these cases, you have to come up with a new algorithm, or apply an old algorithm in a new way. The more you know about algorithms in this case, the better your chances are of finding a good way to solve the problem. In many cases, a new problem can be reduced to an old problem without too much effort, but you will need to have a fundamental understanding of the old problem in order to do this.

As an example of this, lets consider what a switch does on the Internet. A switch has N cables plugged into it, and receives packets of data coming in from the cables. The switch has to first analyze the packets, and then send them back out on the correct cables. A switch, like a computer, is run by a clock with discrete steps – the packets are send out at discrete intervals, rather than continuously. In a fast switch, we want to send out as many packets as possible during each interval so they don’t stack up and get dropped. The goal of the algorithm we want to develop is to send out as many packets as possible during each interval, and also to send them out so that the ones that arrived earlier get sent out earlier. In this case it turns out that an algorithm for a problem that is known as “stable matching” is directly applicable to our problem, though at first glance this relationship seems unlikely. Only through pre-existing algorithmic knowledge and understanding can such a relationship be discovered.

Examples of Algorithms

 
1. Addition of two numbers (numbers are entered by user)
Step 1: Start.
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values of num1 and num2.
Step 4: Add the values of num1 and num2 and assign the result to variable sum.
Step 5: Display sum
Step 6: End
  1. Comparison of 3 numbers to find the largest number
Step 1: Start.
Step 2: Declare variables num1, num2 and num3.
Step 3: Read values of num1, num2 and num3.
Step 4: Compare num1, num2 and num3
If num1 > num2
            If num1 > num3
                        Display num1 is the largest number
            Else
                        Display num2 is the largest number
Else
            If num2 > num3
                        Display num2 is the largest number
            Else
                        Display num3 is the largest number
Step 5: Display sum
Step 6: End
  1. Display Fibonacci series till the number 100
Step 1: Start.
Step 2: Declare variables i and initialize to 1
Step 3: Iterate i from 1101 and display i simultaneously
While i < 100
            Display i
            i = i +1
Step 6: End


CONCLUSION

The different algorithms that people study are as varied as the problems that they solve. However, chances are good that the problem you are trying to solve is similar to another problem in some respects. By developing a good understanding of a large range of algorithms, you will be able to choose the right one for a problem and apply it properly. Furthermore, solving problems like those found in TopCoder’s competitions will help you to hone your skills in this respect. Many of the problems, though they may not seem realistic, require the same set of algorithmic knowledge that comes up every day in the real world.





Comments

Post a Comment