StreakPeaked· Practice

ExamsGATETechnical › GATE 2023 Computer Science and Information Technology (CS)

GATE Technical: GATE 2023 Computer Science and Information Technology (CS) questions with solutions

19 questions with worked solutions.

Questions

Q1. Which one of the following sequences when stored in an array at locations A[1],..., A[10] forms a max-heap?

  1. 23, 17, 10, 6, 13, 14, 1, 5, 7, 12
  2. 23, 17, 14, 7, 13, 10, 1, 5, 6, 12
  3. 23, 17, 14, 6, 13, 10, 1, 5, 7, 15
  4. 23, 14, 17, 1, 10, 13, 16, 12, 7, 5

Answer: 23, 17, 14, 7, 13, 10, 1, 5, 6, 12

This sequence satisfies the max-heap property where each parent node is greater than or equal to its child nodes, ensuring that the largest element is at the root and all levels of the heap maintain this order.

Q2. Let SLLdel be a function that deletes a node in a singly-linked list given a pointer to the node and a pointer to the head of the list. Similarly, let DLLdel be another function that deletes a node in a doubly-linked list given a pointer to the node and a pointer to the head of the list. Let n denote the number of nodes in each of the linked lists. Which one of the following choices is TRUE about the worst-case time complexity of SLLdel and DLLdel?

  1. SLLdel is O(1) and DLLdel is O(n)
  2. Both SLLdel and DLLdel are O(log(n))
  3. Both SLLdel and DLLdel are O(1)
  4. SLLdel is O(n) and DLLdel is O(1)

Answer: SLLdel is O(n) and DLLdel is O(1)

SLLdel has a worst-case time complexity of O(n) because it may need to traverse the list to find the node to delete, while DLLdel can delete a node in O(1) time since it has direct access to both the previous and next nodes, allowing for immediate adjustments to the pointers.

Q3. Consider the Deterministic Finite-state Automaton (DFA) A shown below. The DFA runs on the alphabet {0,1}, and has the set of states {s,p,q,r}, with s being the start state and p being the only final state. Which one of the following regular expressions correctly describes the language accepted by A?

  1. 1(0*11)*
  2. 0(0 + 1)*
  3. 1(0 + 11)*
  4. 1(110*)*

Answer: 1(0 + 11)*

The correct option, 1(0 + 11)*, accurately represents the language accepted by the DFA because it starts with a '1' followed by any combination of '0's and '11's, which aligns with the transitions and final state conditions of the automaton.

Q4. Which one of the options given below refers to the degree (or arity) of a relation in relational database systems?

  1. Number of attributes of its relation schema.
  2. Number of tuples stored in the relation.
  3. Number of entries in the relation.
  4. Number of distinct domains of its relation schema.

Answer: Number of attributes of its relation schema.

The degree, or arity, of a relation in a relational database refers to the number of attributes (or columns) in its schema, which defines the structure of the data within that relation.

Q5. Suppose two hosts are connected by a point-to-point link and they are configured to use Stop-and-Wait protocol for reliable data transfer. Identify in which one of the following scenarios, the utilization of the link is the lowest.

  1. Longer link length and lower transmission rate
  2. Longer link length and higher transmission rate
  3. Shorter link length and lower transmission rate
  4. Shorter link length and higher transmission rate

Answer: Longer link length and higher transmission rate

In the Stop-and-Wait protocol, the utilization is affected by the round-trip time and the time taken to send a packet. A longer link length increases the round-trip time, which means the sender spends more time waiting for an acknowledgment, resulting in lower utilization, even if the transmission rate is higher.

Q6. An algorithm has to store several keys generated by an adversary in a hash table. The adversary is malicious who tries to maximize the number of collisions. Let k be the number of keys, m be the number of slots in the hash table, and k > m. Which one of the following is the best hashing strategy to counteract the adversary?

  1. Division method, i.e., use the hash function h(k) = k mod m.
  2. Multiplication method, i.e., use the hash function h(k) = [m(kA − [kA])], where A is a carefully chosen constant.
  3. Universal hashing method.
  4. If k is a prime number, use Division method. Otherwise, use Multiplication method.

