What is an array?
Answer
An array is a linear data structure that stores elements of the same type in contiguous memory locations, each accessible by an index (0-based in most languages). Characteristics: Fixed size (static arrays) — size declared at creation; Random access — any element accessible in O(1) by index since the address = base_address + (index × element_size); Cache-friendly — contiguous memory means CPU cache lines are used efficiently. Operations: Access by index: O(1); Search (unsorted): O(n); Search (sorted, binary search): O(log n); Insert at end: O(1) amortized (dynamic arrays); Insert at middle: O(n) (must shift elements); Delete at middle: O(n) (must shift); Append: O(1). Dynamic arrays (ArrayList in Java, list in Python, vector in C++): automatically resize when full — typically double the capacity (amortized O(1) append). Pros: fast access, cache-friendly, simple. Cons: fixed size (static), expensive insertion/deletion in middle, wasted space if many deletions. Arrays are the foundation for most other data structures and are ubiquitous in algorithms.