Data Structures19 sections · 729 units
Open in Course

Array Fundamentals

What you already know

You already know arrays: contiguous memory, O(1)O(1) access by index, O(n)O(n) search. I won't rehash basics. What you might not know is how to exploit array structure for speed.

The next technique I'll show you turns O(n)O(n) range queries into O(1)O(1). That's not a typo.

One million queries on a million elements goes from a trillion operations to just one million. How? By precomputing the right information.