Western Governors University (WGU) ICSC2100 C949 Data Structures and Algorithms I Practice Exam

1 / 400

An example of which time complexity is represented by a doubly nested loop?

O(n)

O(log n)

O(n^2)

A doubly nested loop typically indicates that for each iteration of the outer loop, the inner loop executes a number of times proportional to the size of the input. If we consider an outer loop that runs n times, and for each of those iterations, the inner loop also runs n times, the total number of operations performed will be n multiplied by n, resulting in n^2.

This means the time complexity of the entire nested loop structure is quadratic, or O(n^2), which is characterized by the repeated operations that scale with the square of the input size. This is common in algorithms that involve processes like comparing each element in an array with every other element, such as in certain sorting algorithms or in brute-force solutions to problems.

In this case, the correct representation of time complexity for a doubly nested loop is indeed O(n^2), as each layer of nesting multiplies the total number of operations by the size of the input.

Get further explanation with Examzify DeepDiveBeta

O(nm)

Next Question
Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy