Data Structures
Learn how programs organize and store data efficiently using arrays, linked lists, trees, graphs, and more.
What are Data Structures?
A data structure is a way of organizing, managing, and storing data so it can be accessed and modified efficiently. Choosing the right data structure is critical for writing fast and memory-efficient programs.
Array
An array stores elements of the same type in contiguous memory. Access by index is O(1) — instant. Inserting or deleting in the middle is O(n) — slow for large arrays.
int numbers[] = {10, 20, 30, 40, 50}; Linked List
A linked list stores elements as nodes, each pointing to the next. Insertions and deletions are O(1) at the head, but accessing an element requires traversal — O(n).
- Singly Linked List — Each node points to the next.
- Doubly Linked List — Each node points both forward and backward.
- Circular Linked List — The last node points back to the first.
Stack
A stack follows LIFO (Last In, First Out). Think of a stack of plates — you only add or remove from the top. Used in function call management, undo features, and expression parsing.
Queue
A queue follows FIFO (First In, First Out). Like a line at a store — the first person in is the first served. Used in task scheduling and breadth-first search.
Tree
A tree is a hierarchical structure with a root node and child nodes. The most common type is the Binary Search Tree (BST) where the left child is smaller and the right child is larger than the parent — enabling fast O(log n) search.
Hash Table
A hash table maps keys to values using a hash function. Average-case lookup, insertion, and deletion are all O(1). Used heavily in databases, caches, and language interpreters.
Graph
A graph consists of nodes (vertices) connected by edges. Used to model networks, maps, social connections, and dependencies. Key algorithms include BFS, DFS, Dijkstra's shortest path, and more.
What's Next?
Explore Algorithms to learn how to process these structures efficiently, or check out DBMS to see how databases organize data at scale.