An Overview on Time Complexity & Space Complexity

Eliana Lopez
CodeX
Published in
5 min readApr 5, 2023

--

Often, there is more than one way to solve the same problem with different programs. However, determining which program is better or more efficient than another requires analyzing the program’s performance.

So how would you be able to compare the performance of different algorithms, is one program better than the other?

Well the answer to that question is quite simple, you have to see which program is more efficient.

There are two ways to determine which algorithm is more efficient:

  • The amount of space or memory an algorithm requires
  • The amount of time an algorithm requires to execute

To compare algorithms based on performance, it is essential to understand the concept of time and space complexity: Time complexity refers to the number of steps and operations that an algorithm uses to complete a task, while space complexity refers to the amount of memory that an algorithm uses to perform a task.

An Example: Sorting a List of Numbers

To illustrate the concept of space and time complexity, let us consider the task of sorting an arbitrary list of numbers. There are several algorithms that can be used to solve this task but let us look into bubble sort and quick sort specifically.

Bubble sort is a simple algorithm that compares adjacent elements and swaps them if they are in the wrong order. Bubble sort…

--

--