Could it be that some Data Structures are not really structures at all?

My journey to being a Software Engineer wasn’t the academic path. I would say it was unconventional, but I don’t think that is true. I went the bootcamp route which is actually quite popular nowadays. So it is probably quite conventional at this point.

But to get to my point I didn’t learn much about the infamous “Data structures and Algorithms”, the holy grail of interviews. So I had to learn those more or less afterwards on my own.

While I was learning about different data structures, I would sometimes get confused. To me it didn’t sound like a unique structure at all, as a matter of fact for a number of the so-called “Data structures” you can represent them as an array with absolutely no problems.

The first examples that come to mind are stacks and queues. There is nothing unique about them in terms of their structure, what makes something a stack is that you use it when you need a ‘Last In First Out’ (LIFO) functionality. With a queue being the opposite that it has a ‘First In First Out’ (FIFO) functionality.

If you want a queue, you can use an array and use queueArray.unshift() (add to the beginning) and queueArray.pop() (remove from the end).

If you want a stack you can use an array and use stackArray.push() (add to the end) and stackArray.pop() (remove from the end).

It’s true that different structures make certain things more efficient. For example, you can use an array as a stack very nicely, however if you need a queue an array might not be so efficient. But that doesn’t necessarily mean you can’t use an array to represent a queue, it’s just not so efficient. What I’m trying to say is, they don’t describe the structure (how the data is stored), rather they describe the functionality (how the data is accessed).

In contrast, you can think about a linked list. The name “linked list” describes the structure not the functionality. Each node only has a value and pointer to the next node (and possibly previous node). Depending on the desired functionality, you can decide if you want to use an array or a linked list (or something else). Each one has different things they are more efficient at.

You can use a linked list inefficiently, but you are still using the unique “linked list” data structure. Whereas with a queue, you can use a linked list as a queue or an array as a queue. They are both called queues, regardless of the actual structure used.

Once I came to this realization, I came to the conclusion that when we refer to “data structures” we don’t necessarily mean each one is a unique structure. For example a house and a store can both be the exact same structure, but they are unique in their function, so they have different names. Here we can apply the same concept, there can be different names to the same structure, if they serve different functions. But they are all data structures.

Conclusion:

The important thing when learning data structures, is to learn when it is efficient to use a certain structure over another structure. Or which kind of functionality is most efficient here and to decide which structure can give you this functionality most efficiently.

Do you agree or disagree? I would love to hear your thoughts!

--

--

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