11. Which cipher is represented by the following function?
public class Cipher
{
public static String encrypt(String text, final String key)
{
String res = "";
text = text.toUpperCase();
for (int i = 0, j = 0; i < text.length(); i++)
{
char c = text.charAt(i);
if (c < 'A' || c > 'Z')
continue;
res += (char) ((c + key.charAt(j) - 2 * 'A') % 26 + 'A');
j = ++j % key.length();
}
return res;
}
public class Cipher
{
public static String encrypt(String text, final String key)
{
String res = "";
text = text.toUpperCase();
for (int i = 0, j = 0; i < text.length(); i++)
{
char c = text.charAt(i);
if (c < 'A' || c > 'Z')
continue;
res += (char) ((c + key.charAt(j) - 2 * 'A') % 26 + 'A');
j = ++j % key.length();
}
return res;
}
12. How many times is the function recursive_binary_search() called when the following code is executed?
#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[5] = {1,2,3,4,5},num = 1,len = 5;
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[5] = {1,2,3,4,5},num = 1,len = 5;
int indx = recursive_binary_search(arr,num,0,len-1);
printf("Index of %d is %d",num,indx);
return 0;
}
13. What is the period in bifid cipher?
14. An optimal solution satisfying men's preferences is said to be?
15. Which is the correct term of the given relation, lcm (a, b) * gcd (a, b) =?
16. The cost required to execute a FIFO algorithm is expensive.
17. The problem of placing n queens in a chessboard such that no two queens attack each other is called as?
18. What is the time complexity of the following recursive implementation used to find the largest and the smallest element in an array?
#include<stdio.h>
int max_of_two(int a, int b)
{
if(a > b)
return a;
return b;
}
int min_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 max_of_two(arr[idx], recursive_max_element(arr, len, idx + 1));
}
int recursive_min_element(int *arr, int len, int idx)
{
if(idx == len - 1)
return arr[idx];
return min_of_two(arr[idx], recursive_min_element(arr, len, idx + 1));
}
int main()
{
int n = 10, idx = 0, arr[] = {5,2,6,7,8,9,3,-1,1,10};
int max_element = recursive_max_element(arr,n,idx);
int min_element = recursive_min_element(arr,n,idx);
printf("%d %d",max_element,min_element);
return 0;
}
#include<stdio.h>
int max_of_two(int a, int b)
{
if(a > b)
return a;
return b;
}
int min_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 max_of_two(arr[idx], recursive_max_element(arr, len, idx + 1));
}
int recursive_min_element(int *arr, int len, int idx)
{
if(idx == len - 1)
return arr[idx];
return min_of_two(arr[idx], recursive_min_element(arr, len, idx + 1));
}
int main()
{
int n = 10, idx = 0, arr[] = {5,2,6,7,8,9,3,-1,1,10};
int max_element = recursive_max_element(arr,n,idx);
int min_element = recursive_min_element(arr,n,idx);
printf("%d %d",max_element,min_element);
return 0;
}
19. What is the formula used for decoding the ciphered text using affine cipher(a,b are constants and x is the numerical equivalent of a letter to be encrypted)?
20. What is the time complexity of the following recursive implementation to find the nth fibonacci number?
int fibo(int n)
{
if(n == 1)
return 0;
else if(n == 2)
return 1;
return fibo(n - 1) + fibo(n - 2);
}
int main()
{
int n = 5;
int ans = fibo(n);
printf("%d",ans);
return 0;
}
int fibo(int n)
{
if(n == 1)
return 0;
else if(n == 2)
return 1;
return fibo(n - 1) + fibo(n - 2);
}
int main()
{
int n = 5;
int ans = fibo(n);
printf("%d",ans);
return 0;
}
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 4
- 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