Programming-for-Output-Problems
October 6, 2023Programming-for-Output-Problems
October 6, 2023Programming-for-Output-Problems
Question 12
|
Consider the following segment of C-code:
The number of comparisons made in the execution of the loop for any n > 0 is:
⌊log 2n⌋*n
|
|
n
|
|
⌊log 2n⌋
|
|
⌊log 2n⌋+1
|
Question 12 Explanation:
Explanation:
Let us consider n=6, then
1<=6 (correct)
2<=6 (correct)
4<=6 (correct)
8<=6 (False)
4 comparisons required
Option A:
⌊log n⌋+1
⌊log 6⌋+1
3+1=4 (correct)
Option B:
n=6 (False)
Option C:
⌊log n⌋
⌊log 6⌋=3 (False)
Option D:
⌊log 2n⌋+1
⌊log 26⌋+1=2+1=3 (False)
Let us consider n=6, then
1<=6 (correct)
2<=6 (correct)
4<=6 (correct)
8<=6 (False)
4 comparisons required
Option A:
⌊log n⌋+1
⌊log 6⌋+1
3+1=4 (correct)
Option B:
n=6 (False)
Option C:
⌊log n⌋
⌊log 6⌋=3 (False)
Option D:
⌊log 2n⌋+1
⌊log 26⌋+1=2+1=3 (False)
Correct Answer: D
Question 12 Explanation:
Explanation:
Let us consider n=6, then
1<=6 (correct)
2<=6 (correct)
4<=6 (correct)
8<=6 (False)
4 comparisons required
Option A:
⌊log n⌋+1
⌊log 6⌋+1
3+1=4 (correct)
Option B:
n=6 (False)
Option C:
⌊log n⌋
⌊log 6⌋=3 (False)
Option D:
⌊log 2n⌋+1
⌊log 26⌋+1=2+1=3 (False)
Let us consider n=6, then
1<=6 (correct)
2<=6 (correct)
4<=6 (correct)
8<=6 (False)
4 comparisons required
Option A:
⌊log n⌋+1
⌊log 6⌋+1
3+1=4 (correct)
Option B:
n=6 (False)
Option C:
⌊log n⌋
⌊log 6⌋=3 (False)
Option D:
⌊log 2n⌋+1
⌊log 26⌋+1=2+1=3 (False)
Subscribe
Login
0 Comments