Skip to main content

Command Palette

Search for a command to run...

Why Sanke's Mom Is Angry On Him?

Let's Uncover The Mysterious Question

Published
8 min read
Why Sanke's Mom Is Angry On Him?
N

Write code and poems

There was a troublesome snake (Python species) who lived with his mom and dad in the backyard of Shinchan’s house (remember the famous cartoon). As we know, our companionship decides what kind of person we will become in the future, and the same goes for this snake too. This snake saw Shinchan's habits daily, playing around and not behaving properly in front of others. Most importantly, Shinchan never put his toys or books (which he never opened) in their proper place after playing and using them. He threw all his stuff here and there throughout the house. As our snake grew up watching Shinchan’s habits, he also adopted the same habits as Shinchan. (Guys remeber always be in the company of good people)

One day, the snake's mom was walking around his room looking for something important. Suddenly, she stepped on the sharp edge of a toy, slipped, fell to the floor, and hurt herself. She started shouting at the snake. This story is relatable to many Indian households: our moms will never be at peace if we leave our things scattered everywhere instead of putting them away neatly.

Now let’s relate this story and its characters to our programming world so that you will understand the importance of Data Structure in Programming.

Data (The Stuff On The Floor)

Everything in this world is data, from audio and video files to the binary digits that computer systems use. All these things are data. Now suppose we don’t need data to know anything or to process some facts from other facts, or we don’t need to logically examine the situation to get the solution to the problem. In that hypothesis, we don’t care about how data is coming and getting transferred from one place to another.

Actually, data is like those toys and books in our story—spread here and there and very messy. If we don’t have any use for that data, we will never arrange it or put it in proper order. But that’s not the case; we need data to process almost everything happening in this world. For example, a farmer needs data related to weather, the cost of fertilizers, etc., to grow and harvest crops. A painter must know the data related to painting. Similarly, in programming, we need data to process anything, from getting an image from a website to uploading videos to YouTube. We need some kind of data (for example, on YouTube, our computer must know which account we are going to upload our video to).

This diagram will help to give you some clarity.

So we can say in reality data is just spreaded out without any identity of itself. But we use that data to do all the stuff happening in today’s world so How we use this messy data or we can ask to ourself how we divide this data properly and put it at the right place so that we can get the needed information. That’s where the structure part plays its vital role. Let’s discuss it properly and with the same story discussed above.

Putting Data In Proper Structure (Mom Is Happy)

Why is giving data a proper structure important (Why should the snake put his stuff in its proper place)?

Now let’s revisit our story. Mom got angry at the snake because all of the snake's stuff was scattered everywhere, and she couldn't find her belongings and slipped while looking for her stuff. When the snake returned home, his mom shouted at him (kutte ke bacche tujhse apna saman jha se uthata hai wha nhi rkkha jata). Now, the snake puts his stuff back in the proper place, and from then on, whenever our snake takes out his stuff, he puts it right back in its proper place (toys in the toy box, books on the bookshelf). His mom was able to find her belongings easily, and the snake's room also looked clean and beautiful.

Let's take another example. In the English language, there are words, and by words, I mean a lot of words. Consider those words as the messy data in our world, and you cannot understand those words until they are arranged in a proper structure so that they can form a sentence, which we can easily understand and learn what those words are telling us.

Remember, just as in the English language we have some rules to give data the structure of a sentence known as English grammar rules, in the snake’s home there were rules to put toys only in the toy box and books on the bookshelf. Similarly, we have rules in programming that define the way we want to structure our data.

Below is the diagram for more clarity.

I hope you now understand why structuring data is important in the real world and in the programming world too. Now, let's get into structuring data in the programming world. How many types of structures are there in which we can store our data and manipulate it efficiently according to our needs?

Types of Structures (Toy Box or Bookshelf)

In our story, there were two types of stuff making the snake's room messy, and his mom was mad at him. But when his mom shouted at him, he realized his mistake and started to put his stuff back in its proper location, i.e., toys in the toy box and books on the bookshelf.

