Advertisements
Advertisements
Question
For the given code segment, write Big O notation for worst case complexity.
for (int i=1; i<=P; i++)
{ Statements }
for (int j=1; j<=P; ++j)
for (int k=1; k<=Q; k++)
{ Statements }
Very Short Answer
Advertisements
Solution
First loop runs from 1 to P so O(P).
Second loop runs 1 to P so O(P).
Third loop runs from 1 to Q so O(P * Q) is the worst time complexity.
shaalaa.com
Is there an error in this question or solution?
2024-2025 (March) Official Board
