Understanding Data Structures
Tags: beginners, computerscience
Published: 2022-08-05 20:49:00

Welcome to my post about understanding the basics of Data Structures! 

Here, we'll go through a basic overview of the concepts you'll need to learn in order to begin mastering data structures.

## Array
An array is simply a list of something surrounded by `[]` and can contain various data types.

The simplest data structure, the array serves as the foundation to the data structures we'll go over later in the blog. Here's an example of an array: 

```
Shopping List: Chips, Steak, Broccoli, Milk, Eggs

let shoppingList = ["Chips", "Steak", "Broccoli", "Milk", "Eggs"]
```
There are no strict rules for adding elements in an array but there will be some for the other data structures we'll look at.

## Queue
A queue similar to an array, it is a list but when adding or removing elements to a queue but it follows a "**first in, first out**" rule. 

Essentially, the _first_ element we add to the queue will also be the _first_ element to be removed from the queue.

![grocery store conveyor belt](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v1e5sdroifsivvoq5tgd.png)
 
I like to think of Queues as the checkout conveyor belts at the grocery store. The _first_ thing we put on the belt from our cart will be the _first_ thing checked out by the clerk!

## Stack
Also similar to an array and a counterpart to the queue, the difference between those data types and the Stack is that it follows a "**first in, last out**" rule. Meaning that the _first item_ we added to the stack will be the _last item_ removed from it.

![stack of plates](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h07x1ngzveutovkjq63k.png)

I like to think of a stack as a stack of plates where the first plate you add is at the bottom where the last plate you add is at the top.

## Linked List
Things get a little murky from here on out, starting with Linked Lists. 

Linked Lists has an element (or a node) that has a variable in it where **points** to another element in memory. So instead of using an array to contain all the data, these elements connect to each other from their own pointer variable that relates them to one another.

![singly and doubly linked list](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w1hjmgz1mmtrjflpuwci.jpg)

Linked lists come in two flavors: singly linked or doubly linked.

Singly linked lists have a head element that points to the next element, to the next element and so on and so forth until reaching element that has a pointer set to `NULL`. Doubly linked lists means each element has a next and previous pointer to their respective next/previous elements.
 
## Trees
Similar to Linked Lists, Trees are a data structure that has elements that point to each other in memory. However instead of having next/previous elements pointing to an element, Trees have a left/right child element. These children elements are what lead to the tree-like structure.

![tree data structure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/06gi0nznq5kdt5v8wq08.png)
 
The most difficult data structure to understand but when properly implemented, can provide great performance and give you an edge in the interview process!

## Conclusion
This post just scratched the surface of Data Structures but this should get you started on researching and eventually implementing these in your day-to-day work! There are more (and advanced) data structures out in the wild you'll come across on your developer journey. Good luck from here on out!

Sources
[Geek for Geeks](https://www.geeksforgeeks.org/data-structures/)