GATE 2020
64 questions
MCQ 41 · NAT 231-mark 29 · 2-mark 35
Questions 56–60 of 64
Consider the array representation of a binary min-heap containing 1023 elements. The minimum number of comparisons required to find the maximum in the heap is ___________.
Answer: 511
The largest value in a min-heap must sit at a leaf node. The heap has 1023 nodes, so the number of leaves is .
To get the maximum of these 512 elements, we need 512 1 = 511 comparisons.
Answer: 511
To get the maximum of these 512 elements, we need 512 1 = 511 comparisons.
Answer: 511
Consider the following C functions.
The value returned by pp(3,4) is _____
int tob(int b, int* arr){
int i;
for(i=0; b>0; i++){
if(b%2) arr[i]=1;
else arr[i]=0;
b = b/2;
}
return(i);
} int pp(int a,int b) {
int arr[20];
int i, tot = 1, ex, len;
ex = a;
len = tob(b,arr);
for(i=0; i<len; i++){
if(arr[i]==1)
tot = tot * ex;
ex = ex * ex;
}
return(tot);
}The value returned by pp(3,4) is _____
Answer: 81
tob(b, arr) saves the binary bits of b, lowest bit first, and returns how many bits there are. Here b = 4 = 100 arr = [0, 0, 1], len = 3.
pp finds by repeated squaring: ex becomes 3 9 81. tot is multiplied only for a bit equal to 1, the third bit tot = 81.
Answer: 81
pp finds by repeated squaring: ex becomes 3 9 81. tot is multiplied only for a bit equal to 1, the third bit tot = 81.
Answer: 81
Consider a graph , where , , and weight of the edge . The weight of minimum spanning tree of G is _________
Answer: 99
The weight of an edge is |i j| . Weight 1 occurs only between neighbouring vertices. The 99 edges make a spanning tree (a path), each of weight 1.
Every spanning tree has 99 edges, each of weight at least 1. So this tree is minimum: 99.
Answer: 99
Every spanning tree has 99 edges, each of weight at least 1. So this tree is minimum: 99.
Answer: 99
Consider the following set of processes, assumed to have arrived at time 0. Consider the CPU scheduling algorithms Shortest Job First (SJF) and Round Robin (RR). For RR, assume that the processes are scheduled in the order .
If the time quantum for RR is 4 ms, then the absolute value of the difference between the average turnaround times (in ms) of SJF and RR (round off to 2 decimal places) is _______
If the time quantum for RR is 4 ms, then the absolute value of the difference between the average turnaround times (in ms) of SJF and RR (round off to 2 decimal places) is _______
Answer: 5.25
SJF (order of running: P3 2, P4 4, P2 7, P1 8): the completion times are 2, 6, 13, 21 so the average TAT = 42 / 4 = 10.5
RR, q = 4: P1 runs 0-4, P2 runs 4-8, P3 runs 8-10 (done), P4 runs 10-14 (done), P1 runs 14-18 (done), P2 runs 18-21 (done)
Turnaround times: P1 18, P2 21, P3 10, P4 14 so the average = 63 / 4 = 15.75
Difference: |15.75 10.5| = 5.25
Answer: 5.25
RR, q = 4: P1 runs 0-4, P2 runs 4-8, P3 runs 8-10 (done), P4 runs 10-14 (done), P1 runs 14-18 (done), P2 runs 18-21 (done)
Turnaround times: P1 18, P2 21, P3 10, P4 14 so the average = 63 / 4 = 15.75
Difference: |15.75 10.5| = 5.25
Answer: 5.25
Consider the following language.
L={ number of a's in x divisible by 2 but not divisible by 3}
The minimum number of states in DFA that accepts L is _______
L={ number of a's in x divisible by 2 but not divisible by 3}
The minimum number of states in DFA that accepts L is _______
Answer: 6
The DFA must keep track of the count of a's mod 2 and mod 3, which means mod 6. This gives 6 states (b's do not change the state).
Accept the counts that are even but not multiples of 3. These are remainders 2 and 4. All 6 states are distinguishable (for example, they differ in how many a's lead to acceptance).
Answer: 6
Accept the counts that are even but not multiples of 3. These are remainders 2 and 4. All 6 states are distinguishable (for example, they differ in how many a's lead to acceptance).
Answer: 6