Data Structures 101
Tags: beginners, computerscience, webdev, programming
Published: 2021-11-18 17:56:20

**Welcome to Data Structures 101!**

Here we will cover a basic overview of concepts you'll need to get started mastering your skills of structuring data.

**Array**
The Array is the most basic data structure, which is actually used as the foundation to some of the following structures (queue, stack)

An array is simply a list of something, for example
```
Shopping List: Onion, Garlic, Carrots, Milk, Eggs

let shoppingList = ["Onion", "Garlic", "Carrots", "Milk", "Eggs"]
```
Rules for adding items to an array are pretty loose, and elements can usually be added in any order, but this differs for other data structures.

**Queue**
The Queue is similar to an array in that it is a list, however when adding or removing things to a queue, we have to follow a "**first** in, **first** out" order of operations.
Meaning, the **first** item we insert into a queue, will be the **first** item to be removed from a queue.
![Image description](https://i.guim.co.uk/img/static/sys-images/Guardian/About/General/2011/6/15/1308149463745/People-Waiting-in-Line-Ou-005.jpg?width=620&quality=85&auto=format&fit=max&s=51f7746a7aff7ce2dbbe76d0d6d25912)
Think of a queue of people waiting in line...
The first person in line is going to be the first person to leave the line!
This means when adding or removing elements from the queue, we are limited to this same way of thinking.

**Stack**
The Stack is also similar to an array, and a brother/sister to the queue, however when adding or removing things to a stack, we have to follow a "**first** in, **last** out" order of operations.
Meaning, the **first** item we insert into a queue, will be the **last** item to be removed from a queue.
![Image description](http://blog.williams-sonoma.com/wp-content/uploads/2020/02/stack-pancakes-blog-post-1000px-680x680.jpg)
Think of a stack of pancakes! 
The first pancake added to the plate is going to be the last one to be removed (granted you eat them top to bottom and don't just slice through all of the pancakes at once...).


**Linked List**
The Linked List is where things begin to get a little abstract. This structure consists of an element (or node) that has a variable in it that *points* to another element in memory. So rather than being contained inside of something like an array, these elements are connected via their own pointer variable that relates them to one another.
![Image description](https://miro.medium.com/max/970/1*f2oDQ0cdY54olxCFOIMIdQ.png)

Linked lists can be singly linked, meaning they have a head element that points to the next element, and the next, and so on until the reaching an element that has a pointer to NULL.
They can also be doubly linked, meaning each element has a next and previous pointer to their respective next and previous elements.


**Tree**
A tree structure is sort of similar to a linked list in that its elements point to each other in memory, although here instead of having a next and/or previous variable pointing to an element, it has a left and/or right child element. This indicates whether the element being pointed to is to the left or right of said element.
The left / right nature of each elements child elements leads to the "tree" like structure, giving this data structure its name!

![Image description](https://www.thecrazyprogrammer.com/wp-content/uploads/2019/09/General-Tree-Structure.png)

While possibly one of the most difficult to fully understand, the tree structure can be extremely effective performance-wise given proper implementation.

And that is the end of Data Structures 101!
There is a LOT more to learn about each of these structures and the pros and cons of each, but this is just a basic overview to get your digital feet wet.

Here's some links to additional sources on the topic:
[tutorialspoint: data_structures_algorithms](https://www.tutorialspoint.com/data_structures_algorithms/index.htm)