Time complexity and Big O notation
When writing the program just correctness is not enough. The program should be fast and no time being used in a worthless way of writing the program.
The computer runs pretty fast, there won’t be a problem when you run the program with the input size only 10 or 100. But if the program got the input size of 10,000 or more. The program may take forever to execute. That’s why we need to analyze how much time we need to execute the program with Big O notation.
Big O notation represented by the symbol ‘O(_)’. The Big O is the worst case your program could run. There are 8 types of Big O notation.
The blank space in ‘O(_)’ means how many times your program has to run if there are inputs ‘n’.
Example:
The example pseudo-code above. The big O of this code is O(n) because the program will run the for loop for n times. If the input is 1000, the program will loop for 1000 times starts from 0.