PAVANXDCL • DSA FOUNDATION

Master Dynamic Arrays

Understand dynamic arrays, Java ArrayList, Python list, resizing, capacity, operations and the interview patterns built on top of them.

01 — FOUNDATION

What is a Dynamic Array?

A dynamic array behaves like an array but can grow when more elements are needed.

▣

Resizable

When capacity is reached, a larger backing array can be allocated and elements copied over.

⚡

Fast Access

Index-based access is O(1) because elements live in contiguous array storage.

+

Amortized Append

Adding at the end is usually amortized O(1), with occasional O(n) resizing.

02 — JAVA VS PYTHON

ArrayList vs List

Both provide dynamic-array behavior, but the APIs and implementation details differ.

FeatureJava ArrayListPython list
TypeDynamic implementation of ListBuilt-in mutable sequence
Index accessO(1)O(1)
AppendAmortized O(1)Amortized O(1)
Insert at beginningO(n)O(n)
Remove from middleO(n) generallyO(n) generally
DuplicatesAllowedAllowed
Random accessYesYes
03 — INTERNALS

Size vs Capacity

This distinction is the key to understanding dynamic arrays.

SizeNumber of elements currently stored
→
CapacityNumber of slots available in backing storage
→
ResizeGrow backing storage when capacity is full
index 0
10
index 1
20
index 2
30
index 3
40
index 4
empty
index 5
empty
Size: 4  |  Capacity: 6  |  The exact growth policy is implementation-dependent.
04 — OPERATIONS

Important Operations

add / append

Add at the end. Usually amortized O(1).

get / index

Read by index in O(1).

set / update

Replace a value by index in O(1).

remove

Removing can require shifting, so generally O(n).

05 — COMPLEXITY

Time Complexity

OperationComplexityReason
Access by indexO(1)Direct indexing
AppendAmortized O(1)Occasional resize is spread over many appends
Insert middleO(n)Elements may need to shift
Remove middleO(n)Elements may need to shift
Search by valueO(n)May scan all elements
06 — VIDEO LEARNING

Watch Videos

▶
BEGINNER

DA-01: Array basics & methods

▶
BEGINNER

DA-02: Intro Part 2 — Iteration & in-place ops

▶
Algorithm

DA-03: Prefix Sum Array

Important!!

▶
Medium

DA-04: Nested List + HackerRank challenges

▶
Medium

DA-05: Brute Force & Subarrays

Part 1.

▶
Medium

DA-06: Brute Force & Subarrays

Part 2.

▶
Practise

DA-07: Merge Strings Alternately

Prepare for common interview questions.

▶
INTERVIEW

DA-08: Product of Array Except Self

Prepare for common interview questions.

▶
INTERVIEW

DA-09: Increasing Triplet Subsequence

Prepare for common interview questions.

▶
INTERVIEW

DA-10: Can Place Flowers

Prepare for common interview questions.

▶
IMPORTANT!

DA-11: Nested List

Core Concept.