Example: Time Complexity of an Algorithm With Nested Loops

In this lesson, you will learn how to compute the time complexity of an algorithm that involves nested for loops.

Now, we’ll analyze an algorithm with nested for loops.

A program with nested for loops

Consider the following Java program:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.