Algorithm Vs Program

Distribute Education like Computer Geek
Algorithm

An algorithm is a set of finite, step-by-step rules or instructions to convert inputs to outputs. It is simple and effective.

.

Program

A computer program is a collection of instructions that perform a specific task when executed by a computer. It follows the syntax of the programming language.

But my point is not about defining the word. My point is to tell you what an algorithm can do but a program cannot, or what a program can do but an algorithm cannot.

Example: To solve a problem, you need to design an algorithm and then implement it in the source code of any language. However, some problems can be solved by designing an algorithm; no programming language can solve them.

.

 

I will give you an example. Write a program to compute the square root of any number.

You can make an algorithm of square root but you cannot make a program that will give the square root of every input. In an algorithm, you just have to pass the logic. This is so simple, but in a program that is syntactically and semantically correct, you cannot generate the output of every integer.

4 is 2 okay, 9 is 3 okay, and 16 is 4 okay, but what about 5, 6, 7, and 8? 4, 9, 16, 25… These are perfect square roots, but the square root of non-perfect square roots cannot be generated exactly.

.

Example

There are some assumptions that square root 2 is equal to 1.414, and Hippasus, who was a Greek philosopher, discovered that the square root of 2 is an irrational number; that is, he proved that the square root of 2 cannot be expressed as a ratio of two whole numbers. You find out for yourself whether 1.414 is the correct answer; add thousands more numbers next to it, and the answer will still not be perfect. So, a computer program cannot do justice to the square root problem because it needs exactness, but an algorithm can give the logic.

 

Another example is for those who have great faith in friendship: when you like someone and you want to befriend him or her, but you have not yet succeeded, many people ask their closest friend how to talk to their “target.” Then your closest friend gives you some tips, so understand what he says, you should take it as an algorithm, which will only give you a logic, but making this program is a difficult task. The program will be made only if you make friends with your target, but 50% of the coincidences will be such that he or she refuses. Then your program will not be made.

Test Yourself

Q1- Define Computer Program?

A computer program is a collection of instructions that performs a specific task when executed by a computer. It follows the syntax of the programming language.

Q2- Can cube root program gives accurate output on every input?

Perfect cube root numbers can give accurate output but every input can’t give accurate results. 

Q3- Can cube root algorithm give accurate logic on every input?

There is a domain of input which will pass in the algorithm and algorithm instruction will give accurate logic.

 

Q4- An algorithm becomes a ________ when it is written in the form of a programming language.

Program

Q5- Is it possible for a program to evolve into an algorithm? 

Expert programmers can do that. There is a certain way you have to follow to make an algorithm from a program.
1. Write input domain
2. Write all the test cases
3. Note every output.
4. Break the code into modules.
5. Write algorithms for the modules.
6. Find integration of the module’s algorithm.
7. Dry run the program’s algorithm.

Q6- The method that uses a list of well-defined instructions to complete a task starting from a given initial state to an end state is known as

Algorithm

Q7- Algorithms are used to
1. better planning.
2. Better programming
3. Easier testing and debugging

 

All of the above

Q8- What is the pictorial representation of algorithm?

Flowchart

Q9- Pseudocode chooses to focus on
1. Development
2. Design
3. Coding

 

Design

Q10- The pseudocode instructions are written in the order in which they will be executed is _________.

 

Sequence

BOOKS

Algorithm T H CoremanAlgorithm by Udit AgarwalAlgorithm Ellis HorowitzData Structure & Algorithm Made Easy Narasimha

Â