Algorithms and Data Structures

Lesson 02 · 15 min

Arrays and hash tables

Why index access is instant while search is not, and how a Map saves you from nested loops.

15 minLesson 2 of 8Practice includedAsk AI on any point

An array stores its elements next to each other. That is why arr[i] is O(1): the address of the element can be computed right away. But finding an element by value is only possible by scanning: indexOf and includes run in O(n).

Sign in to continue

The rest of this lesson opens after sign up

The first lesson of every course is open without an account. To read on, solve the practice and use Ask, create a free account or log in.