CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
3
You visited us 3 times! Enjoying our articles? Unlock Full Access!
Question

Cosider the following C code segment:
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;
}
Let T(n) denote the number of times the for loop is executed by the program on input n. Which of the following is true?

A
None of these
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
T(n) = O(n) and T(n) = Ω (n)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
T(n) = O(n) and T(n) = Ω (n)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
T(n) = O(n) and T(n) = Ω (1)
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
Open in App
Solution

The correct option is D T(n) = O(n) and T(n) = Ω (1)
T(n) denote the number of times the for loop is execute by the program on input n.
T(n) = n + 1
When n = 1 then best case occurs so T(n) takes constant time i.e., T(n) = Ω(1).
In worst case,
T(n) = n + 1
So T(n) = O(n).

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Evaluation of Determinants
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon