NEW
Font size
S
M
L
XL
WorksheetsDSBS-FN-30.01.2024
Total questions: 15
Worksheet time: 30mins
Name
Class
Date
1.
The first step in the naïve greedy algorithm is?
a)
adding flows with higher values
b)
reversing flow if required
c)
analysing the zero flow
d)
calculating the maximum flow using trial and error
2.
Suppose you have coins of denominations 1,3 and 4. You use a greedy algorithm, in which you choose the largest denomination coin which is not greater than the remaining sum. For which of the following sums, will the algorithm produce an optimal answer?
a)
100
b)
10
c)
6
d)
14
3.
Dijkstra’s Algorithm is the prime example for ___________
a)
Dynamic programming
b)
Back tracking
c)
Branch and bound
d)
Greedy algorithm
4.
With what data structure can a priority queue be implemented?
a)
Array
b)
List
c)
Heap
d)
Tree
5.
What is the time complexity to insert a node based on key in a priority queue?
a)
O(nlogn)
b)
O(logn)
c)
O(n)
d)
O(n2)
6.
Which of the following is not an advantage of a priority queue?
a)
Easy to implement
b)
Processes with different priority can be efficiently handled
c)
Applications with differing requirements
d)
Easy to delete elements in any case
7.
Descending priority queue can be implemented using ______
a)
max heap
b)
min heap
c)
min-max heap
d)
trie
8.
The ascending heap property is ___________
a)
A[Parent(i)] =A[i]
b)
A[Parent(i)] <= A[i]
c)
A[Parent(i)] >= A[i]
d)
A[Parent(i)] > 2 * A[i]
9.
Time complexity of the code?
int fun(int n, int m, int o)
{
if (n <= 0)
printf("%d, %d\n",m, o);
else
{
fun(n-1, m+1, o);
fun(n-1, m, o+1);
}
a)
Quadratic
b)
O (log n)
c)
O (n log m)
d)
Exponential
10.
What is the time complexity of the following code?
int fun(int x)
{
if (x <= 0)
return 1;
return 1 + fun(x-1);
}
a)
O(n)
b)
O (log n)
c)
O (n log n)
d)
O (log log n)
11.
What is the time complexity of the code?
int fun(int x)
{
if (x <= 0)
return 1;
return 1 + fun(x/5);
}
a)
O(n)
b)
O (log n)
c)
O (n log n)
d)
O (log log n)
12.
int sumDigits(int n) {
if (n == 0)
return 0;
else
return n % 10 + sumDigits(n / 10);
}
int main() {
printf("Sum of Digits: %d\n", sumDigits(123));
return 0;
}
a)
6
b)
5
c)
9
d)
12
13.
void show(int,int,int);
int main()
{
int a = 1;
show(++a, a++, a);
return 0;
}
void show(int i, int j, int k)
{
printf("%d %d %d,\n", i, j, k);
}
a)
1 1 3
b)
3 1 3
c)
3 1 1
d)
3 3 3
14.
#include <stdio.h>
int factorial(const int n) {
if (n <= 1)
return 1;
else
return n * factorial(n - 1);
}
int main() {
printf("Factorial: %d\n", factorial(5));
return 0;
}
a)
200
b)
100
c)
120
d)
error
15.
int mysteryFunction(int a, int b) {
if (b == 0)
return 1;
else
return a * mysteryFunction(a, b - 1);
}
int main() {
printf("Mystery Function: %d\n", mysteryFunction(2, 3));
return 0;
}
a)
8
b)
6
c)
16
d)
2
Reset
