- An algorithm named for the ninth century Persian mathematician Al-Khowarizmi is simply set of rules used to perform some calculations either by manually or by machine.
- Algorithm: The algorithm is defined as a collection of unambiguous instructions occurring in some specific and such an algorithm should produce output for given set of input in finite amount of time.
Properties of Algorithm:
1. Non ambiguity:Each step in the algorithm should be unambiguous.That means each instruction should be clear and precise.This property also indicate the effectiveness of algorithm.
2. Range of input:
It should be specified.This is because normally the algorithm is input driven and if the range of input is not been specified then algorithm can go in infinite state.
3. Multiplicity:
Same algorithm can be represented in several different ways.For solving the same problem we can write several different algorithms for example to search any number we can use binary search,sequential search etc…
4. Speed:
The algorithm can be written using some specific ideas but such algorithm should be efficient and should produce the output with fast speed.
5. Finiteness:
The algorithm should be finite.It means after performing required operations it should terminate.Solving A Problem With A Computer Following steps are required:
1) Statement of the problem or the problem definition.2) Development of model.
3) Design of algorithm.
4) Checking the correctness of algorithm.
5) Implementation in some programming language.
6) Analysis and study of complexity of the algorithm.
7) Program testing – debugging.
8) Preparation of documents.
Statement of the problem or the problem definition
- Initially we have to understand the clearly the requirements of particular problem.At this stage we have to decide what must be done. Having a proper problem statement require to asking the right questions like:
- Do we understand the vocabulary used in the row statement of the problem?
- What information is given?
- What is to be found out?
- How to recognize a valid solution?
- What information is requiring defining an algorithm is missing?
- Is any part of the information worthless?
- What assumptions have been made?
Development of model.
- Develop a mathematical model where calculations can be done. There are no definite rules for this step, and this is when the art of programming comes in. still there are two basic questions that can be answered:
2) Are there other problems that have been solved, which resemble this one? Some of the general problem solving strategies which are available like: Divide-and-Conquer. Binary doubling. Dynamic programming. Greedy search, back tracking and branch and bound.
Divide-and-Conquer
Most widely known and used strategy, where the basic idea is to be break down in to two or more sub-problems which are easier and more efficient to solve.
Binary doubling
This is the reverse of the Divide-and-Conquer strategy, that is built-up the solution for a large problem from solutions of the sub-problem.
Dynamic programming
This strategy can be useful when we can built-up the solution as a sequence of immediate steps. (e.g.: Traveling Salesman Problem)
Greedy search, back tracking and branch and bound.
All of these are variant of the basic dynamic programming strategy.
Design of algorithm
- Various issues which arise in the design of algorithm:
- Design approach depends mainly on the model chosen.
- There can be more then one algorithms to solve the same problem.
- The choice between them can be decided by their effectiveness
- One of the difficult but essential task in algorithm development is providing it’s correctness. One possible method is to run a number of data sets as inputs and compare the result again the manually calculated. This is not sufficient. Therefore let us consider one possible way to prove correctness which is especially applicable to the algorithm having series of steps. Try to justify each step. This may involve some condition before and after the step is executed.
Implementation in some programming language.
- This can be straightforward and difficult task, depending upon how clearly the algorithm is written and the programming strategy adopted, including the language chosen.
- The major difficulty is that we must design a data structure to represent the important information held with the algorithm. To do this follow this things:
- What are the variables?
- What are their types?
- How many arrays are required and what is their size?
- Is it requiring using link list for some data?
- Which function and procedure are needed?
- Which programming language will support this data structure?
- Method of implementations will affect the memory requirement and speed of program execution.
- Following are the programming methodologies used:
- Top-Down Programming: languages like C, C++, JAVA, FORTRAN
- Object-Oriented Programming: languages like C++, JAVA, VB, C#.Net
- If the algorithm is incorrect, the program can never be correct.
Analysis and study of complexity of the algorithm.
- Practical Reason for performing an algorithm analysis are:
- Need to know the maximum time to execution and storage requirements.
- Tends to locate an algorithm fragment where a computer is like to spend most of the time. If such a code can be made faster, it results in overall good speed.
- Theoretical Reasons for performing an algorithm analysis are:
- Standard measure to compare two algorithms which can solve the same problem.
- Classify them, which is easily computable and difficult to compute.
Program testing – debugging.
- Program testing is an experimental verification of goodness of program.
- In testing one important point is “How does one choose the test data to be input?”. Generally programs are to be tested for their Average performance (Difficult Input), Worst-Case performance and Best-Case Performance.
Preparation of documents.
- At last this step written chronologically, but is not the final step. Actually documentation should run parallel with the entire developmental effort.
- Usually, it is hard to read and understand the program written by others. One the other hand, it is quite common that the person who coded the program is not the one who maintains it. Even we may forget after a few months how and why we coded the program in that particular way. Proper documentation will reduce this problem
Example Of Algorithm: (Finding Square Root Of Number)
//Problem: find a square root of given number
//Input: number n
//Output: square root of given number n
Step 1: Select a number n (a good first guess would be m/2) less than the number m.
Step 2: Square n and if n2 is greater than in decrease n by 1 and repeat step 2, else go to step 3.
Step 3: When the square of n is less than in we should start increasing n by 0.1.
Step 4: We again compute the square of n until we have incremented n enough so that n2 is greater than m.
Step 5: Then we decrement n by 0.01 and repeat the above steps, until the desired accuracy is obtained
Smallest Divisor Of Integer Number
//Algorithm Description
1. Establish ’n', the integer whose smallest divisor is required.
2. If ’n' is not odd, return 2 as the divisor, else
Compute r the square root of n;
Initialize divisor d to 3;
While not an exact divisor and square root limit not reached do: generate next number in the odd sequence.
If the current odd value ’d' is an exact divisor then return it as the smallest divisor, else return 1 as the smallest divisor.
No comments:
Post a Comment