Overview of Algorithm in Computer Science and uses in Programming Language.
Hello Everyone ,
Today we will discuss about Algorithm as it’s very important for any Programmer to understand Algorithm to make program in simpler way. In simple word an algorithm can be defined as a step by step procedure for accomplishing a task. In the world of programming, an algorithm is a well-structured computational procedure that takes some values as input some values as output. Algorithms can have a wide variety of applications. In math, they can help calculate functions from points in a data set. Aside from their use in programming itself, they play major roles in things like file compression and data encryption.
Before Going to Importance of algorithm just need to understand how algorithm works to write any simple program.
For example Suppose we write a simple program in Pl/SQL to check if there is any records in table then update the table else insert the records in a table.
So doing this I come up with below Algorithm in PL/SQL:
1. Declare 1 variables, for storing the value from using function count in SQL.
2. We need to put that value in variable by using count function from that table by using select statement.
3. Check with conditional statement IF the count is greater than 0, It allows user to update the data in a table else automatically it will insert the records in table as it will check the condition as value stored in variable.
As this is a simple check condition program so we use only 3 steps and step-by-step process to create our program is what is known as Algorithm.
Below is the implementation Program for above requirement by using algorithim.
Declare
v_count number;
BEGIN
Select count(*) into v_count from employee;
If v_count >1
Update employee set salary =200000 where dept_id=20;
Else
Insert into employee values(‘20’,200000);
END IF;
END;
This is Anonymous block and we use simple step defined in algorithm.
Let’s take one another example in any language like C , C++ , Java etc to check whether the number is odd or even .
So I will come up with below Algorithm:
1. First, declare 2 variables.
First variable for storing the number from the user will enter, 1 for storing the remainder after modulus by 2 in the second variable.
2. Provide the user a message informing to enter a number.
3. Allow the user to enter a number and store it in the first variable.
4. Divide in modulus by 2 and store the remainder in the second variable.
5. Check with conditional statement IF the remainder is equal to 0, Display the result as Entered number is an even number ELSE Display the result as Entered number is an odd number.
Below is the implementation Program in C for above requirement by using algorithm.
#include <stdio.h>
int main() {
int i;
printf("Enter any number: ");
scanf("%d", &i);
// checking if variable i is perfectly divisible by 2
if(i % 2 == 0)
printf("%d Entered number is an even number.", i);
else
printf("%d Entered number is an even number ", i);
return 0;
}
In Above Program we simply use above algorithm to write the program in simple manner.
Now we need to understand how algorithm play important role in computer Programming.
Importance of Algorithm in Computer Programming:
1. Improve the efficiency of a computer program: In computer programming, there are different ways of solving a problem. However, the efficiency of the methods available vary. Some methods are well suited to give more accurate answers than others. Algorithms are used to find the best possible way of solving a problem. In programming, efficiency can be used to mean different things. One of them is the accuracy of the software. With the best algorithm, a computer programmer will be able to give very accurate result. Another way of looking at the efficiency of software is performance. An algorithm can be used to improve the performance at which a program executes a problem. A single algorithm has the potential of reducing the time that a program takes to solve a problem in short period of time.
2. Utilization of resources : As we know computer has different resources. One of them is computer memory. During the execution phase, a computer program will require some amount of memory. Some programs use more memory space than others. The usage of computer memory depends on the algorithm that has been used. Apart from memory, and the algorithm can determine the amount of processing power that is needed by a program so right choice of an algorithm will ensure that a program consumes the least amount of memory and your program can work fast if you use the resources by using correct algorithm.
In Computer Programming there are different type of Algorithm and Different algorithms play different roles in programming. It dependends on you or programmer who can select the right algorithm to use.
Searching algorithms, Sorting algorithms ,Tree and graph-based algorithms,Compression algorithms, Pathfinding algorithm and many others.
So finally , We can say Algorithm plays important role in computer programming as if you follow the algorithm your program is more efficient and also you can use steps to follow the program as per requirement and we can say for programmers it’s very easy for them to write the pieces of code in efficient manner as well as they can utilize correct resources to improve the performance of any code either written in C, C++ , Java etc.
Note: By creating algorithm you will be able to evaluate all the possible solution to specific problem.
Please go through this blog carefully and let me know if you have any doubts. Algorithm is very important for computer science graduate and also for the candidate who is preparing for interview and Interviewer can ask the importance of algorithm in computer language. In next blog I will come up with another Topic.
Thanks
Very well explained !
ReplyDeleteIt is very useful for me. Thanks...
ReplyDeleteAzure Data Engineering Online Training
Azure Data Engineering Online Training