11. . . . . . . . . separates a particular pair of vertices in a graph.
12. What type of graph has chromatic number less than or equal to 2?
13. Consider the following code:
#include<stdio.h>
int recursive_sum(int n)
{
if(n == 0)
return 0;
return n + recursive_sum(n - 1);
}
int main()
{
int n = 5;
int ans = recursive_sum(n);
printf("%d",ans);
return 0;
}
Which of the following is the base case for the above recursive code?
#include<stdio.h>
int recursive_sum(int n)
{
if(n == 0)
return 0;
return n + recursive_sum(n - 1);
}
int main()
{
int n = 5;
int ans = recursive_sum(n);
printf("%d",ans);
return 0;
}
Which of the following is the base case for the above recursive code?14. Which header file contains the function rand() in C language?
15. What will be the output for the following code?
#include <stdio.h>
#include <stdlib.h>
void combination(int arr[], int aux[], int start, int end, int index, int r);
int compare (const void * a, const void * b)
{ return ( *(int*)a - *(int*)b ); }
void print(int arr[], int n, int r)
{
int aux[r];
qsort (arr, n, sizeof(int), compare);
combination(arr, aux, 0, n-1, 0, r);
}
void combination(int arr[], int aux[], int start, int end, int index, int r)
{
if (index == r)
{
for (int i=0; i<r; i++)
printf("%d " ,aux[i]);
printf(", ");
return;
}
for (int i=start; i<=end && end-i+1 >= r-index; i++)
{
aux[index] = arr[i];
combination(arr, aux, i+1, end, index+1, r);
while (arr[i] == arr[i+1])
i++;
}
}
int main()
{
int arr[] = {1, 2, 2};
int r = 2;
int n = sizeof(arr)/sizeof(arr[0]);
print(arr, n, r);
}
#include <stdio.h>
#include <stdlib.h>
void combination(int arr[], int aux[], int start, int end, int index, int r);
int compare (const void * a, const void * b)
{ return ( *(int*)a - *(int*)b ); }
void print(int arr[], int n, int r)
{
int aux[r];
qsort (arr, n, sizeof(int), compare);
combination(arr, aux, 0, n-1, 0, r);
}
void combination(int arr[], int aux[], int start, int end, int index, int r)
{
if (index == r)
{
for (int i=0; i<r; i++)
printf("%d " ,aux[i]);
printf(", ");
return;
}
for (int i=start; i<=end && end-i+1 >= r-index; i++)
{
aux[index] = arr[i];
combination(arr, aux, i+1, end, index+1, r);
while (arr[i] == arr[i+1])
i++;
}
}
int main()
{
int arr[] = {1, 2, 2};
int r = 2;
int n = sizeof(arr)/sizeof(arr[0]);
print(arr, n, r);
}
16. Which among the following algorithms can be used to decide which page should be replaced when the new page comes in?
17. What will be the recurrence relation of the following code?
int xpowy(int x, int n)
if (n==0) return 1;
if (n==1) return x;
if ((n % 2) == 0)
return xpowy(x*x, n/2);
else
return xpowy(x*x, n/2) * x;
int xpowy(int x, int n)
if (n==0) return 1;
if (n==1) return x;
if ((n % 2) == 0)
return xpowy(x*x, n/2);
else
return xpowy(x*x, n/2) * x;
18. What will be the time complexity of the code to print combinations?
19. What will be the output 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[] = {3,5,2,4};
int n = sizeof(arr)/sizeof(arr[0]);
convert(arr , n);
printArr(arr, n);
return 0;
}
#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[] = {3,5,2,4};
int n = sizeof(arr)/sizeof(arr[0]);
convert(arr , n);
printArr(arr, n);
return 0;
}
20. What is the running time of the Huffman encoding algorithm?
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