Can the snake put his books in the toy box and his toys on the bookshelf? Yes, he can, but that would make a huge mess. For example, if he wants a toy next time, he will search in the toy box and find his books instead of that toy and have to go for studies instead of playing.

So, the type of structure in which we should put our data is the most important thing. It decides how to search for a particular data we want from our computer, update our data, and manipulate it the way we want very efficiently while using fewer resources (e.g., time, space in memory).

There are two types of data structures →

  1. Linear Data Structures

  2. Non-Linear Data Structures

Let’s discuss both of them in details.

  1. Linear Data Structures (The Bookshelf)

    From its name, we can define it as some kind of structure in which we store data linearly, or we can say, sequentially. In these types of data structures, data is stored in a particular sequence. Now let's understand it with an example.

    Suppose the snake in our story has a huge bookshelf, and there are sections for each subject. Then he should put the books in the proper order on the bookshelf. If he puts the Mathematics book in the Biology section, it will cause trouble for him to get that particular math book (because he will search for the math book in the Mathematics section, but our genius Snake put it in the Biology section).

    As we understand from the above example, sometimes we need our data in the proper sequence so that we can use it efficiently and manipulate it according to our needs.

    By linear, it also means that one data item is connected to another single data item. It is similar to the one-to-one relationship of functions that we studied in our school days.

    Some examples of linear data structures are Lists (Arrays), Linked Lists, Tuples (in Python), Stacks, and Queues. We will discuss each one by one in upcoming articles.

  2. Non-Linear Data Structures (The Toy Box)

    It is the opposite of linear data structures; it doesn’t follow any particular sequence, which means it helps us store data in a non-sequential way.

    Returning to our story, our snake put all the toys into the toy box without any sequence (the toy car is in the same box, the toy train is in the same box, the toy gun is also in the same box). So we can say our snake stores toys non-linearly inside the toy box.

    Technically, we can understand this as data having many-to-one, one-to-many, or many-to-many relationships with other data.

    Some examples of non-linear data structures are Trees and Graphs.

Operations On Data

As we discussed, we need data structures to perform some operations on that data and manipulate it so that we can perform our computer-related tasks more efficiently. But what are these operations that we need to operate on the data? Let’s take an overview of these operations; we will discuss each of them in detail in upcoming articles.

  1. Insertion

    This operation helps us insert data into the structure.

  2. Deletion

    It is very common to insert some wrong data into our structure, which can cause trouble, so we must delete such data. The deletion operation does that for us.

  3. Traversal

    To find which data we want to delete, we must know where it is situated inside the big complex structure. To do that, we use the traversal operation.

  4. Searching

    If we want to retrieve some information (data), we search for it inside our data structure using search operations.

  5. Sorting

    If we want to put our data in a particular order, which may make our work more efficient, we use sorting operations.

  6. Updating

    If we want to update outdated data inside our data structure, how will we do that? Updating operations help us in that situation.

These operations are applied differently to each type of data structure. Lists (Arrays) use specific techniques for each operation, and Graphs have their own methods as well. This is just a brief overview; we will explore each operation in detail for each data structure in upcoming articles, one at a time.

Conclusion

In this article, we explore the importance of data structures in programming through a relatable story involving a mischievous snake in Shinchan's backyard. Just as the snake learns to organize his toys and books from the chaos, data needs to be properly structured to be useful. We delve into the different types of data structures—linear and non-linear—and their significance in storing and manipulating data efficiently. Additionally, we introduce operations like insertion, deletion, traversal, searching, sorting, and updating, which are essential for effectively managing data within these structures.

Thanks for reading, and don’t forget to give feedback.

#ChaiCode

A

bhaiya apka article padh kr mai bhi inspired ho kr likhta hoon, but apka article hmesa next level hota hai 🙇‍♂️🙇‍♂️🙇‍♂️.

1
N
Nikhil1y ago

Bhot shukriya bhai, achha likhte rho dusro ko sikhate rho or aage badhte rho all the best buddy.

1