Data Structures
Data structures are specialized formats for organizing, processing, and storing data. They enable
efficient access and modification, forming the backbone of software applications.
Arrays are collections of elements stored in contiguous memory locations. They offer fast access
using indices but are fixed in size.
Linked lists consist of nodes, each containing data and a pointer to the next node. They offer
dynamic memory use and easy insertion/deletion but slower access.
Stacks are linear structures following LIFO (Last In, First Out). They're used in undo operations,
expression parsing, and recursion.
Queues follow FIFO (First In, First Out). They're used in scheduling, buffering, and breadth-first
search algorithms.
Trees are hierarchical structures. Binary trees have nodes with two children. Binary Search Trees
(BST) maintain sorted data. AVL trees are self-balancing BSTs.
Heaps are specialized trees used in priority queues. Max-heaps keep the largest element at the
root, while min-heaps keep the smallest.
Graphs represent relationships between entities. They consist of vertices (nodes) and edges
(connections). Graphs can be directed or undirected, weighted or unweighted.
Hash tables store data in key-value pairs for quick access. Hash functions map keys to indices, and
collisions are handled via chaining or open addressing.
Complex structures include tries (prefix trees) for efficient string searching, and segment trees for
range queries.
Data structure operations include insertion, deletion, traversal, and searching. Each operation has
time and space complexity.
Choosing the right data structure is crucial for algorithm efficiency. Time complexity is analyzed
using Big O notation (e.g., O(1), O(n log n)).