Array Data Structure For Dummies

Made using canva

As software engineers, we have to face Data structure and algorithms one way or the other no matter how hard we try to avoid them. For beginners, this can be a very hard topic to grasp and wrap their heads around.

But don’t worry I got you covered. Today, I will explain Array Data Structure in the easiest way possible but before I do that let’s freshen up the basics.

What is an array?

An array is just a collection of items, stored in a contiguous memory location. Imagine a wardrobe where you have drawers in a continuous manner. Each drawer can be accessed with its key.

To access elements of an array is just like that. Every element in an array has an index or you can say a key. By using that index you can access the element that is stored in that place in the array.

Why do we need ADT?

Traditional arrays that come with the languages like C /C++ have limitations like:

1. No functionality for bounds checking.
2. No functionality to insert an element.
3. No functionality to delete an element.

So to overcome these limitations some really intelligent people come up with Array Data Structure. (ADT)

It not only solves the problems mentioned above but it is so customizable that we can have any functionality we want.

Bounds Checking

A user wants to enter 20 names and he using the traditional C array that you have provided. The size of the array that you have provided is 10.

Think for a moment that you don’t know exception handling. What will happen if the user goes beyond the limit.
Have you relied on the user that they will only use the storage space that you have provided and he/she doesn’t break your program? Let me tell an ugly truth — The users don’t care about your program, they are only trying to break it.

As a software engineer, it is our responsibility that our code must be robust. So how do we make our array robust that when someone tries to enter elements beyond the size limit it throws an OVERFLOW error?

Comes to our rescue ADT which unlike traditional array comes with the inbuilt functionality of bounds checking.

Insertion/Deletion

Just like no bounds checking, traditional C/C++ arrays do not come with the functionality of insertion/deletion. If you have an array of 5 and it is full. There is no place for a new element to be inserted.

So ADT does is it shifts the element where we wang to insert our element while simultaneously increasing the size of the array.

And the same process happens for deletion. Growing and shrinking in size is the beauty of ADT.

Conclusion

Data structure are a necessity and an eternal part of a software engineers life. Whether we despise them or love them they are helpful in so many situations that they become a life saver for us.

Thank You for reading and giving this article your precious time.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store