GATE 2024 (Session 2)
65 questions
MCQ 32 · MSQ 18 · NAT 151-mark 30 · 2-mark 35
Questions 46–50 of 65
Consider a multi-threaded program with two threads T1 and T2. The threads share two semaphores: s1 (initialized to 1) and s2 (initialized to 0). The threads also share a global variable x (initialized to 0). The threads execute the code shown below.
// code of T1
wait(s1);
x = x+1;
print(x);
wait(s2);
signal(s1);
// code of T2
wait(s1);
x = x+1;
print(x);
signal(s2);
signal(s1); Which of the following outcomes is/are possible when threads T1 and T2 execute concurrently?One or more options are correct.
Answer: (B), (C)
s1 acts as a mutex, so the thread that gets s1 first runs its part first.
If T1 runs first: T1 does wait(s1), sets x = 1 and prints 1. Then wait(s2) blocks because s2 = 0, and T1 still holds s1. T2 now blocks on wait(s1) deadlock. Only "1" is printed. So (C) is possible and (A) is not.
If T2 runs first: T2 does wait(s1), sets x = 1, prints 1, then does signal(s2) and signal(s1). Next T1 sets x = 2, prints 2, wait(s2) goes through (s2 = 1), and T1 does signal(s1). So (B) is possible. T2 never blocks, so (D) is not possible.
Answer: (B), (C)
If T1 runs first: T1 does wait(s1), sets x = 1 and prints 1. Then wait(s2) blocks because s2 = 0, and T1 still holds s1. T2 now blocks on wait(s1) deadlock. Only "1" is printed. So (C) is possible and (A) is not.
If T2 runs first: T2 does wait(s1), sets x = 1, prints 1, then does signal(s2) and signal(s1). Next T1 sets x = 2, prints 2, wait(s2) goes through (s2 = 1), and T1 does signal(s1). So (B) is possible. T2 never blocks, so (D) is not possible.
Answer: (B), (C)
Let be an matrix over the set of all real numbers . Let be a matrix obtained from by swapping two rows. Which of the following statements is/are TRUE?
One or more options are correct.
Answer: (A), (B)
(A) Swapping two rows changes the sign of the determinant: . TRUE.
(B) If A is invertible, , so and B is invertible. TRUE.
(C) Take , which is symmetric. Swapping the rows gives , which is not symmetric. FALSE.
(D) Take , with trace 0. Swapping the rows gives , with trace 1. FALSE.
Answer: (A), (B)
(B) If A is invertible, , so and B is invertible. TRUE.
(C) Take , which is symmetric. Swapping the rows gives , which is not symmetric. FALSE.
(D) Take , with trace 0. Swapping the rows gives , with trace 1. FALSE.
Answer: (A), (B)
Let S1 and S2 be two stacks. S1 has capacity of 4 elements. S2 has capacity of 2 elements. S1 already has 4 elements: 100, 200, 300, and 400, whereas S2 is empty, as shown below.
Stack S1
Stack S2
Only the following three operations are available:
PushToS2: Pop the top element from S1 and push it on S2.
PushToS1: Pop the top element from S2 and push it on S1.
GenerateOutput: Pop the top element from S1 and output it to the user.
Note that the pop operation is not allowed on an empty stack and the push operation is not allowed on a full stack.
Which of the following output sequences can be generated by using the above operations?
Stack S1
Stack S2
Only the following three operations are available:
PushToS2: Pop the top element from S1 and push it on S2.
PushToS1: Pop the top element from S2 and push it on S1.
GenerateOutput: Pop the top element from S1 and output it to the user.
Note that the pop operation is not allowed on an empty stack and the push operation is not allowed on a full stack.
Which of the following output sequences can be generated by using the above operations?
One or more options are correct.
Answer: (B), (C), (D)
S1 holds 100, 200, 300, 400 (top). S2 can hold only 2 elements.
- 100, 200, 400, 300: to output 100 first, the elements 400, 300 and 200 (3 elements) must all go to S2, but S2 holds only 2. So this is not possible.
- 200, 300, 400, 100: move 400 and 300 to S2. Output 200. Move 300 back and output 300. Move 400 back and output 400. Then output 100. This is possible.
- 400, 200, 100, 300: output 400. Move 300 to S2. Output 200 and 100. Move 300 back and output 300. This is possible.
- 300, 200, 400, 100: move 400 to S2. Output 300 and 200. Move 400 back and output 400. Then output 100. This is possible.
Answer: (B), (C), (D)
- 100, 200, 400, 300: to output 100 first, the elements 400, 300 and 200 (3 elements) must all go to S2, but S2 holds only 2. So this is not possible.
- 200, 300, 400, 100: move 400 and 300 to S2. Output 200. Move 300 back and output 300. Move 400 back and output 400. Then output 100. This is possible.
- 400, 200, 100, 300: output 400. Move 300 to S2. Output 200 and 100. Move 300 back and output 300. This is possible.
- 300, 200, 400, 100: move 400 to S2. Output 300 and 200. Move 400 back and output 400. Then output 100. This is possible.
Answer: (B), (C), (D)
Which of the following is/are EQUAL to 224 in radix-5 (i.e., base-5) notation?
One or more options are correct.
Answer: (A), (B), (D)
- Yes
- Yes
- No
- Yes
Answer: 64 in radix-10, 100 in radix-8, 121 in radix-7
Consider 4-variable functions expressed in sum-of-minterms form as given below.
With respect to the circuit given above, which of the following options is/are CORRECT?
With respect to the circuit given above, which of the following options is/are CORRECT?
One or more options are correct.
Answer: (C), (D)
Find the AND, OR and XOR outputs as sets of minterms:
- AND: takes only the minterms common to both, so it is
- OR:
- XOR keeps the minterms that are in exactly one set: . Minterms 11 and 13 are in both sets, so they are dropped.
The result is (that is, ).
Answer: and
- AND: takes only the minterms common to both, so it is
- OR:
- XOR keeps the minterms that are in exactly one set: . Minterms 11 and 13 are in both sets, so they are dropped.
The result is (that is, ).
Answer: and