43.3k views
2 votes
What is the big O notation for the given code snippet? int sum = 0; for (int i = 0; i < n; i ) sum ;

1 Answer

5 votes

Final answer:

The time complexity of the given code snippet is O(n), where n is the input variable.

Step-by-step explanation:

The given code snippet is a for loop that iterates from 0 to n. Inside the loop, the variable sum is updated by adding the value of i to it. The time complexity of this code can be represented using Big O notation, which analyzes the performance of an algorithm as the input size grows. In this case, the time complexity is O(n), where n is the value of the input variable.

User Umar Yusuf
by
8.3k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.

9.4m questions

12.2m answers

Categories