Core CS Data Structures

I had trouble understanding the point of data structures in the beginning. But really they are just clever ways to hold and operate on data. And most of them are not included in programming languages so you have to build them yourself.

You can store data in a plain Array. Or in a String. But those structures don't have many interesting things going for them.

But by using those primitive data structures, you can build more interesting data structures.

That means you can build objects that, depending on the algorithms they implement, can store data in different ways.

Let's say you want to keep track of a stack of books. A Stack data structure would be perfect to use. Just like stacking books one on top of the other, you can only pull out the book that's on top first.

Most languages don't come with a Stack data structure by default, the way they do with data types like Arrays, Strings and Hashes.

But you can build your own object that implements this functionality of stacking and taking off an item from the top of the stack.

How do you build your own data structure? There are two ways:

1. By literally creating an object called Stack that has methods and attributes that a Stack structure would have in theory.

2. OR you could use duck-typing. Just call an array a stack and treat it like a stack. If you want to add something to the array, only add it to the end. If you want to remove something from the array, only remove from the beginning.

This mimics the real-world scenario of a stack, like the stack of books. Think of an array of books where books are only added at the end of the array, and only removed at the beginning of the array. That's the code equivalent of a Stack in computer science.

There are some core data structures in computer science that every engineer should know.

You'll want to know the costs and benefits of each data structure so when the time comes to operate on some data, you'll know the right one to use.

What's helped me the most in understanding how to go from computer science theory to practical hands-on engineering is to build each data structure out by hand.

Below is the code (with plenty of notes!) for some of the core CS data structures, written in JavaScript.
For this I used the excellent resource from FreeCodeCamp. Check them out :)

To see the code visit my GitHub repository https://github.com/Bryanprz/data-structures