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;
}A. O(1)
B. O(n)
C. O(n2 )
D. O(logn)
Select an option to see the answer and solution.
Which of the following is a disadvantage of quickselect?
A. Poor space complexity
B. Poor best case time complexity
C. Poor average case time complexity
D. Poor worst case time complexity
Select an option to see the answer and solution.
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;
}A. Index of 7 is 4
B. Index of 7 is 5
C. Index of 7 is 6
D. Index of 7 is 7
Select an option to see the answer and solution.
How many approaches can be applied to solve quick hull problem?
Select an option to see the answer and solution.
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?
A. Depth First Search
B. Breadth First Search
C. Topological Sorting
D. Dijkstra's Shortest path algorithm
Select an option to see the answer and solution.
Dynamic programming approach can be used to implement Catalan numbers.
Select an option to see the answer and solution.
. . . . . . . . enumerates a list of promising nodes that could be computed to give the possible solutions of a given problem.
A. Exhaustive search
B. Brute force
C. Backtracking
D. Divide and conquer
Select an option to see the answer and solution.
Which of the following forms a sequence of natural numbers that occur in different counting problems?
A. Chromatic number
B. Pascal triangle
C. Catalan numbers
D. Factorial of a number
Select an option to see the answer and solution.
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.
Select an option to see the answer and solution.
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?
Options are not available for this question.
Select an option to see the answer and solution.
Which of the problems cannot be solved by backtracking method?
A. n-queen problem
B. subset sum problem
C. hamiltonian circuit problem
D. travelling salesman problem
Select an option to see the answer and solution.
What is the magnitude of resultant of cross product of two parallel vectors a and b?
A. |a|.|b|
B. |a|.|b| cos(180)
C. |a|.|b| sin(180)
D. 1
Select an option to see the answer and solution.
What will be the ciphered text corresponding to "EXAMPLE" if beaufort cipher is used for encryption with key as "PASS"?
A. LSAODGP
B. OPAGSDL
C. LDSGAPO
D. PGDOASL
Select an option to see the answer and solution.
. . . . . . . . states that, on a page fault, the frame that has been in memory the longest is replaced.
A. Belady's anomaly
B. Second chance algorithm
C. Partial second chance algorithm
D. LRU replacement algorithm
Select an option to see the answer and solution.
Which of the following recursive formula can be used to find the factorial of a number?
A. fact(n) = n * fact(n)
B. fact(n) = n * fact(n+1)
C. fact(n) = n * fact(n-1)
D. fact(n) = n * fact(1)
Select an option to see the answer and solution.
How many stages of procedure does a non-deterministic algorithm consist of?
Select an option to see the answer and solution.
Consider the given page reference string 3, 1, 0, 2, 1, 5, 6, 2, 8, 6, 9, 1. How many page faults will occur if the program has 4-page frames available to it and it uses the not recently used algorithm?
Select an option to see the answer and solution.
Poly alphabetic cipher harder to decipher than mono alphabetic cipher.
Select an option to see the answer and solution.
Solve the following recurrence using Master's theorem.
T(n) = 0.7 T (n/2) + 1/n
A. T(n) = O(n)
B. T(n) = O(log n)
C. T(n) = O(n2 log n)
D. cannot be solved using master's theorem
Select an option to see the answer and solution.
A two-out-of-five code consists of . . . . . . . .
A. Two 0s and three 1s
B. Three 0s and two 1s
C. Four 0s and one 1s
D. One 0s and four 1s
Select an option to see the answer and solution.