finding the running time for my algorithm for finding whether an input is prime in terms of the input

前端 未结 1 1054
挽巷
挽巷 2021-01-25 22:36

This is my function for finding prime numbers

void print(int num)
{
    for(int i=2; i

        
相关标签:
1条回答
  • 2021-01-25 22:53

    Yes, the loop runs n/2-1 times and only contains commands of constant complexity, so your runtime scales as a*(n/2-1) for some a. In big-o this is written as O(n/2-1) and because constant factors don't matter this is equal to O(n).

    (as an aside: it is actually theta(n) which means, that it is not just bounded from above by n but also from below by n)

    0 讨论(0)
提交回复
热议问题