Answer: Universal hashing method.

Universal hashing is designed to minimize the impact of an adversary by randomly selecting a hash function from a family of functions, making it difficult for the adversary to predict and exploit collisions. This randomness ensures that even if the keys are chosen maliciously, the expected number of collisions remains low, providing a robust defense against collision attacks.

Q7. The output of a 2-input multiplexer is connected back to one of its inputs as shown in the figure. Match the functional equivalence of this circuit to one of the following options.

  1. D Flip-flop
  2. D Latch
  3. Half-adder
  4. Demultiplexer

Answer: D Latch

The circuit behaves like a D latch because it holds the value of the input when the control signal is active, allowing it to store data based on the input while being transparent to changes when the control signal is inactive.

Q8. Which one or more of the following need to be saved on a context switch from one thread (T1) of a process to another thread (T2) of the same process?

  1. Page table base register
  2. Stack pointer
  3. Program counter
  4. General purpose registers

Answer: Stack pointer

The stack pointer must be saved during a context switch because it indicates the current position in the stack for the thread, which is essential for maintaining the correct execution state when switching between threads.

Q9. Which of the following statements is/are INCORRECT about the OSPF (Open Shortest Path First) routing protocol used in the Internet?

  1. OSPF implements Bellman-Ford algorithm to find shortest paths.
  2. OSPF uses Dijkstra’s shortest path algorithm to implement least-cost path routing.
  3. OSPF is used as an inter-domain routing protocol.
  4. OSPF implements hierarchical routing.

Answer: OSPF implements Bellman-Ford algorithm to find shortest paths.

The statement is incorrect because OSPF actually uses Dijkstra’s algorithm, not Bellman-Ford, to calculate the shortest paths in a network. This distinction is crucial as it affects how OSPF determines the most efficient routing paths.

Q10. Which one or more of the following CPU scheduling algorithms can potentially cause starvation?

  1. First-in First-Out
  2. Round Robin
  3. Priority Scheduling
  4. Shortest Job First

Answer: Priority Scheduling

Priority Scheduling can lead to starvation because lower-priority processes may be indefinitely postponed if higher-priority processes continuously arrive, preventing them from getting CPU time.

Q11. Consider the two functions incr and decr shown below. incr(){ wait(s); X = X+1; signal(s); } decr(){ wait(s); X = X-1; signal(s); } There are 5 threads each invoking incr once, and 3 threads each invoking decr once, on the same shared variable X. The initial value of X is 10. Suppose there are two implementations of the semaphore s, as follows: I-1: s is a binary semaphore initialized to 1. I-2: s is a counting semaphore initialized to 2. Let V1, V2 be the values of X at the end of execution of all the threads with implementations I-1, I-2, respectively. Which one of the following choices corresponds to the minimum possible values of V1, V2, respectively?

  1. 15, 7
  2. 7, 7
  3. 12, 7
  4. 12, 8

Answer: 12, 7

The correct option is 12 for V1 because with a binary semaphore, only one thread can modify X at a time, allowing for all increments to occur before any decrements, resulting in 10 + 5 - 3 = 12. For V2, the counting semaphore allows two threads to access X simultaneously, but even with this concurrency, the maximum value achievable after all operations is 10 + 5 - 3 = 12, but the minimum possible value is 7 due to potential interleaving of operations.

Q12. Consider the context-free grammar G below S → aSb | X X → aX | Xb | a | b, where S and X are non-terminals, and a and b are terminal symbols. The starting non-terminal is S. Which one of the following statements is CORRECT?

  1. The language generated by G is (a + b)*
  2. The language generated by G is a*(a + b)b*
  3. The language generated by G is a*b*(a + b)
  4. The language generated by G is not a regular language

