Now that we have understood the basics of how information is actually stored in a computer; let's get right into the crux of this blog. ALGORITHMS !
Algorithms are everywhere! They are so incorporated and embedded in our daily lives that they completely escape our notice. How does your mom prepare her mouth-wateringly delicious dishes? She has a secret recipe. This recipe is an algorithm. Remember the mechanics problems you used to solve. In most of the questions, you first drew the free body diagrams, then resolved the components in the desired axis, and only then proceeded further. This was an algorithm.
So what exactly is the algorithm then? An algorithm put simply, is a sequence of steps that we follow to solve a problem.
Let us further try to understand the use and implementation of algorithms through an example that you all must have come across in your school days.
Algorithm to find the G.C.D of two numbers (Let’s take 6 and 8 for our example) (G.C.D stands for Greatest Common Divisor)
Method 1
- Divide 6 and 8 by 1.
- Divide both the numbers by 2 this time.
- As the remainder comes out to be 0, write 2 on a page.
- Divide both the numbers by 3.
- As the remainder is not 0 for both, discard 3.
- Repeat the same process for all numbers till the smallest of the given numbers (6 in this case).
- Now the largest number amongst the numbers written on our page is our G.C.D.(2 in our case as after 2 we will not find any number which is totally divisible by 6 and 8).
Method 2
- Divide the larger number by the smaller one and find out the remainder(8/6=2 in this case)
- Now, forget about the bigger number and consider the remainder and the smaller number. So, divide the larger one of the two by the smaller one and find the remainder (6/2=0 in this case)
- Repeat until we get remainder as 0 (6/2 is the last step).
- The smaller number at the time when the remainder is 0 is the G.C.D.(2 in this case)
If you closely observe both the algorithms by taking a few more examples, you will find that the second algorithm takes less number of steps and hence less time in general. This is a core concept. The search for “efficient” algorithms is evergoing in the world of computers. It is the driving force behind so many new inventions. So before writing any code we always try to think of an algorithm that both takes less time and is memory efficient.
In this search, algorithms often get complex and difficult to understand. So, after writing an algorithm, we usually make a flowchart to make it simpler and understandable. Flowcharts are going to be our next topic. But before that, try a question.
Try finding out a time-efficient algorithm for calculating the LCM of two numbers.
Mail your assignment answers to zine.nitj@gmail.com and contact us in communication channel with doubts.
Robotics &
Research
Group
GROUP
Home
Team
Alumni
PROJECTS
Achievements
Projects
Contribute
ACTIVITIES
Workshops
Blogs
Gallery
COPYRIGHT 2023, ZINE
zine.nitj@gmail.com