GATE 2024 (Session 1)
65 questions
MCQ 29 · MSQ 20 · NAT 161-mark 30 · 2-mark 35
Questions 16–20 of 65
A user starts browsing a webpage hosted at a remote server. The browser opens a single TCP connection to fetch the entire webpage from the server. The webpage consists of a top-level index page with multiple embedded image objects. Assume that all caches (e.g., DNS cache, browser cache) are all initially empty. The following packets leave the user's computer in some order.
(i) HTTP GET request for the index page
(ii) DNS request to resolve the web server's name to its IP address
(iii) HTTP GET request for an image object
(iv) TCP SYN to open a connection to the web server
Which one of the following is the CORRECT chronological order (earliest in time to latest) of the packets leaving the computer ?
(i) HTTP GET request for the index page
(ii) DNS request to resolve the web server's name to its IP address
(iii) HTTP GET request for an image object
(iv) TCP SYN to open a connection to the web server
Which one of the following is the CORRECT chronological order (earliest in time to latest) of the packets leaving the computer ?
Answer: (C)
The packets leave the computer in this order:
1. (ii) DNS request The server's IP address is needed before anything else, because all caches are empty.
2. (iv) TCP SYN This opens the TCP connection to the server.
3. (i) GET index page This is the first request sent on the connection.
4. (iii) GET image The browser learns about the image only after it gets the index page and parses it.
Answer: (ii), (iv), (i), (iii)
1. (ii) DNS request The server's IP address is needed before anything else, because all caches are empty.
2. (iv) TCP SYN This opens the TCP connection to the server.
3. (i) GET index page This is the first request sent on the connection.
4. (iii) GET image The browser learns about the image only after it gets the index page and parses it.
Answer: (ii), (iv), (i), (iii)
Given an integer array of size , we want to check if the array is sorted (in either ascending or descending order). An algorithm solves this problem by making a single pass through the array and comparing each element of the array only with its adjacent elements. The worst-case time complexity of this algorithm is
Answer: (A)
The algorithm looks at each pair of adjacent elements one time. In the worst case it makes comparisons. This happens when the array is really sorted, because it must check every pair before it says YES.
It cannot do fewer checks, since any element it does not look at could break the order. So the worst case is . That means it is both and .
Answer: both and
It cannot do fewer checks, since any element it does not look at could break the order. So the worst case is . That means it is both and .
Answer: both and
Consider the following C program:
#include <stdio.h>
int main(){
int a = 6;
int b = 0;
while(a < 10) {
a = a / 12 + 1;
a += b;}
printf("%d", a);
return 0;}
Which one of the following statements is CORRECT?Answer: (C)
The program uses integer division.
First pass: , and after that .
Second pass: once more, and the same repeats on every pass.
The value of stays at 1. So the condition is true every time, and printf is never reached.
Answer: The program gets stuck in an infinite loop
First pass: , and after that .
Second pass: once more, and the same repeats on every pass.
The value of stays at 1. So the condition is true every time, and printf is never reached.
Answer: The program gets stuck in an infinite loop
Consider the following C program:
#include <stdio.h>
void fX();
int main(){
fX();
return 0;}
void fX(){
char a;
if((a=getchar()) != '\n')
fX();
if(a != '\n')
putchar(a);} Assume that the input to the program from the command line is 1234 followed by a newline character. Which one of the following statements is CORRECT?Answer: (C)
Every call of fX() reads one character. If the character is not a newline, it calls fX() again before it prints anything. Each call keeps its own local variable .
The calls read: '1' '2' '3' '4' '\n'. The last call reads the newline. It makes no new call and prints nothing.
As the calls return, they print their characters in reverse order: 4, 3, 2, 1. After that, main returns normally.
Answer: The program will terminate with 4321 as output
The calls read: '1' '2' '3' '4' '\n'. The last call reads the newline. It makes no new call and prints nothing.
As the calls return, they print their characters in reverse order: 4, 3, 2, 1. After that, main returns normally.
Answer: The program will terminate with 4321 as output
Let S be the specification: "Instructors teach courses. Students register for courses. Courses are allocated classrooms. Instructors guide students." Which one of the following ER diagrams CORRECTLY represents S?
Answer: (D)
The specification gives us 4 entity sets Instructor, Course, Student and Classroom . It also gives us 4 relationships:
Instructor-Teaches-Course, Student-Registers-Course, Course-Allocated-Classroom, Instructor-Guides-Student.
- (i): Registration is drawn as an entity and Student is drawn as a relationship so it is wrong.
- (ii): There is no Student entity, and an extra Projects entity is used so it is wrong.
- (iii): Classroom is joined straight to Course, and the Allocation relationship does not connect Classroom so it is wrong.
- (iv): All four entities and all four relationships are connected correctly.
Answer: (iv)
Instructor-Teaches-Course, Student-Registers-Course, Course-Allocated-Classroom, Instructor-Guides-Student.
- (i): Registration is drawn as an entity and Student is drawn as a relationship so it is wrong.
- (ii): There is no Student entity, and an extra Projects entity is used so it is wrong.
- (iii): Classroom is joined straight to Course, and the Allocation relationship does not connect Classroom so it is wrong.
- (iv): All four entities and all four relationships are connected correctly.
Answer: (iv)