GATE 2024 (Session 2)
65 questions
MCQ 32 · MSQ 18 · NAT 151-mark 30 · 2-mark 35
Questions 36–40 of 65
What is the output of the following C program?
#include <stdio.h>
int main() {
double a[2]={20.0, 25.0}, *p, *q;
p = a;
q = p + 1;
printf("%d,%d", (int)(q - p), (int)(*q - *p));
return 0;}Answer: (B)
Work out the two values that are printed:
- Here . Subtracting two pointers gives the number of elements between them, not bytes: .
- For the second value, . Casting this to int gives 5.
Output: 1,5
Answer: 1,5
- Here . Subtracting two pointers gives the number of elements between them, not bytes: .
- For the second value, . Casting this to int gives 5.
Output: 1,5
Answer: 1,5
Consider a single processor system with four processes A, B, C, and D, represented as given below, where for each process the first value is its arrival time, and the second value is its CPU burst time.
A (0, 10), B (2, 6), C (4, 3), and D (6, 7).
Which one of the following options gives the average waiting times when preemptive Shortest Remaining Time First (SRTF) and Non-Preemptive Shortest Job First (NP-SJF) CPU scheduling algorithms are applied to the processes?
A (0, 10), B (2, 6), C (4, 3), and D (6, 7).
Which one of the following options gives the average waiting times when preemptive Shortest Remaining Time First (SRTF) and Non-Preemptive Shortest Job First (NP-SJF) CPU scheduling algorithms are applied to the processes?
Answer: (B)
SRTF Gantt chart: A(0-2), B(2-4), C(4-7), B(7-11), D(11-18), A(18-26)
Waiting time is completion time arrival time burst time.
A = 26010 = 16, B = 1126 = 3, C = 743 = 0, D = 1867 = 5
Average waiting time
NP-SJF Gantt chart: A(0-10), C(10-13), B(13-19), D(19-26)
Waiting times: A = 0, C = 104 = 6, B = 132 = 11, D = 196 = 13
Average waiting time
Answer: SRTF = 6, NP-SJF = 7.5
Waiting time is completion time arrival time burst time.
A = 26010 = 16, B = 1126 = 3, C = 743 = 0, D = 1867 = 5
Average waiting time
NP-SJF Gantt chart: A(0-10), C(10-13), B(13-19), D(19-26)
Waiting times: A = 0, C = 104 = 6, B = 132 = 11, D = 196 = 13
Average waiting time
Answer: SRTF = 6, NP-SJF = 7.5
Which one of the following CIDR prefixes exactly represents the range of IP addresses 10.12.2.0 to 10.12.3.255?
Answer: (A)
The range 10.12.2.0 to 10.12.3.255 contains addresses. So the host bits are 9 and the prefix length is .
Look at the third octet: 2 = 00000010 and 3 = 00000011 The first 23 bits are the same in both, so the block is aligned.
(A /24 covers only 10.12.2.x. A /22 covers 10.12.0.0-10.12.3.255.)
Answer: 10.12.2.0/23
Look at the third octet: 2 = 00000010 and 3 = 00000011 The first 23 bits are the same in both, so the block is aligned.
(A /24 covers only 10.12.2.x. A /22 covers 10.12.0.0-10.12.3.255.)
Answer: 10.12.2.0/23
You are given a set of distinct integers. A binary search tree is created by inserting all elements of one by one, starting with an empty tree. The tree follows the convention that, at each node, all values stored in the left subtree of the node are smaller than the value stored at the node. You are not aware of the sequence in which these values were inserted into , and you do not have access to .
Which one of the following statements is TRUE?
Which one of the following statements is TRUE?
Answer: (A)
For any BST, the inorder traversal lists the keys in sorted order. This is true for every insertion order. So we can get it from V by simply sorting V.
The root, preorder and postorder change with the insertion order. Take V = {1, 2} as an example. If 1 is inserted first and then 2, the root is 1. If 2 is inserted first and then 1, the root is 2.
Answer: Inorder traversal of T can be determined from V
The root, preorder and postorder change with the insertion order. Take V = {1, 2} as an example. If 1 is inserted first and then 2, the root is 1. If 2 is inserted first and then 1, the root is 2.
Answer: Inorder traversal of T can be determined from V
Consider the following context-free grammar where the start symbol is and the set of terminals is .
The following is a partially-filled LL(1) parsing table.
Which one of the following options represents the CORRECT combination for the numbered cells in the parsing table?
Note: In the options, "blank" denotes that the corresponding cell is empty.
The following is a partially-filled LL(1) parsing table.
Which one of the following options represents the CORRECT combination for the numbered cells in the parsing table?
Note: In the options, "blank" denotes that the corresponding cell is empty.
Answer: (A)
Fill the LL(1) table with the help of FIRST and FOLLOW sets:
- (A is c or ) So cell (1) [S, c] = .
- So cell (2) [S, d] = .
- goes in the columns of FOLLOW(A). A comes before a and before b, so So cell (3) [A, b] = .
- In the same way, So cell (4) [B, a] = .
Answer: (1) (2) (3) (4)
- (A is c or ) So cell (1) [S, c] = .
- So cell (2) [S, d] = .
- goes in the columns of FOLLOW(A). A comes before a and before b, so So cell (3) [A, b] = .
- In the same way, So cell (4) [B, a] = .
Answer: (1) (2) (3) (4)