Answer: The language generated by G is a*(a + b)b*

S -> aSb gives a^n ... b^n wrapping X, and X -> aX | Xb | a | b generates a*(a+b)b*; the a^n/b^n wrappers are absorbed, so L(G) = a*(a+b)b*, which IS regular. Hence the correct statement is option index 1, not 'not regular'.

Q13. Consider the pushdown automaton (PDA) P below, which runs on the input alphabet {a,b}, has stack alphabet {⊥,A}, and has three states {s,p,q}, with s being the start state. A transition from state u to state v, labelled c/X/γ, where c is an input symbol or ε, X is a stack symbol, and γ is a string of stack symbols, represents the fact that in state u, the PDA can read c from the input, with X on the top of its stack, pop X from the stack, push in the string γ on the stack, and go to state v. In the initial configuration, the stack has only the symbol ⊥ in it. The PDA accepts by empty stack. Which one of the following options correctly describes the language accepted by P?

  1. {a^m bⁿ | 1 ≤ m and n < m}
  2. {a^m bⁿ | 0 ≤ n ≤ m}
  3. {a^m bⁿ | 0 ≤ m and 0 ≤ n}
  4. {a^m | 0 < m} ∪ {bⁿ | 0 < n}

Answer: {a^m bⁿ | 0 ≤ n ≤ m}

The correct option describes a language where the number of 'b's can be equal to or less than the number of 'a's, which aligns with the PDA's ability to push and pop symbols based on the input, ensuring that for every 'b' processed, there is a corresponding 'a' that can be matched, thus maintaining the condition 0 ≤ n ≤ m.

Q14. Consider the given C-code and its corresponding assembly code, with a few operands U1–U4 being unknown. Some useful information as well as the semantics of each unique assembly instruction is annotated as inline comments in the code. The memory is byte-addressable. // C-code int a[10], b[10], i; // int is 32-bit for (i=0; i<10; i++) a[i] = b[i] * 8; ; assembly-code (; indicates comments) ;r1–r5 are 32-bit integer registers ;initialize r1=0, r2=10 ; r3, r4 with base address of a, b L01: jeq r1, r2, end;if(r1==r2) goto end L02: lw r5, 0(r4);r5 <- Memory[r4+0] L03: shl r5, r5, U1;r5 <- r5 << U1 L04: sw r5, 0(r3);Memory[r3+0] <- r5 L05: add r3, r3, U2;r3 <- r3+U2 L06: add r4, r4, U3;r4 <- r4+U3 L07: add r1, r1, 1 L08: jmp U4;goto U4 L09: end Which one of the following options is the CORRECT replacement for operands in the position (U1, U2, U3, U4) in the above assembly code?

  1. (8, 4, 1, L02)
  2. (3, 4, 4, L01)
  3. (8, 1, 1, L02)
  4. (3, 1, 1, L01)

Answer: (3, 4, 4, L01)

The correct option (3, 4, 4, L01) is right because the left shift operation in U1 must shift the value by 3 bits to multiply by 8 (2³), U2 should increment the address of array 'a' by 4 bytes (size of an int), and U3 should increment the address of array 'b' by 4 bytes as well. The jump back to L01 ensures the loop continues until the condition is met.

Q15. A Boolean digital circuit is composed using two 4-input multiplexers (M1 and M2) and one 2-input multiplexer (M3) as shown in the figure. X0-X7 are the inputs of the multiplexers M1 and M2 and could be connected to either 0 or 1. The select lines of the multiplexers are connected to Boolean variables A, B and C as shown. Which one of the following set of values of (X0, X1, X2, X3, X4, X5, X6, X7) will realise the Boolean function A + A̅.C̅ + A.B.C?

  1. (1, 1, 0, 0, 1, 1, 1, 0)
  2. (1, 1, 0, 0, 1, 1, 0, 1)
  3. (1, 1, 0, 1, 1, 1, 0, 0)
  4. (0, 0, 1, 1, 0, 1, 1, 1)

