Week 2-3 - Analysis of Algorithms
Week 2-3 - Analysis of Algorithms
● Algorithm analysis
● Time complexity
● Experimental approach
● Theoretical approach
○ Count primitive operations
● Worst-case time complexity
1. Program Performance
As we know from the previous lecture, the DSA can help to improve the quality of the
application so as to measure its effectiveness, the term Program Performance was
used. Program performance is the amount of computer memory/space and time needed
to run a program.
Memory/ Spac complexity is the amount of memory that a program uses when it runs.
Usually measured in Bytes, KB, or MB.
Time complexity is the amount of time that a program needs to run. Usually measured
by the number of operations.
2. Time complexity
Time complexity is the amount of computer time a program needs to run, as a function
of the length of the input.
Unlike space complexity, the modern user usually cares more about the time that an
app takes than the space in memory because the memory can be upgraded but the time
is still a problem for us. If there are many solutions to a problem, we’ll choose the
fastest.
Besides that, some computers require upper limits for program execution times, and
nowadays, real-time response is one of the requirements of an application.
In some cases: Theoretically, we can solve the problem, but practically, we can't; it
just takes too long when the input size gets larger. E.g: RSA public-key
cryptosystems.
9. Asymptotic behavior
The leading term (fastest growing term) will dominate the running time.
To compare the time complexity of two algorithms, we compare the growing rate of
the leading terms. (Note: compare n3 and 2n when n = 1, 2, 4, 8,…).