What's a Data Structure?
I’ve always considered the term “data structure” to be confusing. What the heck is it? Is it data with structure, which is an equally ambiguous term?
When I used to share my bewilderment with my peers, they would quickly quip, "data with structure". The look of satisfaction on their faces used to make me question myself. I guess that's all I needed to know....
Eventually, I learned to resolve the concept of a data structure with a simple rephrasing of the term "data structure" to "structure of data". In this context, the focus shifts from data (a thing) to structure (organization). This is a subtle but immensely important detail. We aren’t focusing, in other words, on things, but on the process of organizing things.
Let's imagine that the things we're discussing are books. What makes more sense: books with structure or organization of books? In my opinion, the latter is easier to comprehend. The focus is correctly on organization—not books.
Different Types of Data Structures
Books, similar to data, can be organized in many ways. Let's image that we have 20 books. How do we organize them?
If we want to quickly find a book when we need a reference to it, we can insert all of our books in alphabetical order on a shelf; every time we need a book, we can find it using our knowledge that books are stored alphabetically.
If we want to read all of our books in a specific order, maybe from the first book we inserted into our collection to the last book we insert, then we would want to place our books in a sequence with that order; moreover, we want to impose a restriction of reading our books in only that order.
If we lack the storage to keep all of our books in the same room, maybe we want to organize our books in a way where we can quickly find them. How about placing our 20 books throughout our house, and then creating a list with two columns: the first column lists a book's title; the second column lists a book's location.
At this moment, it should become clear that there are many ways to organize books; moreover, there are many different types of data structures. The data structure we use in web development, just like our example with books, depends on our needs.
If this seems hard to imagine, don't worry. I used to think of a Set, which is a type of a data structure, as just a Set! Oh, how naive, Cho. A Set isn't a thing; a Set is the name assigned to a particular way of organizing data. What's equally important, a Set is created using objects.
Since there are too many data structures to be adequately covered in this series, we will explore only a few but the most common data structures:
- Stack and Queue
- Singly-Linked List and Doubly-Linked List
- Tree (Depth-First Search and Breadth-First Search)
When we complete this series, I hope you'll not only learn how to implement these common data structures, but you'll also see that they are used all around us. When you realize that these data structures serve a very specific and useful purpose in organizing all data, you'll elevate your appreciation for them. You'll begin to think differently about your data and how you organize it, too.
Subscribe below and we’ll send you a weekly email summary of all new Code tutorials. Never miss out on learning about the next big thing.Update me weekly
Envato Tuts+ tutorials are translated into other languages by our community members—you can be involved too!Translate this post