Answer: (1, 1, 0, 0, 1, 1, 1, 0)

The correct option (1, 1, 0, 0, 1, 1, 1, 0) satisfies the Boolean function A + A̅.C̅ + A.B.C by ensuring that for all combinations of A, B, and C, the output evaluates to true when A is true or when A is false and both B and C are false.

Q16. Let A be a priority queue for maintaining a set of elements. Suppose A is implemented using a max-heap data structure. The operation EXTRACT-MAX(A) extracts and deletes the maximum element from A. The operation INSERT(A,key) inserts a new element key in A. The properties of a max-heap are preserved at the end of each of these operations. When A contains n elements, which one of the following statements about the worst case running time of these two operations is TRUE?

  1. Both EXTRACT-MAX(A) and INSERT(A,key) run in O(1).
  2. Both EXTRACT-MAX(A) and INSERT(A,key) run in O(log(n)).
  3. EXTRACT-MAX(A) runs in O(1) whereas INSERT(A,key) runs in O(n).
  4. EXTRACT-MAX(A) runs in O(1) whereas INSERT(A,key) runs in O(log(n)).

Answer: Both EXTRACT-MAX(A) and INSERT(A,key) run in O(log(n)).

Both operations, EXTRACT-MAX and INSERT, involve maintaining the heap property, which requires traversing the height of the heap. Since a max-heap is a complete binary tree, the height is logarithmic in relation to the number of elements, leading to a worst-case time complexity of O(log(n)) for both operations.

Q17. Consider the C function foo and the binary tree shown. typedef struct node { int val; struct node *left, *right; } node; int foo(node *p) { int retval; if (p == NULL) return 0; else { retval = p->val + foo(p->left) + foo(p->right); printf("%d ", retval); return retval; } } When foo is called with a pointer to the root node of the given binary tree, what will it print?

  1. 3 8 5 13 11 10
  2. 3 5 8 10 11 13
  3. 3 8 16 13 24 50
  4. 3 16 8 50 24 13

Answer: 3 8 5 13 11 10

The function recursively calculates the sum of values in the binary tree, printing the cumulative sum at each node after processing its left and right children. This results in the output reflecting the order of node processing and their respective sums.

Q18. Let G be a simple, finite, undirected graph with vertex set {v1,..., vn}. Let Δ(G) denote the maximum degree of G and let N = {1, 2,...} denote the set of all possible colors. Color the vertices of G using the following greedy strategy: for i = 1,..., n, color(vi) ← min{j ∈ N: no neighbour of vi is colored j}. Which of the following statements is/are TRUE?

  1. This procedure results in a proper vertex coloring of G.
  2. The number of colors used is at most Δ(G) + 1.
  3. The number of colors used is at most Δ(G).
  4. The number of colors used is equal to the chromatic number of G.

Answer: The number of colors used is at most Δ(G) + 1.

The greedy coloring strategy ensures that each vertex is assigned the smallest color not used by its neighbors, which can require at most one additional color beyond the maximum degree of the graph, thus guaranteeing that the number of colors used does not exceed Δ(G) + 1.

Q19. The forwarding table of a router is shown below. Subnet Number | Subnet Mask | Interface ID 200.150.0.0 | 255.255.0.0 | 1 200.150.64.0 | 255.255.224.0 | 2 200.150.68.0 | 255.255.255.0 | 3 200.150.68.64 | 255.255.255.224 | 4 Default | 0 A packet addressed to a destination address 200.150.68.118 arrives at the router. It will be forwarded to the interface with ID _________.

  1. 1
  2. 2
  3. 3
  4. 4

Answer: 3

200.150.68.118 matches 200.150.68.0/24 (interface 3) but not 200.150.68.64/27 (range .64-.95, and 118>95). The longest matching prefix is the /24 entry, so it is forwarded to interface 3 (index 2).

⚔️ Practice GATE Technical free + battle 1v1 →