Data Structures

Reading time
2 min read
Word count
282 words
Diagram count
0 diagrams

Source: Victor Bona's Obsidian Compendium snapshot, Knowledge base/Data Structures/Data Structures.md.

Data Structures

A data structure is a specialized format for organizing, processing, retrieving, and storing data. Choosing the right data structure is crucial for writing efficient algorithms and building performant software systems.

Fundamental / Linear Structures

Hash-Based Structures

Tree Structures

Graph Structures

Advanced / Specialized Structures


Complexity Reference

StructureAccessSearchInsertDeleteSpace
ArrayO(1)O(n)O(n)O(n)O(n)
Linked ListO(n)O(n)O(1)O(1)O(n)
StackO(n)O(n)O(1)O(1)O(n)
QueueO(n)O(n)O(1)O(1)O(n)
Hash TableN/AO(1)*O(1)*O(1)*O(n)
BSTO(log n)*O(log n)*O(log n)*O(log n)*O(n)
AVL/Red-BlackO(log n)O(log n)O(log n)O(log n)O(n)
HeapO(1) topO(n)O(log n)O(log n)O(n)
TrieO(k)O(k)O(k)O(k)O(n*k)

*Average case; worst case may differ

Choosing the Right Data Structure

Consider these factors:

  1. Access patterns - Random access? Sequential? By key?
  2. Operation frequency - Which operations are most common?
  3. Memory constraints - How much overhead is acceptable?
  4. Ordering requirements - Do elements need to stay sorted?
  5. Concurrency - Will multiple threads access the structure?

Common scenarios: