I'm studying about data structures and algorithms in that Time complexity and calculating time complexity of the programs.
I just wondered that how to calculate time complexity of non terminating loops such as infinite loops
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It only takes a minute to sign up.Sign up to join this community
If the program runs forever, its running time is infinite. So, if it always enters an infinite loop, its running time is infinite.
This is a degenerate case. Normally we focus only on algorithms that are certain to terminate (but see footnote).
Footnote: When studying randomized algorithms, this gets relaxed a bit, and we frequently look at algorithms that in principle could run forever if they keep getting an unlucky choice of random bits, but whose expected running time is finite. However, if you're just starting with algorithms, it's likely that you are dealing with deterministic algorithms, not randomized algorithms, so this is unlikely to come up.
Basically time complexity usage makes it easy to calculate the running time of a program and this complexity is depicted in Big-O notation. But since the loop never ends it has no "algorithmic time complexity" Trying to estimate such loop's complexity would be weird and of no good use as infinity is not a real number.