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.
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.
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.
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!
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
Top comments (0)