Data Structures and Algorithms (Pt. 1-Data Structures)

liz_p

Liz P

Posted on November 29, 2021

Data Structures and Algorithms (Pt. 1-Data Structures)

My personal feeling is that data structures and algorithms are an asterisk subject or simply not not covered at all in the majority of structured coding programs (at least the ones I’ve come across). Unless you’re specifically taking a DSA course, they aren’t really tackled in-depth. BUT, this is how many potential employers will assess your technical capabilities during a live coding scenario. My immediate thoughts on this topic gravitated to “what the hell is a binary search tree or a linked list?”.

Data Structures- a data structure is a particular way of organizing data so that it can be used efficiently. (For the purpose of this article I’ll be referring to JavaScript).

Data Structures handle four main functions:

Inputting information
Processing information
Maintaining information
Retrieving information

In JavaScript there are primitive and non-primitive data types. All primitive data types are immutable, meaning they can’t be changed.

Boolean

Null

Undefined

Number 

String 

Symbol

Non-primitive or complex data types can be changed.

Array

Object

Here are the data structures in JS that you’ll likely be questioned on:

Array- arrays are objects and the most simple data structure. They are collection of elements stored in sequence, starting with the 0th index (which as we all know means the first element is at position 0 not 1).

Hash Table- this data structure uses an associative array, mapping keys to values. It also uses a hash function that converts a key into an array index.

Tree- trees have one root node, the other nodes “branch” off making it into a tree form. Each node in a tree data structure must have the following properties:

key: The key of the node

value: The value of the node

parent: The parent of the node (null if there is none)

children: An array of pointers to the node's children

A common type of tree is the "binary search tree" which is used to easily search stored data. And the search duration is not dependent on the number of nodes, rather the number of levels down the tree.

Linked List- yes, this is as easy as it sounds, it’s a list that's linked. They’re similar to arrays, with the key difference being that elements are not stored in a particular memory location or index. Rather each element is a separate object that contains a pointer or a link to the next object in that list. Elements are referred to as nodes. The analogy used is linked lists are like train cars, linked together, but can be reordered by changing how they’re linked.

Stack- the way stacks are structured is pretty self-explanatory, a collection of elements on top of each other. And they use the LIFO (last in, first out) principle, so the last thing to be added to the stack will be the first out. You add an element by pushing it on to the stack and remove an element by popping it off.

Queues- queues are similar to stacks but queues use the FIFO (first in, first out) principle. Elements are added to the end of the queue (enqueue) and elements are removed from the beginning of the queue (dequeue). Just like an actual queue/line, the first person waiting in line is the first to check out.

Graphs- are a relation-based data structure helpful for storing web-like relationships. Each node, or vertex, as they’re called in graphs, has a title (A, B, C, etc.), a value contained within, and a list of links (called edges) it has with other vertices.

This is a lot of information, and a lot of it's still on the new side to me. Hopefully this helps explain some common data structures. It definitely helped me get a better understanding of each of them. Comprehending and implementing these takes time and practice, so much practice. Next time I’ll get into algorithms. Thanks for reading.

💖 💪 🙅 🚩
liz_p
Liz P

Posted on November 29, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related