Skip to main content

Command Palette

Search for a command to run...

What is an Algorithm?

Published
2 min read
What is an Algorithm?
H

I am a full-stack developer with expertise on JavaScript stack like reactjs, react native, vue, node, redux, next, nuxt, express and so on. I am currently working on python stack with machine learning and AI focused. I always enjoy learning new things and sharing out with fellow dev community.

An algorithm is a set of well-defined instructions to solve a particular problem.

Recipe Analogy

adsad

Let's suppose u have to make a dish so u have a set of ingredients, then u follow the recipe by following step by step in the sequence, and the final result is the tasty dish.

Now let's suppose u have to make noodles, so in the first diagram u can see u have some set of instructions, and n the second step, u have step by step process to make noodles and the final output is in the form of tasty noodles.

Programming Algorithms

Let's suppose we have a problem with ''add two numbers''.

Here, in the above example. We have two numbers 'a' and 'b' as a set of instructions, then we have to create an algorithm by following step by step process in sequence first adding numbers using the plus operator, and then the last step is the return of the value and our output is the total value by adding a with b.

Characteristics of Algorithms

  1. Well-defined inputs and outputs. (So in the above example u can see that we have to add two numbers a and b which are inputs and our output is the sum of these two numbers. So, here is our first step lies correct).

  2. Each step should be clear and unambiguous. (U can see in the above example that in our algorithms sequence our first step is to add numbers using the + operator and the second step is to return the value of those sums. So, here our second characteristic lies true and clear).

  3. Language Independent. (That means we have to create an algorithm that should execute on every programming language, in simple words that means if you are writing an algorithm in JavaScript language then the same algorithm logic should work on any other programming language as well).

Why Algorithms?

So, why should we learn algorithms? The answer is simple

  1. As a developer, you will come across a problem that needs to be solved.

  2. Learning algorithms means u will get insight into how to efficiently solve those problems.

  3. One problem can be solved in many ways using algorithms, which means if u stuck on one road u can take the second road to reach your destination 😉.

  4. Every algorithm comes with its own tradeoffs when it comes to algorithms, but HOW? Which I will discuss in the next article.

All about DSA

Part 2 of 2

Here, In this series, I'll be sharing my learning journey of data structures and algorithms with fellow community. My main purpose to write this series is to get and help others to get a job in FAANG.

Start from the beginning

Time and Space Complexity

Algorithm Analysis In the previous articles of this series, I told you that there are multiple ways to solve one problem. Example: There are multiple algorithms to sort a list of numbers. So, now we have to analyze which one of them is the most effic...

More from this blog

Hammad's tech

14 posts