75.0k views
0 votes
Imagine that we have a list of names called nameList. There are various algorithms we could run on it. Here's one such algorithm, which compares each name in the list to every other name:

1 Answer

9 votes

Answer:

The algorithm has a quadratic time complexity of O(n^2)

Step-by-step explanation:

The algorithm has two nested for-loop statements. The length of the name list is denoted as "n". Every name searched in the name list has a time complexity of n, therefore the time complexity of finding two names is (n x n) = n^2, which is denoted as O(n^2) in Big-O notation.

User Alvaro Aguilar
by
5.4k points