What is a data structure?
A data structure is a particular way of organizing data in a computer so that it can be used effectively.
A data structure is like a filing cabinet.
You first have to open the filing cabinet to see how all the files are structured.
Inside the cabinet, all of the files are organized in a specific way (alphabetical, chronological, etc.) that allows you as the user to easily access the files in the most efficient and compact manner.
In other words...
A data structure is the way your data and information is organized.
Why are data structures important?
It's one thing to know what a term means, but that is worthless if you don't know why you should know what a data structure is in the first place. Let's break down the importance of this tech term based on two high level categories. We'll walk through an explanation as well as provide a score, 1-10, that shows you how much you should care about data structures.
The first will be if you do not have a product yet. This means that you don't have a physical product. Maybe you're in the ideation phase, or maybe you're almost ready to start development. Whichever it is, we'll get into why data structures are important and why you should or shouldn't care about it if you do not have a product.
Your data structure is really important to think about. Before you launch your product, you need to be sure you are collecting your data in the most efficient way. For example, imagine you launch a product that collects data in a word document rather than a spreadsheet, that would make things very difficult. So be sure to plan ahead with your data structure.
Live Product: 8/10
The second category is if you do have a live product. Maybe you just launched your business or maybe it's been live for years and you're continuing to improve its quality. Regardless of the scenario, if your product is live, data structures carries a different weight.
This term is important once your product is live because it is important to understand how you are currently pulling data in. The more you understand how your data flows, the better you can manipulate it and learn from it.
Examples of data structures
So you know what data structures are, by definition. You know if you should care about it or not depending on your situation as a business/company/product. To dig in deeper, we will walk through some examples so we can make sure you really have a solid grasp on the data structures within a database.
Eight core data structures:
There are many basic structures that when used properly are able to create more complex data structures. In order to give you a broad understanding, we're going to walk through the eight core building blocks of data structures and what they are.
An array is going to be your most common data structure. Think of an array as a list of values, each assigned a numerical value to identify its position. There are two main types of arrays: one-dimensional and multi-dimensional. A one-dimensional array is a simple line of values. a multi-dimensional array is an array within an array (it's array-ception!). So within your value of, let's say 1, you may have an array of additional values.
A stack is a way of organizing data that allows you as the end user the opportunity to navigate through information in an organized manner. Think of a stack of library books in alphabetical order. If you want to find the book that starts with the letter 'G' then you need to first unstack the books on top of it, or the books that start with the letters before 'G.' An easy application of a stack data structure is the Undo command. I know you've used it, because let's be honest, it's the most helpful tool out there. When you click to undo something, you are just grabbing the most recently added stack of information from the stored data - that is why when you hit Undo multiple times in a row, it will backtrack your steps in the reverse order they were performed. A stack method utilizes the Last In First Out method (LIFO).
A queue is similar to a stack but instead of being organized as Last In First Out (LIFO), it is organized as First in First Out (FIFO). Try to imagine a real life queue (as it mimics the data structure). There is a line of people waiting to order food. If a new person joins the queue, they are added to the end of the line, they don't just jump right in front of everyone who has been waiting.
- Linked Lists
A linked list is also a linear data structure that is similar to an array but differentiated by an important variable: a pointer leading to the next value in the chain. Rather than just listing out values, a linked list will show the relationship between the values, pointing to the directional order of the values. Linked lists can be used to implement things like file systems or relational lists.
A tree is a form of hierarchical data structuring. Think of a tree exactly like a decision tree. You start off with the root question/prompt/etc. Based off of that, you can choose either of the options provided. Once you choose an option, you continue down that path until you reach the end. You cannot jump between options, you must continue down the tree path that you have chosen.
A graph is a type of network, allowing relationships between multiple variables. Unlike a tree, a graph can work in a continuous cycle, jumping between all variables that each one is connected to. There is no delineated path structure that must be followed.
A trie is just like a tree but it delineates the end of a linear path. So, where a tree could end with three options to choose from, a trie will always work an individual towards a final answer, whether that final answer sits after the first decision matrix or the 4th.
- Hash Tables
A hash table is a way to jumble up a sequence of text or variables into a unique key. A hash table allows you to uniquely identify objects and store them all within a table, then utilizing the key to find the relevant output. Hash tables are generally implemented using arrays.
- A data structure is the way your data and information is organized.
- If you don't have a product, it is important to think about how you will plan out your data structures for when you are ready to build.
- If you do have a product, you should know what your data structure looks like.
- There are eight basic building-blocks of data structures: Arrays, Stacks, Queues, Linked Lists, Trees, Graphs, Tries, Hash Tables.