Why Data Structures and Algorithms?

Hello everyone, this post is to discuss why using right data structures and algorithms are considered as an important skill for developers. Let me start of with an story like example.

Suppose you are standing near a lake. Lake is full of water. You need water in your house for drinking and other purposes. So your task is to carry required amount of water to home. You also have some other works after this, so the more quicker you finish this task, the more better.

So how do you carry water?
There are three things available with you at the moment, a plate, a spoon, a pot(volume which is sufficient for one day).

First task will be choosing the right container to carry water. Among three, pot will be the best choice. If you think it's not sufficient, you can build a large container out of materials available near lake and carry month sufficient water. But lets consider pot as right container for this example to keep it simple, to reach home back soon to carry on with other tasks and we are not sure about building leak proof container with available materials near lake (considering you are not Bear Grylls).

So we decided feasible container choice as pot.

Now, how are we going to fill and transport pot with water from lake to home fastly. For filling you have options like filling with hands or using spoon or using plate(it will be feasible to use when container is so heavy, you can't dip and take out of the lake) or just dip pot into lake and fill the water. Dipping is the fastest way we can choose. You are having following transport choices : walk, run, cycle, motor vehicle, flight. Walk and  run are the options which are slow compared to other options but they are free of cost. Motor vehicle is bit faster but its has fuel charges. Flight will be the fastest means of transport available, but we need airports near lake and home. Though they are available, flight charges are not reasonable just to carry lake water. Using flights as transport for carrying lake water seems to be over optimising (this can be considered as immature optimization). So based on resources you have, you choosed motor vehicle as a better option.

Now you reached home and completed your tasks in the best time possible.

So, if we considered above scenario, it's all about making right choice using our imagination and knowledge. Now it's time to relate it with Data structures and Algorithms and understand why they are useful.

Consider yourself as a program, your house as your project or application you are working on, lake water as data available from oustide, containers as data structures which will be filled with data, filling the containers and transport as algorithm, time constraints for bringing water to home as time constraints for bringing data in required format.

Lets consider water molecule as unit data type,
Lake water is a collection of water molecues. Lets consider spoon as water molecule data type which can hold one molecule, plate as linear array data structure, pot as multi dimensional array data structure.

So pot seems to be a feasible solution which holds collection of molecules and the shape they took.

Now lets jump into transporting, lets consider walking as brute force algorithm,  cycle as littile bit optimised but had lots of patches to handle different conditions, motor cycle can be a neat and structured optimized algorithm without patches, flight can be overly optimized solution which is not required at the movement which complicates the code and process. So motor cycle algorithm will be the best choice and finally saves the data.

So yeah, what I want to say is data structures are like containers or a toy for programmers to play with. And algorithms are the logic patterns which uses those data structures efficiently to perform different tasks. Being a programmer, making the right decision regarding data structure and algorithms is a very imporatant skill in developing an application or application design or problem solving.

To learn and feel good with data structures and algorithms below resources will be helpful:
(make sure you are comfortable with basics and writing code in atleast one programming language before going through below stuff)

Thank you
Madhurima Paruchuri

Comments

  1. It was really informative. Your site is very helpful.
    You can learn more about Data Structure from here -

    https://www.etutorialspoint.com/index.php/data-structure/data-structure-introduction

    ReplyDelete

Post a Comment

Popular Posts