Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Consider the programvoid function(int n) {int... Start Learning for Free
Consider the program
void function(int n) {
int i, j, count=0;
for (i=n/2; i <= n; i++)
for (j = 1; j <= n; j = j*2)
count++;}
The complexity of the program is
  • a)
    O(log n)
  • b)
    O(n2)
  • c)
    O(n2 log n)
  • d)
    O(n log n)
Correct answer is option 'D'. Can you explain this answer?
Most Upvoted Answer
Consider the programvoid function(int n) {int i, j, count=0;for (i=n/2...
The outer loop runs n/2 times The inner loop runs logn times Therefore the total time complexity of the program is O(nlogn) which is option (D)
Free Test
Community Answer
Consider the programvoid function(int n) {int i, j, count=0;for (i=n/2...
This program calculates the number of prime numbers that are less than or equal to the input integer n.

The program starts by initializing three variables: i, j, and count. i is set to n/2, which means the program will start checking for prime numbers from the middle of the range (n/2) instead of the beginning (1). j is set to 2, which will be used to check if i is a prime number. count is initialized to 0, which will be used to keep track of the number of prime numbers found.

The program then enters a loop that will iterate from i down to 2 (inclusive). For each iteration, the program checks if i is a prime number by iterating from j up to the square root of i (rounded up to the nearest integer). If i is divisible by any number between 2 and the square root of i, then i is not a prime number and the loop moves on to the next iteration. If i is not divisible by any number between 2 and the square root of i, then i is a prime number and count is incremented.

Finally, the program prints out the value of count, which represents the number of prime numbers that are less than or equal to n.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Question Description
Consider the programvoid function(int n) {int i, j, count=0;for (i=n/2; i <= n; i++)for (j = 1; j <= n; j = j*2)count++;}The complexity of the program isa)O(log n)b)O(n2)c)O(n2 log n)d)O(n log n)Correct answer is option 'D'. Can you explain this answer? for Computer Science Engineering (CSE) 2026 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Consider the programvoid function(int n) {int i, j, count=0;for (i=n/2; i <= n; i++)for (j = 1; j <= n; j = j*2)count++;}The complexity of the program isa)O(log n)b)O(n2)c)O(n2 log n)d)O(n log n)Correct answer is option 'D'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2026 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the programvoid function(int n) {int i, j, count=0;for (i=n/2; i <= n; i++)for (j = 1; j <= n; j = j*2)count++;}The complexity of the program isa)O(log n)b)O(n2)c)O(n2 log n)d)O(n log n)Correct answer is option 'D'. Can you explain this answer?.
Solutions for Consider the programvoid function(int n) {int i, j, count=0;for (i=n/2; i <= n; i++)for (j = 1; j <= n; j = j*2)count++;}The complexity of the program isa)O(log n)b)O(n2)c)O(n2 log n)d)O(n log n)Correct answer is option 'D'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Consider the programvoid function(int n) {int i, j, count=0;for (i=n/2; i <= n; i++)for (j = 1; j <= n; j = j*2)count++;}The complexity of the program isa)O(log n)b)O(n2)c)O(n2 log n)d)O(n log n)Correct answer is option 'D'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the programvoid function(int n) {int i, j, count=0;for (i=n/2; i <= n; i++)for (j = 1; j <= n; j = j*2)count++;}The complexity of the program isa)O(log n)b)O(n2)c)O(n2 log n)d)O(n log n)Correct answer is option 'D'. Can you explain this answer?, a detailed solution for Consider the programvoid function(int n) {int i, j, count=0;for (i=n/2; i <= n; i++)for (j = 1; j <= n; j = j*2)count++;}The complexity of the program isa)O(log n)b)O(n2)c)O(n2 log n)d)O(n log n)Correct answer is option 'D'. Can you explain this answer? has been provided alongside types of Consider the programvoid function(int n) {int i, j, count=0;for (i=n/2; i <= n; i++)for (j = 1; j <= n; j = j*2)count++;}The complexity of the program isa)O(log n)b)O(n2)c)O(n2 log n)d)O(n log n)Correct answer is option 'D'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the programvoid function(int n) {int i, j, count=0;for (i=n/2; i <= n; i++)for (j = 1; j <= n; j = j*2)count++;}The complexity of the program isa)O(log n)b)O(n2)c)O(n2 log n)d)O(n log n)Correct answer is option 'D'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev