Complexity analysis

Overview

An array organizes items sequentially, one after another in memory. Each position in the array has an index, starting at 0.

Strengths:

Weaknesses:

The following are an array’s standard operations and their corresponding time complexities:

Inserting

If we want to insert something into an array, first we have to make space by "scooting over" everything starting at the index we're inserting into.

In the worst case we're inserting into the 0th index in the array (prepending), so we have to "scoot over" everything in the array. That's O(n) time.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/af7675d4-5502-462b-bf7d-55b35be4c350/Untitled.png