There can be several aspects when you think about analysis of algorithms. You may be writing a large scale application where you have to decide between two choices. You may be trying to submit a solution to some online competition and you want a higher score, or probably you may just want to write fewer lines of code.
Analysis during an Interview
Let’s say you are appearing for an interview. The person who is interviewing you gives you a problem to solve. He or she is not just interested in the solution but rather, they want to see how you approach the problem and what solution do you eventually come up with. Even after you have come up with a solution, there is a very good chance that your interviewer would ask you to think other solutions to the problem. That is probably because a better solution to the problem exists, and he/she wants you to figure it out.
You start to think again and this is where analysis of algorithms comes in handy. You could start to think of multiple solutions, but you need to first figure out for yourself, if they are better than the ones you have already told.
Analysis based on performance
An algorithm is basically just a series of steps to solve a problem. But it is not necessary that it will perform the same under all kinds of test cases.
Think about it like a car. If you get a car, it is not necessary that it will perform the same in a city, as on a highway. What about off road? It will have different kinds of performance.
Similar is the case with algorithms as well. An algorithm can behave differently based on the type of input data you have. This is known as the time complexity of an algorithm.
Topics covered in the playlist:
- How to Compare two Algorithms: Just like you need to have certain criteria in mind to compare two products, we need to determine some parameters based on which we can evaluate two algorithms.
- Time Complexity of an Algorithm: You cannot execute every algorithm that you write and calculate the time for each kind of input test cases. The time complexity is used to annotate how to measure the speed of an algorithm.
- What is Big O: We are always interested in the worst case performance of an algorithm. This is where the Big O notation comes in handy for analysis of algorithms.
- Rate of Growth of an Algorithm: You must also be able to determine how much more time your algorithm will take if you increase the input size by some certain quantity.
Watch these videos to do a deep dive into each of the topics.