What is the time complexity of the following code?
#include <bits/stdc++.h>
using namespace std;
void convert(int arr[], int n)
{
int temp[n];
memcpy(temp, arr, n*sizeof(int));
sort(temp, temp + n);
unordered_map<int, int> map;
int sort_index = 0;
for (int i = 0; i < n; i++)
map[temp[i]] = sort_index++;
for (int i = 0; i < n; i++)
arr[i] = map[arr[i]];
}
void printArr(int arr[], int n)
{
for (int i=0; i<n; i++)
cout << arr[i] << " ";
}
int main()
{
int arr[] = {10, 20, 15, 12, 11, 50};
int n = sizeof(arr)/sizeof(arr[0]);
convert(arr , n);
printArr(arr, n);
return 0;
}A. O(n)
B. O(1)
C. O(n log n)
D. O(n2 )
Select an option to see the answer and solution.
What is meant by the power set of a set?
A. subset of all sets
B. set of all subsets
C. set of particular subsets
D. empty set
Select an option to see the answer and solution.
Which of the following is considered as the top of the stack in the linked list implementation of the stack?
A. Last node
B. First node
C. Random node
D. Middle node
Select an option to see the answer and solution.
Which of the following is an application of the minimum cut problem?
A. Pre-order traversal
B. To find strongly connected components
C. To study the reliability of a network
D. Detecting cycle in a graph
Select an option to see the answer and solution.
What is the following expression, lcm (a, lcm (b, c) equal to?
A. lcm (a, b, c)
B. a*b*c
C. a + b + c
D. lcm (lcm (a, b), c)
Select an option to see the answer and solution.
A key matrix used for encryption in hill cipher must be?
A. invertible matrix
B. non invertible matrix
C. square matrix
D. rectangular matrix
Select an option to see the answer and solution.
What is the output of the following code?
#include<stdio.h>
int search_num(int *arr, int num, int len)
{
int i;
for(i = 0; i < len; i++)
if(arr[i] == num)
return i;
return -1;
}
int main()
{
int arr[5] ={1,3,3,3,5},num=3,len = 5;
int indx = search_num(arr,num,len);
printf("Index of %d is %d",num,indx);
return 0;
}A. Index of 3 is 0
B. Index of 3 is 1
C. Index of 3 is 2
D. Index of 3 is 3
Select an option to see the answer and solution.
Gronsfeld cipher is similar to?
A. additive cipher
B. multiplicative cipher
C. caesar cipher
D. affine cipher
Select an option to see the answer and solution.
Atbash cipher cannot be cracked until the exact type of encryption of ciphered text is known.
Select an option to see the answer and solution.
Which of the following methods can be used to find the largest and smallest number in a linked list?
A. Recursion
B. Iteration
C. Both Recursion and iteration
D. Impossible to find the largest and smallest numbers
Select an option to see the answer and solution.
Who published the extended version of eight queens puzzle?
A. Franz Nauck
B. Max Bezzel
C. Carl
D. Friedrich
Select an option to see the answer and solution.
Solve the following recurrence using Master's theorem.
T(n) = 2T (n/2) + n/ log 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.
Consider the following recursive implementation of linear search on a linked list:
struct Node
{
int val;
struct Node* next;
}*head;
int linear_search(struct Node *temp,int value)
{
if(temp == 0)
return 0;
if(temp->val == value)
return 1;
return _________;
}
Which of the following lines should be inserted to complete the above code?
A. 1
B. 0
C. linear_search(temp, value)
D. linear_search(temp->next, value)
Select an option to see the answer and solution.
In n-queen problem, how many values of n does not provide an optimal solution?
Select an option to see the answer and solution.
How many cases are there under Master's theorem?
Select an option to see the answer and solution.
Consider the following recursive implementation to find the largest element in an array.
int max_of_two(int a, int b)
{
if(a > b)
return a;
return b;
}
int recursive_max_element(int *arr, int len, int idx)
{
if(idx == len - 1)
return arr[idx];
return _______;
}
Which of the following lines should be inserted to complete the above code?
A. max_of_two(arr[idx], recursive_max_element(arr, len, idx))
B. recursive_max_element(arr, len, idx)
C. max_of_two(arr[idx], recursive_max_element(arr, len, idx + 1))
D. recursive_max_element(arr, len, idx + 1)
Select an option to see the answer and solution.
What is the formula to calculate the element present in second row, first column of the product matrix?
A. M1 + M7
B. M1 + M3
C. M2 + M4 - M5 + M7
D. M2 + M4
Select an option to see the answer and solution.
Which of the following is hardest to break using frequency analysis?
A. Vigenere cipher
B. Autokey cipher
C. Playfair cipher
D. Rotor cipher
Select an option to see the answer and solution.
Why do we require hamming codes?
A. Error correction
B. Encryption only
C. Decryption
D. Bit stuffing
Select an option to see the answer and solution.
Which of the following methods used to find the sum of first n natural numbers has the least time complexity?
A. Recursion
B. Iteration
C. Binomial coefficient
D. All have equal time complexity
Select an option to see the answer and solution.