The worst case time complexity for the following code represented in terms of Big O is _____. (Here the problem size is denoted by the parameter n of the function.) Coder my_test(n){ for (i=1; i<n; i++){ m = m + 1 } if(n>0){ my_test(n-1) } } O(n^2) O(n^2logn) O(nlogn) O((logn)^2)
Added by Cameron G.
Close
Step 1
The loop "for i=1 to n-1" runs n-1 times. So, the complexity of the loop is O(n-1) = O(n). Show more…
Show all steps
Your feedback will help us improve your experience
Michael Feffer and 92 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
Supreeta N.
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
Determine the Big O Notation Algorithmic Complexity for each of the following problems below, showing clearly step by step how you came by your answers. 4n^3 * (n+1)^2 (3n+5)^4 5n^3 + 2n^2 + 4n
Sri K.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD