Time Complexity Simplified
We (Beginners) often assume; Time Complexity is the time taken for the code to run, BUT its not.
Because, Depending on the Computer ( System / OS ), and the version ( Old / Latest ), the time taken for the system to run the code differs, hence time taken is NOT time complexity ( T != Time taken )
Actual Definition: The rate at which the time taken increases with respect to the Input size.
Source: TUF Striver’s A2Z DSA sheet
So, The question is — ? How do we calculate Time complexity of a problem? simple, It is calculated in Big-O notation → O( time taken )
There are THREE major rules to be followed before calculating Time complexity: 1) Always consider Worst case scenario 2) Avoid Constants 3) Avoid lower values.
Note: Other than Big-O notation, there are other terms such as Theta and Omega ( Though these two terms are not particularly asked in interviews, It’s better to know they exist :)
Space Complexity — It is defined as the Memory space taken by the input in any system, Which is also calculated using Big-O notation.
Space complexity = Auxiliary space ( Space taken to solve the problem ) + Input space ( Space taken to store the problem )
you can watch the detailed explanation by Striver TUF. Happy Learning :)
Subscribe to my newsletter
Read articles from Alla Yasheela directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Alla Yasheela
Alla Yasheela
I'm Yasheela, an undergraduate with a deep interest in DevOps, and cloud technologies. Currently working on exciting projects on all things DevOps. I’m passionate about simplifying complex concepts and sharing practical insights. Through my Hashnode blog, I document my learning journey, from building scalable applications to mastering cloud services, with the goal of empowering others to grow their tech skills. Let's Learn Together !!