Grokking Algorithm Complexity and Big-O
Ask Author
Back to course home

0% completed

Vote For New Content
Linear Space: O(n)
On this page

Linear Space Complexity O(n) refers to algorithms where the memory usage grows linearly with the input size. This occurs when an algorithm needs to store a new copy of the input or requires auxiliary data structures proportional to the input size.

Key Characteristics

In an algorithm with O(n) space complexity:

  • The memory usage increases linearly with the size of the input.
  • Common in tasks that duplicate the input data or process each element with additional storage.

Code Example 1: Copying a String

Let’s look at an example where we create a copy of a string

.....

.....

.....

Like the course? Get enrolled and start learning!

On this page