Course Data Structures Essentials

Computational Complexity

Course's Page 19 min Text by
User Image
Abacate

Hello ๐Ÿ˜„!

In this lesson, you will learn how to analyze the complexity of your code. This lesson is divided into three parts, being them:

  • What is complexity analysis;
  • Big-O notation;
  • Complexity groups.

What is complexity analysis

At some point as a programmer, you may have wondered how "fast" an algorithm you made is or if your algorithm executes all instances of a problem in a given time.

Analyzing the complexity of an algorithm is an essential skill that allows you to estimate the time your algorithm would spend to execute an input of size .

One way to estimate the complexity of an algorithm is to analyze the complexity of the repetition loops; that is, we can analyze what happens to an algorithm by analyzing the code snippets that have while or for because these repetition structures are usually the "bottleneck" of an algorithm. Look at the following code snippet:

//Code snippet with complexity O(nยฒ)
for(int i = 0; i < n; i++)
	for(int j = 0; j < n; j++)