What is the time complexity of the following function fun()? int fun(int n) { int count = 0; for (int i = 0; i < n; i++) for (int j = 2n; j > 0; j--) count = count + 1; return count; } Group of answer choices
Added by M-Nica B.
Step 1
The function `fun()` contains two nested loops: - The outer loop runs from `i = 0` to `i < n`. - The inner loop runs from `j = 2n` to `j > 0`. Show more…
Show all steps
Your feedback will help us improve your experience
Madhur L and 83 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
What is the running time complexity of the following code snippet as a function of n (give your answer in theta notation): int Function1 (int n) { int count = 0; for (i = 0; <= n; i=i++) for (j = 0; j < i; j++) count++; return count; }
Madhur L.
Consider the following lines of code and compute the overall big O complexity: for i in range(n): if i % 3 == 0: for j in range(1000): sum += j else: for j in range(i + 1): sum += j
Supreeta N.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD