DEV Community

Cover image for Understanding Data Structures
Steven Dawn
Steven Dawn

Posted on

Understanding Data Structures

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"]
Enter fullscreen mode Exit fullscreen mode

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

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

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

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

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

Top comments (0)