Time Complexity and Big O

A few weeks ago, I used to try competitive programming, a kind of challenge for developers who want to improve their skills with hands-on exercises, on Leetcode. I gave up in a few days because I did not have enough skills in C++ and those challenges were pretty hard for me.
I have just enrolled in a course that focuses on Data Structures & Algorithms in C++.

Time Complexity

In computer science, it can be defined as the amount of time that requires to run an algorithm.

To exemplify it, I use an example from geeksforgeeks.com.

The example

Imagine a classroom of 32 students in which you gave your pen to one person. You have to find that pen without knowing to whom you gave it. 

(n = size)

The O(n2) solution is to ask everyone and also inquire about the others if they have it. n2 means you need to repeat your action 32*32=1024 times.

The O(n) solution is to ask everyone if there is, and if the response is false, ask the next one. 'n' means you need to repeat your action 32 times, which is better than the first method.

The O(log n) algorithm involves dividing the class into two groups and then asking, "Is it on the left side or the right side of the classroom?" Repeat this process until you find the student who has your pen. (log n) means you need to log base 2 of 32, which is equal to 5 times repeating your action. This is considered the best method.

Big O Cheat Sheet

As you can see, O(log n) seems one of the best. It's important to know that. I will not detail anymore this because I don't have depth information.

I know it's more complex than learning it in a superficial blog post so if you need more information, you just google it!