Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
int IsPrime(n)
{
    int i, n;
    for (i=2; i<=sqrt(n);i++)
        if(n%i == 0)
            {printf("Not Prime \n"); return 0;}
    return 1;
}

Here the loop executes for $ \Theta (\sqrt{n}) $ time . But my teacher said that it is not because the lower bound is $ \omega (1) $ I was not able to understand why it so .

Q1] Could some of you explain which one of us is right justifying reason ?

Q2] What is the importance of " return 0 " ? What would have been the change if there had no " return 0 inside looping function ?

Q3] In general What is the meaning of return 0, 1, -1 in C programming language ? I have read thisthis from stackoverflow but that didn't solve . Need little bit explanation

int IsPrime(n)
{
    int i, n;
    for (i=2; i<=sqrt(n);i++)
        if(n%i == 0)
            {printf("Not Prime \n"); return 0;}
    return 1;
}

Here the loop executes for $ \Theta (\sqrt{n}) $ time . But my teacher said that it is not because the lower bound is $ \omega (1) $ I was not able to understand why it so .

Q1] Could some of you explain which one of us is right justifying reason ?

Q2] What is the importance of " return 0 " ? What would have been the change if there had no " return 0 inside looping function ?

Q3] In general What is the meaning of return 0, 1, -1 in C programming language ? I have read this from stackoverflow but that didn't solve . Need little bit explanation

int IsPrime(n)
{
    int i, n;
    for (i=2; i<=sqrt(n);i++)
        if(n%i == 0)
            {printf("Not Prime \n"); return 0;}
    return 1;
}

Here the loop executes for $ \Theta (\sqrt{n}) $ time . But my teacher said that it is not because the lower bound is $ \omega (1) $ I was not able to understand why it so .

Q1] Could some of you explain which one of us is right justifying reason ?

Q2] What is the importance of " return 0 " ? What would have been the change if there had no " return 0 inside looping function ?

Q3] In general What is the meaning of return 0, 1, -1 in C programming language ? I have read this from stackoverflow but that didn't solve . Need little bit explanation

added 425 characters in body
Source Link
int IsPrime(n)
{
    int i, n;
    for (i=2; i<=sqrt(n);i++)
        if(n%i == 0)
            {printf("Not Prime \n"); return 0;}
    return 1;
}

Here the loop executes for $ \Theta (\sqrt{n}) $ time . But my teacher said that it is not because the lower bound is $ \omega (1) $ I was not able to understand why it so . Could

Q1] Could some of you explain which one of us is right justifying reason and providing explanations?

Q2] What is the importance of " return 0 " ? What would have been the change if there had no " return 0 inside looping function ?

Q3] In general What is the meaning of return 0, 1, -1 in C programming language ? I have read this from stackoverflow but that didn't solve . Need little bit explanation

int IsPrime(n)
{
    int i, n;
    for (i=2; i<=sqrt(n);i++)
        if(n%i == 0)
            {printf("Not Prime \n"); return 0;}
    return 1;
}

Here the loop executes for $ \Theta (\sqrt{n}) $ time . But my teacher said that it is not because the lower bound is $ \omega (1) $ I was not able to understand why it so . Could some of you explain which one of us is right justifying reason and providing explanations ?

int IsPrime(n)
{
    int i, n;
    for (i=2; i<=sqrt(n);i++)
        if(n%i == 0)
            {printf("Not Prime \n"); return 0;}
    return 1;
}

Here the loop executes for $ \Theta (\sqrt{n}) $ time . But my teacher said that it is not because the lower bound is $ \omega (1) $ I was not able to understand why it so .

Q1] Could some of you explain which one of us is right justifying reason ?

Q2] What is the importance of " return 0 " ? What would have been the change if there had no " return 0 inside looping function ?

Q3] In general What is the meaning of return 0, 1, -1 in C programming language ? I have read this from stackoverflow but that didn't solve . Need little bit explanation

Source Link

What is the time complexity of the piece of code given below

int IsPrime(n)
{
    int i, n;
    for (i=2; i<=sqrt(n);i++)
        if(n%i == 0)
            {printf("Not Prime \n"); return 0;}
    return 1;
}

Here the loop executes for $ \Theta (\sqrt{n}) $ time . But my teacher said that it is not because the lower bound is $ \omega (1) $ I was not able to understand why it so . Could some of you explain which one of us is right justifying reason and providing explanations ?