Fundamentals 22 min read

Master the 10 Essential Data Structures: From Arrays to Graphs

This article provides a comprehensive visual guide to ten fundamental data structures—including arrays, linked lists, skip lists, stacks, queues, trees, heaps, hash tables, and graphs—explaining their concepts, characteristics, and typical use cases for programmers and interview preparation.

macrozheng
macrozheng
macrozheng
Master the 10 Essential Data Structures: From Arrays to Graphs

Data structures are essential for programmers; they organize data based on relationships, affecting processing efficiency.

Common structures are divided into linear (arrays, stacks, queues, linked lists) and non‑linear (trees, graphs, etc.). This article uses diagrams to introduce nine typical structures.

1. Array

Arrays store homogeneous elements in contiguous memory, accessed by index. Elements are stored sequentially, and adjacent elements' addresses differ by the element size.

2. Linked List

Linked lists add a pointer field to each node, forming a chain. Nodes contain data and a pointer to the next node, allowing flexible insertion and deletion by adjusting pointers.

Variants include singly linked list, doubly linked list, and circular linked list.

Linked List vs Array

Choosing between them depends on their trade‑offs; this comparison is a frequent interview topic.

3. Skip List

Skip lists add multi‑level indexes to a linked list, reducing search complexity from O(n) to O(log n). They support efficient dynamic insertion and deletion, similar to balanced trees, and are used in Redis and LevelDB.

Each index node has a forward pointer and a down pointer to the lower level.

4. Stack

A stack is a linear structure with LIFO semantics; only one end is accessible for push and pop operations. It serves as a temporary container for ordering data.

5. Queue

A queue follows FIFO order, opposite to a stack. It is often paired with a stack to maximize functionality.

6. Tree

Trees represent hierarchical parent‑child relationships. Each node may have multiple children; the root has no parent. Variants include binary trees, complete binary trees, full binary trees, AVL trees, red‑black trees, etc.

Complete binary tree : All levels are full except possibly the last, which is filled from left to right.
Full binary tree : Every node has either 0 or 2 children.

Balanced binary tree (AVL)

AVL trees keep the height difference between left and right subtrees ≤ 1, guaranteeing O(log N) search time, but rotations are required on insert/delete. Four rotation cases exist: LL, RR, LR, RL. Simple left and right rotations are described.

Red‑Black Tree

Red‑black trees relax strict balance for faster updates. They have five properties:

Each node is red or black. The root is black. All leaves (NIL) are black. Red nodes have black children. Every path from a node to its descendant leaves contains the same number of black nodes.

Used in the C++ STL.

Red‑Black Tree vs AVL

7. Heap

A heap is a tree‑like structure stored in an array; it is a complete binary tree where each parent’s key is ≥ (max‑heap) or ≤ (min‑heap) its children.

For a parent at index n (0‑based), children are at 2n+1 and 2n+2.

Heaps implement priority queues and are used for heap sort, top‑K queries, etc.

8. Hash Table

A hash table maps keys to values via a hash function, achieving O(1) average access. Various hash functions (direct addressing, division, multiplication, etc.) are described.

Collisions occur when different keys map to the same address; common resolution methods include open addressing, rehashing, chaining, and overflow area.

Chaining often combines arrays and linked lists; sometimes a red‑black tree replaces the chain for better performance.

Key lookup:

key

value

address; collisions may cause overwrites, so conflict‑resolution strategies are essential.

9. Graph

Graphs consist of vertices and edges, which may be directed or undirected and weighted. Common storage methods are adjacency matrix and adjacency list.

Adjacency matrix uses a 2‑D array; for undirected graphs it is symmetric, while directed graphs are not.

Adjacency list stores each vertex’s outgoing neighbors as a linked list; an inverse adjacency list stores incoming neighbors, enabling full representation.

Cross‑linked lists combine both directions but can be further optimized.

10. Summary

Data structures are foundational to computer science. While this article provides a visual overview of nine common structures, mastering them requires deeper study of optimizations and practical usage.

Programmingdata structuresinterview preparationAlgorithmsComputer ScienceFundamentals
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.