Published on

Data Structures: A Quick Reference

Authors
  • avatar
    Name
    Loi Tran
    Twitter

Introduction

Here are a few things to consider when trying to identify what data structure to use for algorithms.

We'll cover the following sorting algorithms.

Array/List

Hash Table/Map

Set

Stack

Last In First Out(L.I.F.O.)

SituationUseReasoning / Pattern
Need to process elements in reverse orderStackLIFO (Last In, First Out)
Tracking function calls / recursionStackCall stack mirrors nested calls
Undo functionality (e.g., editor)StackLast action undone first
Balanced parentheses / bracket matchingStackPairs resolved in reverse order

Queue

First In First Out(F.I.F.O.)

SituationUseReasoning / Pattern
Need to process elements in the order receivedQueueFIFO (First In, First Out)
Level-order traversal of tree (BFS)QueueProcess nodes layer by layer
Scheduling tasks / simulationQueueTasks processed in arrival order

Deque

Double ended queue

Linked List

A linear data structure where elements, called nodes, are linked together.

Tree

A data structure composed of nodes that contain values & leafs.

Binary Tree

A tree where each node has only two children nodes, left & right.

Binary Search Tree(BST)

A binary search tree where the value of the left child is less than the parent node's value. The right node's value is greater than the parent node's value.

Heap

SituationUse
Always want largest/smallestMax/Min heap
Keep top K of somethingMin/Max heap of size K
Custom processing orderPriority queue (heap)
Streaming dataHeap(s) to track top items

Segment Tree/Fenwick Tree

Trie(Prefix Tree)

Graph

Nodes & Edges. Node's are airports and edges are the flights between them.

Furthermore graphs can be directed or undirected meaning that the flights can be listed as pointing from one airport to another or both ways(undirected).

The edges can have weighted as well meaning that the edges from one node to another may vary in value. For example the price from an airport to airport a & b may differ.

Union-Find(Disjoint Set)

Conclusion

Data StructureTypical Use Cases
Array/ListIndex-based access, iteration
Hash Table (Map)Fast lookups, counting, caching
SetFast membership tests, removing duplicates
StackUndo operations, expression parsing, backtracking, DFS
QueueScheduling, BFS, order of processing
DequeSliding window problems, double-ended queue operations
Linked ListEfficient insertions/deletions at head/tail
TreeRepresenting data with a parent-child relationship, such as file systems, organizational charts, or XML/HTML documents.
Binary TreeHierarchical data, expression parsing
Binary Search Tree (BST)Sorted data, efficient range queries
Heap (Priority Queue)Getting largest/smallest elements efficiently, scheduling
Trie (Prefix Tree)Prefix search, autocomplete
GraphNetwork problems, path-finding, connected components
Union-Find (Disjoint Set)Connectivity queries, Kruskal’s algorithm
Segment Tree / Fenwick TreeRange queries and updates (e.g., sum, min, max)