Why Interviewers Ask This

This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Data Structures & Algorithms topics. It also reveals how well you can explain technical ideas to non-experts.

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.

Pro Tip

Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Data Structures & Algorithms codebase.