Data Structures Basics
What each data structure is, how it sits in memory, its types, what every operation costs and which Java class to use, with step-through visuals. Read the one you need before its patterns.
What you will learn
- Picture how arrays, linked lists, hash tables, trees, heaps and graphs are laid out
- State the cost of every common operation and explain why
- Name the types of each structure (singly vs doubly, BST vs heap, directed vs undirected…)
- Pick the right Java class for a job and avoid the legacy ones
- Choose a data structure from the operations a problem needs
- Read the constraints to know the target complexity, the data type, the memory budget and the edge cases
Linear Structures
Elements in a sequence: by position, by link, by order of arrival, or by key.
- Arrays & Strings: Contiguous memory, O(1) indexing, dynamic arrays that double, 2D arrays and immutable strings.
- Linked Lists: Nodes and pointers: singly, doubly and circular lists, and when they beat arrays.
- Stacks & Queues: Last-in-first-out and first-in-first-out, deques, and how both are built on arrays.
- Hash Tables: Hash functions, buckets, collisions and resizing: why lookups are O(1) on average.
Trees, Heaps & Graphs
Structures with branches: hierarchies, priority orders and networks.
- Trees: Vocabulary, the types of tree, binary search trees and the four traversals.
- Heaps & Priority Queues: A complete tree stored in an array: always know the minimum, in O(log n) per change.
- Graphs: Nodes and edges: directed, weighted, cyclic; adjacency lists vs matrices; BFS and DFS.
Putting It Together
From "what operations do I need?" and "how big is the input?" to the right structure and complexity.
- Choosing a Data Structure: One table of every structure and operation, and a decision guide for picking one.
- Reading Constraints: The problem's biggest hint: target complexity from n, int vs long, negatives, value ranges, memory, recursion depth and modulo 10^9 + 7.