Back to Basics: The Beginning

As I write this, I have spent a total of 117 days locked up in my house. COVID19 has indeed taken a toll on not just economies but the psyche of the general public. As a developer, I decided to take this as an opportunity to revisit algorithms and data structures. This idea which was throttled by the job interviews I have been taking recently made me wonder how there must be others who are looking for this. A way for you to visualize these famous algorithms so that you can base your own on them.

A building is only as strong as the foundations. The walls can’t even support its own weight. But when that weight is transferred to the foundation, the whole building is stable

— Rob Dingman.

Taking from the above quote, this series aims to provide the following :

  1. A explanation of what and how of the algorithm.
  2. Examples from the real world you can relate the algorithm with.
  3. Some questions you can ask yourself and try yourself to test your understanding of the algorithm.

Pointless to say,

If you cant explain something simply, you don’t understand it well enough.

— Albert Einstein.

The article will assume that the reader does not know anything and will aim to explain everything from the bottom. Another assumption this series will make is that you know basic algebra. Suppose I tell you f(x) = 6x and ask you f(5). You should know that the answer is 30.

If you are an experienced developer or graduate, feel free to skip to the main parts. However, I would suggest you go with the flow, if you have the time.

What is an algorithm ?

An algorithm in it’s most basic form, is a set of instructions required to achieve a task. So basically any code which does anything can be considered an algorithm. However, there are some which are more interesting as they take on a different approach to solve a problem faster or without using much resources.

Let’s take an example. Given there are n boxes, each of which has either a red colored or a yellow colored ball. I need to find which ones have a red ball.

  1. Open each box.
  2. If it has a red ball, keep it aside.
  3. If it has a yellow ball, move on to the next one.
  4. Once all red ball boxes are separated from the yellow ones, you have your answer.

This algorithm grows at the rate of n. Meaning, if there are 5 boxes, the worst case would require me to check all 5.

What are data structures ?

A data structure is basically a construction in the memory which helps you to efficiently use your data. It’s similar to you keeping tabs on your files, bookmarks in your book. It makes it easy to reach the section which has data worth your value or the page you last stopped at. Computer will similarly have these organized spaces which will have their own properties and use cases.

Now these data structures can be linear or non linear. We’ll see in the upcoming parts what we mean by linear and non linear in detail. However, for simplicity sakes and basic overview you can think of linear data structures like continuous seats in a movie theatre. They are one after the other and connected. For non linear data structures, you can think of a company’s hierarchy. You have nodes which have relationships with other nodes and there are levels which make the whole structure not very simple outright.

What data structure are you going to talk about ?

In this series, we’ll talk about the following data structures:

  1. Arrays
  2. Lists
  3. Stacks
  4. Queues
  5. Maps
  6. Trees
  7. Graphs

This part was all about introducing you to the realm of algorithms and data structures. In the next article we shall start with searching. How to do it, how to make it more efficient and how can you relate to it.

Stay curious! Cheers!

Full Stack Developer, Tech Enthusiast, Traveler, “Chill guy”