81. What is the time complexity of the following code used to convert a decimal number to its binary equivalent?
#include<stdio.h>
void dec_to_bin(int n)
{
int arr[31],len = 0,i;
if(n == 0)
{
arr[0] = 0;
len = 1;
}
while(n != 0)
{
arr[len++] = n % 2;
n /= 2;
}
for(i=len-1; i>=0; i--)
printf("%d",arr[i]);
}
int main()
{
int n = 0;
dec_to_bin(n);
return 0;
}
#include<stdio.h>
void dec_to_bin(int n)
{
int arr[31],len = 0,i;
if(n == 0)
{
arr[0] = 0;
len = 1;
}
while(n != 0)
{
arr[len++] = n % 2;
n /= 2;
}
for(i=len-1; i>=0; i--)
printf("%d",arr[i]);
}
int main()
{
int n = 0;
dec_to_bin(n);
return 0;
}
82. Which of the following is a disadvantage of quickselect?
83. What is the output of the following code?
#include<stdio.h>
int recursive_binary_search(int *arr, int num, int lo, int hi)
{
if(lo > hi)
return -1;
int mid = (lo + hi)/2;
if(arr[mid] == num)
return mid;
else if(arr[mid] < num)
lo = mid + 1;
else
hi = mid - 1;
return recursive_binary_search(arr, num, lo, hi);
}
int main()
{
int arr[8] = {1,2,3,4,5,6,7,8},num = 7,len = 8;
int indx = recursive_binary_search(arr,num,0,len-1);
printf("Index of %d is %d",num,indx);
return 0;
}
#include<stdio.h>
int recursive_binary_search(int *arr, int num, int lo, int hi)
{
if(lo > hi)
return -1;
int mid = (lo + hi)/2;
if(arr[mid] == num)
return mid;
else if(arr[mid] < num)
lo = mid + 1;
else
hi = mid - 1;
return recursive_binary_search(arr, num, lo, hi);
}
int main()
{
int arr[8] = {1,2,3,4,5,6,7,8},num = 7,len = 8;
int indx = recursive_binary_search(arr,num,0,len-1);
printf("Index of %d is %d",num,indx);
return 0;
}
84. How many approaches can be applied to solve quick hull problem?
85. A man wants to go different places in the world. He has listed them down all. But there are some places where he wants to visit before some other places. What application of graph can he use to determine that?
86. Dynamic programming approach can be used to implement Catalan numbers.
87. . . . . . . . . enumerates a list of promising nodes that could be computed to give the possible solutions of a given problem.
88. Which of the following forms a sequence of natural numbers that occur in different counting problems?
89. In the least recently used algorithm, if the current page doesn't exist in the set then it is replaced with the recently used page.
90. Consider the following iterative implementation to find the nth fibonacci number?
int main()
{
int n = 10,i;
if(n == 1)
printf("0");
else if(n == 2)
printf("1");
else
{
int a = 0, b = 1, c;
for(i = 3; i <= n; i++)
{
c = a + b;
________;
________;
}
printf("%d",c);
}
return 0;
}
Which of the following lines should be added to complete the above code?
int main()
{
int n = 10,i;
if(n == 1)
printf("0");
else if(n == 2)
printf("1");
else
{
int a = 0, b = 1, c;
for(i = 3; i <= n; i++)
{
c = a + b;
________;
________;
}
printf("%d",c);
}
return 0;
}
Which of the following lines should be added to complete the above code?Read More Section(Miscellaneous on Data Structures)
Each Section contains maximum 100 MCQs question on Miscellaneous on Data Structures. To get more questions visit other sections.
- Miscellaneous on Data Structures - Section 1
- Miscellaneous on Data Structures - Section 2
- Miscellaneous on Data Structures - Section 3
- Miscellaneous on Data Structures - Section 5
- Miscellaneous on Data Structures - Section 6
- Miscellaneous on Data Structures - Section 7
- Miscellaneous on Data Structures - Section 8
- Miscellaneous on Data Structures - Section 9
- Miscellaneous on Data Structures - Section 10
- Miscellaneous on Data Structures - Section 11
- Miscellaneous on Data Structures - Section 12