ELI5: Data Structures Basics

What are data structures and why does it matter for coding?
When given a set of data values, the data can be formatted to fit certain parameters (or structures) to improve data access, manipulation, and modification. By focusing on these aspects, the user benefits from efficient and quick responses from a software system.

Amongst the variety of data structures, eight are commonly implemented — arrays, linked lists, stacks, queues, hash tables, trees, binary search trees, heaps, and graphs.

Arrays: a collection of variables (all the same data type) stored contiguously and sequentially in memory; each element has a specific index that allows it to be identified and accessed. Arrays have a fixed length of elements (static array) but can be expanded by creating a copy of the elements and increasing the capacity (dynamic array).

Figure. Array Data Structure

Linked Lists: a chain of nodes composed of its data and a pointer referring to its succeeding node. Aside from a node’s pointer, the linked list contains a head pointer indicating where the start of the list exists; if the list is empty the head pointer points to null. Linked lists are applied to implement file systems, hash tables, and adjacency lists.

Figure. Linked List Data Structure

Stacks: a linear data structure that follows the last-in-first-out (LIFO)/ first-in-last-out (FILO) method; a real-life example is if your favorite book were in the middle of a stack of books, all the books “pushed” onto the stack after it needs to be popped off before your favorite book can be accessed.

Figure. Stack Data Structure

Queues: a linear data structure that follows the first-in-first-out (FIFO) method.

Figure. Queue Data Structure

Hash Tables: one definition of hash is “to chop and mix” — in this case, data inputs are “chopped” into pieces and “mixed” into your data table non-sequentially and non-contiguously., The data is accessible through the use of key:value pairs in a table and improves the average time complexity to O(1) for search, insert, and delete methods.

Figure. Hash Table Data Structure

Trees: a nonlinear data structure with nodes connected by directed or undirected edges. One node is designated as the root and the tree expands from parent to child. At the end of the tree are leaf nodes which have no child notes.

Figure. Tree Data Structure

Binary Search Tree (BST): a type of tree with the left child node holding keys lesser than the parent node and the right child node holding keys greater than the parent node. Binary search trees can be balanced (applying a data algorithm to rearrange the nodes to prevent poor data arrangement [ex. formatting data to look like a linked list which has a less ideal search complexity of O(n)]. An advantage of a BST is quick lookup, addition and removal of data items, and implementation of data sets and lookup tables; the order of the nodes in a BST allows for comparison algorithms to skip about half of the tree nodes.

Figure. Binary Search Tree

Heaps: another type of tree-based data structure that holds a heap property (can be thought of as a rule for the tree’s construction). Common heaps are max heaps and min heaps. The max heap’s root node holds the key with the highest value and the min heap’s root node holds the key with the lowest value. This heap property holds true recursively for sub-trees in the heap.

Figure. Heap Data Structure

Graphs: a non-linear/network-like data structure with nodes that are connected to each other by edges (lines). Examples of graph-usage include paths in a city or a telephone network.

Figure. Visualization of graph data structure

1 https://www.bigocheatsheet.com/
2 https://www.cs.cmu.edu/~adamchik/15-121/lectures/Trees/trees.html



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store