Hi there, do you know? What is an Algorithm in computer science? Why we use them? I will cover all related information in this blog
“Bad programmer’s worry about the code. Good programmer’s worry about data structures and their relationships “–Linus Torvalds
” algorithms + data structures = program”–Niklaus Wirth
An algorithm is a step by step procedure to solve a problem. Being comfortable with algorithm one can solve a problem in 1 hour, while the other who is not familiar with algorithms might take several day’s to figure out the solution.
If you are not familiar enough with algorithms, you won’t even know there exist an elegant solution out there.
According to John Sonmez the author of the book “the complete software developer’s career guide”. He says that every software developer must be familiar with arrays, trees, linked list, stack, queues.
John Sonmez also says that he realized the importance of data structure and algorithms when he was competing on the website called Top Coder
knowing data structure and algorithms gave him a competitive edge over other developers, who were also competing on the same website
being good with data structure and algorithms gives the competitive edge to one developer over other.
Example of an algorithm
suppose you want to eat an apple, so what steps you will take to eat an apple
Step1: take an apple
Step2: wash with water
Step 3: cut the apple with a knife into four piece’s
Step4: eat each piece one by one till you finish it
So, here are the four steps that you need to eat an apple. These four steps are nothing but the algorithm to eat an apple
You can think algorithm as a recipe, same as recipes we need in order to make a certain food. Like how much amount of salt needed, at what boiling point you have to mix the rice in the water when to add oil, so in a way algorithms are recipes to solve a problem
An algorithm is a procedure, which takes some input values and produces some output values
Example: given input sequences of number (15, 24, 77, 68, 25) then a sorting algorithm(reordering) gives an output(15, 24, 25, 68,77)
See some algorithm example in C programming language with pseudo-code
What is Data Structure
The data structure is a logical way of storing and organizing data.
Data structures and algorithms go together with each other
If you have ever read any algorithm book you might notice, they cover data structure first because it is the core of the algorithms
It is impossible to implement merge sort algorithm if you don’t know data structures( arrays, linked list, queues)
Data: are simply value’s which are represented by 0’s and 1’s
A data item: now a data item is a single element of a data
Group item: the data item which is divided into subitems are known as a group item.
Example: a student’s name can be divided into 3 subitems
: first name
: middle name and
: the last name
Values of an employee’s data are assigned to the attributes
Still confused! Let me explain you with the simple concept using apples
Suppose you have 100 apple’s then will you create 100 different boxes to keep this apple’s or keep all the apple’s in a one-box called array (Data structure)
But wait! what is an Array?
An array is a data structure that we use for storing the collection of similar data elements.
Let me explain you another example so that you will have a clear idea of data structure’s
Suppose if you have 100 students then will you create a 100 class(variables) for it,
We don’t do that because it is complicated and complex
so, to reduce the complexity we use only class(variable) called student
the main purpose of using data structure is to reduce the complexity
we use data structures in our programming instead of creating 100 different variables because we can create only one variable called Array in comparison, with 100 different variables
What kind of problems algorithms solve?
Determining all the 100,000 genes in DNA of human
storing information in the database require sophisticated algorithms
the internet we use and also over the world people can access information with the help of algorithms
finding the good routes during traveling.
Some data structures are
- Arrays or vectors
- Linked lists
Data structure operations
Data structures are chosen based on a particular operation is performed number of times
- Copying and concatenation.
Organizing, structuring data is important to the design, development of efficient algorithms and program implementation
Which algorithm In computer programming is best?
We have a large number of algorithms In computer science at our disposal then how to choose? it depends on the factors such as the number of items to be sorted, the computer architecture and what kind of storage devices you used.