0
$\begingroup$

ive been struggling with counting primitive operations. I know that you do not have to outline every operation that happens in your pseudocode but this is never the less a bit complicated for me. Heres my example:

enter image description here T(n) = 3n+14 ∈ O(n) this is how I interpreted this code, as far as i can see these for loops are independend from each other meaning we still have O(n) and not O(n^2) right? Also unsure what recursion exactly is as an operation. im grateful for every advice

$\endgroup$
1
  • $\begingroup$ Please fix some statements. $\endgroup$
    – gnasher729
    Commented May 21 at 18:13

1 Answer 1

0
$\begingroup$

Write down the number of primitive operations and the result returned in the cases n=0, n=1.

Write down the number of primitive operations and the return value for 2 <= n <= 7. In the recursive call the same function is called with the first argument 0 or 1, and you wrote down the primitive operations and result for that case.

Then handle 8 <= n <= 31, 32 <= n <= 127 etc.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.