The Start of Journey of DSA.
Table of contents
Hello! everyone, today's the start of my new journey in DSA. Every programmer knows how valuable the concept of DSA is for any kinda programming work. Without the knowledge of DSA, wellstable codes can't be possibly made. This is the day 1 of the 100-day challenge. Starting with one of the most important topics, what we have got here is Time Complexity. A basic yet tricky topic for most beginners.
Time Complexity
Most of the learners who study time complexity assume that the time taken by any program is the time complexity of the program. However, that's not the case because time taken depends upon the system configuration of any computer or laptop. In reality, the time complexity is the rate of change of time taken with respect to increases in the input size of the code.
Time Complexity depends upon certain factors: -
Speed of the device you are working on.
Speed of data transfer if coding on any online platform.
Size of the code.
Time Complexity is measured in the form of a function and represented with the help of mathematical symbols i.e. Asymptotic Notations. There are three types of asymptotic notations: - Big-O Notation, Omega Notation and Theta Notation. Whereas most of the time, we measure time complexity in the form of Big-O Notation because it represents the worst-case complexity.
Big-O Notation
The Big-O Notation is a common way to express time complexity. Learn about Big O and how to represent the upper bound of an algorithm's running time. Common notations you'll encounter include O(1), O(log n), O(n), O(n log n), O(n^2), etc.
The function f(n) = O(g(n)) iff there exits a positive constants C and n0 such that f(n) <= C(g(n)) for all n > n0.
Example: -
f(n) = 2n + 3 and C(g(n)) = 7n
2n + 3 <= 7n
(for n = 1)
5 <= 7
Subscribe to my newsletter
Read articles from Sawan Badhwar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by