StreakPeaked· Practice

ExamsGATETechnical › COMPUTER SCIENCE AND INFORMATION TECHNOLOGY

GATE Technical: COMPUTER SCIENCE AND INFORMATION TECHNOLOGY questions with solutions

54 questions with worked solutions.

Questions

Q1. We want to design a synchronous counter that counts the sequence 0-1-0-2-0-3 and then repeats. The minimum number of J-K flip-flops required to implement this counter is

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

Answer: 3

The sequence 0-1-0-2-0-3 has six steps and the three occurrences of 0 are different states (they lead to different next outputs 1,2,3), so the counter needs 6 distinct states. Six states require ceil(log2 6)=3 flip-flops, so 3 J-K flip-flops are needed (index 2).

Q2. A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is CORRECT (n refers to the number of items in the queue)?

  1. Both operations can be performed in O(1) time
  2. At most one operation can be performed in O(1) time but the worst case time for the other operation will be Ω(n)
  3. The worst case time complexity for both operations will be Ω(n)
  4. Worst case time complexity for both operations will be Ω(log n)

Answer: Both operations can be performed in O(1) time

Both ENQUEUE and DEQUEUE operations can be implemented to run in O(1) time by using a circular array approach, which allows efficient addition and removal of elements without needing to shift other elements.

Q3. Consider the following C program. void f(int, short); void main() { int i = 100; short s = 12; short *p = &s; ________; // call to f() } Which one of the following expressions, when placed in the blank above, will NOT result in a type checking error?

  1. f(s,*s)
  2. i = f(i,s)
  3. f(i,*s)
  4. f(i,*p)

Answer: f(i,*p)

The expression 'f(i,*p)' correctly passes an integer and a short to the function 'f', as 'i' is an integer and '*p' dereferences to the short value stored in 's', thus matching the function's parameter types without causing a type checking error.

Q4. The worst case running times of Insertion sort, Merge sort and Quick sort, respectively, are:

  1. Θ(n log n), Θ(n log n), and Θ(n²)
  2. Θ(n²), Θ(n²), and Θ(n log n)
  3. Θ(n²), Θ(n log n), and Θ(n log n)
  4. Θ(n²), Θ(n log n), and Θ(n²)

Answer: Θ(n²), Θ(n log n), and Θ(n²)

Insertion sort has a worst-case running time of Θ(n²) due to its nested loops when the input is in reverse order. Merge sort consistently performs at Θ(n log n) because it divides the array and merges sorted subarrays regardless of the input order. Quick sort, while efficient on average, can degrade to Θ(n²) in the worst case when the pivot selection is poor, such as when the smallest or largest element is consistently chosen.

Q5. Let G be a weighted connected undirected graph with distinct positive edge weights. If every edge weight is increased by the same value, then which of the following statements is/are TRUE? P: Minimum spanning tree of G does not change Q: Shortest path between any pair of vertices does not change

  1. P only
  2. Q only
  3. Neither P nor Q
  4. Both P and Q

Answer: P only

Adding a constant to every edge preserves the relative order of edge weights, so the MST is unchanged (P true). But shortest paths can change because a path with more edges accumulates more added constant, so Q is false. Answer: P only.

Q6. Consider the following C program. #include<stdio.h> void mystery(int *ptra, int *ptrb) { int *temp; temp = ptrb; ptrb = ptra; ptra = temp; } int main() { int a=2016, b=0, c=4, d=42; mystery(&a, &b); if (a < c) mystery(&c, &a); mystery(&a, &d); printf("%d ", a); } The output of the program is _________.

  1. 2016
  2. 0
  3. 4
  4. 42

Answer: 42

The function 'mystery' swaps the pointers but does not affect the values of the variables they point to. After the calls to 'mystery', the value of 'a' is ultimately set to the value of 'd', which is 42, making that the final output.

Q7. Which of the following languages is generated by the given grammar? S → aS | bS | ε

  1. {aⁿ b^m | n,m ≥ 0}
  2. {w ∈ {a,b}* | w has equal number of a’s and b’s}
  3. {aⁿ | n ≥ 0} ∪ {bⁿ | n ≥ 0} ∪ {aⁿ bⁿ | n ≥ 0}
  4. {a,b}*

Answer: {a,b}*

The grammar allows for any combination of 'a' and 'b' by recursively adding 'a' or 'b' to the string, including the empty string, which means it can generate all possible strings made up of 'a' and 'b'.

Q8. Which of the following decision problems are undecidable? I. Given NFAs N1 and N2, is L(N1) ∩ L(N2) = Φ? II. Given a CFG G = (N, Σ, P, S) and a string x ∈ Σ*, does x ∈ L(G)? III. Given CFGs G1 and G2, is L(G1) = L(G2)? IV. Given a TM M, is L(M) = Φ?

  1. I and IV only
  2. II and III only
  3. III and IV only
  4. II and IV only

Answer: III and IV only

Options III and IV are correct because determining if two context-free grammars generate the same language (III) and whether the language of a Turing machine is empty (IV) are both undecidable problems, meaning there is no algorithm that can solve them for all possible inputs.

Q9. Which one of the following regular expressions represents the language: the set of all binary strings having two consecutive 0s and two consecutive 1s?

  1. (0 + 1)*0011(0 + 1)* + (0 + 1)*1100(0 + 1)*
  2. (0 + 1)*(00(0 + 1)*11 + 11(0 + 1)*00)(0 + 1)*
  3. (0 + 1)*00(0 + 1)* + (0 + 1)*11(0 + 1)*
  4. 00(0 + 1)*11 + 11(0 + 1)*00

Answer: (0 + 1)*(00(0 + 1)*11 + 11(0 + 1)*00)(0 + 1)*

The correct option captures the requirement for the presence of both '00' and '11' in any order within the binary strings, allowing for any characters before or after these patterns. This ensures that the strings can contain any combination of 0s and 1s while still meeting the criteria of having two consecutive 0s and two consecutive 1s.

Q10. Consider an arbitrary set of CPU-bound processes with unequal CPU burst lengths submitted at the same time to a computer system. Which one of the following process scheduling algorithms would minimize the average waiting time in the ready queue?

  1. Shortest remaining time first
  2. Round-robin with time quantum less than the shortest CPU burst
  3. Uniform random
  4. Highest priority first with priority proportional to CPU burst length

Answer: Shortest remaining time first

Shortest remaining time first (SRTF) minimizes the average waiting time by always selecting the process with the least remaining CPU burst time, allowing shorter processes to complete quickly and reducing the waiting time for subsequent processes.

Q11. Which of the following is NOT a superkey in a relational schema with attributes V, W, X, Y, Z and primary key VY?

  1. VXYZ
  2. VWXZ
  3. VWXY
  4. VWXYZ

Answer: VWXZ

VWXZ is not a superkey because it does not include the primary key attributes V and Y together, which are necessary to uniquely identify a record in the relational schema.

Q12. Which one of the following is NOT a part of the ACID properties of database transactions?

  1. Atomicity
  2. Consistency
  3. Isolation
  4. Deadlock-freedom

Answer: Deadlock-freedom

Deadlock-freedom is not one of the ACID properties; instead, it refers to a condition in which a set of processes cannot proceed because each is waiting for the other to release resources. The ACID properties focus on ensuring reliable transaction processing in databases.

Q13. Which one of the following protocols is NOT used to resolve one form of address to another one?

  1. DNS
  2. ARP
  3. DHCP
  4. RARP

Answer: DHCP

DHCP is primarily used for dynamically assigning IP addresses to devices on a network, rather than resolving one address type to another, which is the function of the other protocols listed.

Q14. Which of the following is/are example(s) of stateful application layer protocols? (i) HTTP (ii) FTP (iii) TCP (iv) POP3

  1. (i) and (ii) only
  2. (ii) and (iii) only
  3. (ii) and (iv) only
  4. (iv) only

Answer: (ii) and (iv) only

FTP and POP3 are considered stateful application layer protocols because they maintain session information and state across multiple requests, unlike HTTP, which is stateless.

Q15. Consider a carry lookahead adder for adding two n-bit integers, built using gates of fan-in at most two. The time to perform addition using this adder is

  1. Θ(1)
  2. Θ(log(n))
  3. Θ(√n)
  4. Θ(n)

Answer: Θ(log(n))

The carry lookahead adder improves the speed of addition by calculating carry signals in parallel, allowing the addition process to be completed in logarithmic time relative to the number of bits, as it reduces the depth of the circuit to a logarithmic scale.

Q16. The following function computes the maximum value contained in an integer array p[ ] of size n (n >= 1). int max(int *p, int n) { int a=0, b=n-1; while (__________) { if (p[a] <= p[b]) { a = a+1; } else { b = b-1; } } return p[a]; } The missing loop condition is

  1. a != n
  2. b != 0
  3. b > (a + 1)
  4. b != a

Answer: b != a

The loop condition 'b != a' ensures that the indices a and b do not cross each other, allowing the function to correctly compare elements from both ends of the array until the maximum value is found. This prevents the loop from terminating prematurely and guarantees that the maximum value is identified.

Q17. What will be the output of the following C program? void count(int n){ static int d=1; printf("%d ", n); printf("%d ", d); d++; if(n>1) count(n-1); printf("%d ", d); } void main(){ count(3); }

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

Answer: 3 1 2 2 1 3 4 4

The correct output is generated by the recursive function, which prints the current value of 'n', the static variable 'd', and increments 'd' with each call. As the recursion unwinds, it prints 'd' again, resulting in the sequence observed in the correct option.

Q18. An operator delete(i) for a binary heap data structure is to be designed to delete the item in the i-th node. Assume that the heap is implemented in an array and i refers to the i-th index of the array. If the heap tree has depth d (number of edges on the path from the root to the farthest leaf), then what is the time complexity to re-fix the heap efficiently after the removal of the element?

  1. O(1)
  2. O(d) but not O(1)
  3. O(2^d) but not O(d)
  4. O(d²) but not O(2^d)

Answer: O(d) but not O(1)

After removing an element from a binary heap, the heap property must be restored, which involves either bubbling down or bubbling up the affected node. This process can take time proportional to the depth of the heap, denoted as d, since the maximum number of levels to traverse is equal to the depth.

Q19. Consider the following context-free grammars: G1: S → aS|B, B → b|bB G2: S → aA|bB, A → aA|B|ε, B → bB|ε Which one of the following pairs of languages is generated by G1 and G2, respectively?

  1. {a^m bⁿ | m > 0 or n > 0} and {a^m bⁿ | m > 0 and n > 0}
  2. {a^m bⁿ | m > 0 and n > 0} and {a^m bⁿ | m > 0 or n > 0}
  3. {a^m bⁿ | m ≥ 0 or n > 0} and {a^m bⁿ | m > 0 and n > 0}
  4. {a^m bⁿ | m ≥ 0 and n > 0} and {a^m bⁿ | m > 0 or n > 0}

Answer: {a^m bⁿ | m ≥ 0 and n > 0} and {a^m bⁿ | m > 0 or n > 0}

The correct option accurately describes the languages generated by the grammars: G1 allows for any number of 'a's followed by at least one 'b', while G2 requires at least one 'a' or one 'b', ensuring that both languages have the specified conditions on the counts of 'a's and 'b's.

Q20. Consider the transition diagram of a PDA given below with input alphabet Σ = {a,b} and stack alphabet Γ = {X,Z}. Z is the initial stack symbol. Let L denote the language accepted by the PDA. Which one of the following is TRUE?

  1. L = {aⁿ bⁿ | n ≥ 0} and is not accepted by any finite automata
  2. L = {aⁿ | n ≥ 0} ∪ {aⁿ bⁿ | n ≥ 0} and is not accepted by any deterministic PDA
  3. L is not accepted by any Turing machine that halts on every input
  4. L = {aⁿ | n ≥ 0} ∪ {aⁿ bⁿ | n ≥ 0} and is deterministic context-free

Answer: L = {aⁿ | n ≥ 0} ∪ {aⁿ bⁿ | n ≥ 0} and is deterministic context-free

The correct option accurately describes the language accepted by the PDA as a union of two sets: strings of 'a's of any length and strings of 'a's followed by an equal number of 'b's. This language can be recognized by a deterministic pushdown automaton, confirming its classification as deterministic context-free.

Q21. Let X be a recursive language and Y be a recursively enumerable but not recursive language. Let W and Z be two languages such that ̅Y reduces to W, and Z reduces to ̅X (reduction means the standard many-one reduction). Which one of the following statements is TRUE?

  1. W can be recursively enumerable and Z is recursive.
  2. W can be recursive and Z is recursively enumerable.
  3. W is not recursively enumerable and Z is recursive.
  4. W is not recursively enumerable and Z is not recursive.

Answer: W is not recursively enumerable and Z is recursive.

Since Y is r.e. but not recursive, its complement bar-Y is not r.e.; as bar-Y many-one reduces to W, W cannot be r.e. either. X is recursive so bar-X is recursive, and Z reducing to bar-X makes Z recursive. Thus W is not r.e. and Z is recursive.

Q22. Consider the following proposed solution for the critical section problem. There are n processes: P0,...,Pn-1. In the code, function pmax returns an integer not smaller than any of its arguments. For all i, t[i] is initialized to zero. Code for Pi: do { c[i]=1; t[i] = pmax(t[0],...,t[n-1])+1; c[i]=0; for every j != i in {0,...,n-1} { while (c[j]); while (t[j] != 0 && t[j]<=t[i]); } Critical Section; t[i]=0; Remainder Section; } while (true); Which one of the following is TRUE about the above solution?

  1. At most one process can be in the critical section at any time
  2. The bounded wait condition is satisfied
  3. The progress condition is satisfied
  4. It cannot cause a deadlock

Answer: At most one process can be in the critical section at any time

The solution ensures that only one process can enter the critical section by using the timestamp mechanism, where each process waits for others to finish based on their timestamps. This guarantees mutual exclusion, as a process will only enter the critical section when it has the highest timestamp among all processes.

Q23. Consider the following two phase locking protocol. Suppose a transaction T accesses (for read or write operations), a certain set of objects {O1,...,Ok}. This is done in the following manner: Step 1. T acquires exclusive locks to O1,...,Ok in increasing order of their addresses. Step 2. The required operations are performed. Step 3. All locks are released. This protocol will

  1. guarantee serializability and deadlock-freedom
  2. guarantee neither serializability nor deadlock-freedom
  3. guarantee serializability but not deadlock-freedom
  4. guarantee deadlock-freedom but not serializability

Answer: guarantee serializability and deadlock-freedom

The protocol ensures that locks are acquired in a strict order, which prevents circular wait conditions, thereby achieving deadlock-freedom. Additionally, by acquiring all necessary locks before performing any operations, it guarantees that the transactions will execute in a manner that is equivalent to some serial execution, ensuring serializability.

Q24. Consider that B wants to send a message m that is digitally signed to A. Let the pair of private and public keys for A and B be denoted by K_A⁻ and K_A⁺ for x = A,B, respectively. Let Kₓ(m) represent the operation of encrypting m with a key Kₓ and H(m) represent the message digest. Which one of the following indicates the CORRECT way of sending the message m along with the digital signature to A?

  1. {m, K_B^+(H(m))}
  2. {m, K_B^-(H(m))}
  3. {m, K_A^-(H(m))}
  4. {m, K_A^+(m)}

Answer: {m, K_B^-(H(m))}

The correct option is right because B needs to sign the message digest H(m) using their private key K_B⁻, which allows A to verify the signature using B's public key K_B⁺. This ensures the authenticity and integrity of the message.

Q25. Let x1 ⊕ x2 ⊕ x3 ⊕ x4 = 0 where x1, x2, x3, x4 are Boolean variables, and ⊕ is the XOR operator. Which one of the following must always be TRUE?

  1. x1 x2 x3 x4 = 0
  2. x1 x3 + x2 = 0
  3. x̄1 ⊕ x̄3 = x̄2 ⊕ x̄4
  4. x1 + x2 + x3 + x4 = 0

Answer: x̄1 ⊕ x̄3 = x̄2 ⊕ x̄4

The equation x1 ⊕ x2 ⊕ x3 ⊕ x4 = 0 indicates that the number of true values among x1, x2, x3, and x4 must be even. The correct option shows that the negations of the variables also maintain this even parity, as the XOR operation on the negated variables reflects the same relationship.

Q26. Assume that the algorithms considered here sort the input sequences in ascending order. If the input is already in ascending order, which of the following are TRUE? I. Quicksort runs in Θ(n²) time II. Bubblesort runs in Θ(n²) time III. Mergesort runs in Θ(n) time IV. Insertion sort runs in Θ(n) time

  1. (A) I and II only
  2. (B) I and III only
  3. (C) II and IV only
  4. (D) I and IV only

Answer: (D) I and IV only

Quicksort has a worst-case time complexity of Θ(n²) when the input is already sorted, as it may repeatedly choose poor pivot elements. Insertion sort, however, is efficient for already sorted data, operating in Θ(n) time as it only requires a single pass through the list to confirm order.

Q27. The Floyd-Warshall algorithm for all-pair shortest paths computation is based on

  1. Greedy paradigm.
  2. Divide-and-Conquer paradigm.
  3. Dynamic Programming paradigm.
  4. neither Greedy nor Divide-and-Conquer nor Dynamic Programming paradigm.

Answer: Dynamic Programming paradigm.

The Floyd-Warshall algorithm utilizes dynamic programming by systematically considering all pairs of vertices and updating the shortest path estimates based on previously computed paths, ensuring that all possible paths are evaluated efficiently.

Q28. Language L1 is defined by the grammar: S1 → aS1b | ε Language L2 is defined by the grammar: S2 → abS2 | ε Consider the following statements: P: L1 is regular Q: L2 is regular Which one of the following is TRUE?

  1. Both P and Q are true
  2. P is true and Q is false
  3. P is false and Q is true
  4. Both P and Q are false

Answer: P is false and Q is true

L1 generates a^n b^n, which is not regular (requires matching counts, provable by pumping lemma). L2 generates (ab)^n = (ab)*, which is regular. So P is false and Q is true.

Q29. Consider the following types of languages: L1: Regular, L2: Context-free, L3: Recursive, L4: Recursively enumerable. Which of the following is/are TRUE? I. L̅3 ∪ L4 is recursively enumerable II. L̅2 ∪ L3 is recursive III. L1* ∩ L2 is context-free IV. L̅1 ∪ L̅2 is context-free

  1. I only
  2. I and III only
  3. I and IV only
  4. I, II and III only

Answer: I, II and III only

The correct options are true because: I states that the complement of a recursive language combined with a recursively enumerable language is recursively enumerable, which is accurate; II indicates that the union of the complement of a context-free language and a recursive language is recursive, which holds true; III asserts that the intersection of a regular language (which is closed under intersection) and a context-free language results in a context-free language, which is also correct.

Q30. Match the following: (P) Lexical analysis (Q) Top down parsing (R) Semantic analysis (S) Runtime environments (i) Leftmost derivation (ii) Type checking (iii) Regular expressions (iv) Activation records

  1. P ↔ i, Q ↔ ii, R ↔ iv, S ↔ iii
  2. P ↔ iii, Q ↔ i, R ↔ ii, S ↔ iv
  3. P ↔ ii, Q ↔ iii, R ↔ i, S ↔ iv
  4. P ↔ iv, Q ↔ i, R ↔ ii, S ↔ iii

Answer: P ↔ iii, Q ↔ i, R ↔ ii, S ↔ iv

The correct option matches lexical analysis with regular expressions, as it involves tokenizing input based on patterns defined by regular expressions. Top-down parsing is associated with leftmost derivation, which is a method of constructing parse trees. Semantic analysis relates to type checking, ensuring that operations in the code are semantically valid, while runtime environments are linked to activation records, which manage function calls and local variables during execution.

Q31. In which one of the following page replacement algorithms it is possible for the page fault rate to increase even when the number of allocated frames increases?

  1. LRU (Least Recently Used)
  2. OPT (Optimal Page Replacement)
  3. MRU (Most Recently Used)
  4. FIFO (First In First Out)

Answer: FIFO (First In First Out)

FIFO can lead to an increase in page fault rates when more frames are allocated because it may evict pages that are still needed, unlike other algorithms that consider usage patterns.

Q32. B+ Trees are considered BALANCED because

  1. the lengths of the paths from the root to all leaf nodes are all equal.
  2. the lengths of the paths from the root to all leaf nodes differ from each other by at most 1.
  3. the number of children of any two non-leaf sibling nodes differ by at most 1.
  4. the number of records in any two leaf nodes differ by at most 1.

Answer: the lengths of the paths from the root to all leaf nodes are all equal.

B+ Trees are balanced because all leaf nodes are at the same depth, ensuring that the paths from the root to each leaf node are of equal length, which allows for efficient searching and maintaining order.

Q33. Suppose a database schedule S involves transactions T1,..., Tn. Construct the precedence graph of S with vertices representing the transactions and edges representing the conflicts. If S is serializable, which one of the following orderings of the vertices of the precedence graph is guaranteed to yield a serial schedule?

  1. Topological order
  2. Depth-first order
  3. Breadth-first order
  4. Ascending order of transaction indices

Answer: Topological order

A topological order of the vertices in a precedence graph ensures that for every directed edge from transaction Ti to Tj, Ti appears before Tj in the ordering. This property is essential for constructing a serial schedule that respects the conflicts represented in the graph, thereby guaranteeing serializability.

Q34. Anarkali digitally signs a message and sends it to Salim. Verification of the signature by Salim requires

  1. Anarkali’s public key.
  2. Salim’s public key.
  3. Salim’s private key.
  4. Anarkali’s private key.

Answer: Anarkali’s public key.

To verify a digital signature, the recipient needs the sender's public key, which is used to confirm that the signature was created with the corresponding private key, ensuring the authenticity of the message.

Q35. In an Ethernet local area network, which one of the following statements is TRUE?

  1. A station stops to sense the channel once it starts transmitting a frame.
  2. The purpose of the jamming signal is to pad the frames that are smaller than the minimum frame size.
  3. A station continues to transmit the packet even after the collision is detected.
  4. The exponential backoff mechanism reduces the probability of collision on retransmissions.

Answer: The exponential backoff mechanism reduces the probability of collision on retransmissions.

The exponential backoff mechanism helps to minimize the chances of collisions during retransmissions by increasing the wait time exponentially after each successive collision, allowing more time for the network to clear before attempting to resend the data.

Q36. Identify the correct sequence in which the following packets are transmitted on the network by a host when a browser requests a webpage from a remote server, assuming that the host has just been restarted.

  1. HTTP GET request, DNS query, TCP SYN
  2. DNS query, HTTP GET request, TCP SYN
  3. DNS query, TCP SYN, HTTP GET request
  4. TCP SYN, DNS query, HTTP GET request

Answer: DNS query, TCP SYN, HTTP GET request

The correct sequence starts with a DNS query to resolve the domain name into an IP address, followed by a TCP SYN packet to establish a connection with the server, and finally the HTTP GET request to retrieve the webpage.

Q37. A binary relation R on N × N is defined as follows: (a,b)R(c,d) if a ≤ c or b ≤ d. Consider the following propositions: P: R is reflexive Q: R is transitive Which one of the following statements is TRUE?

  1. Both P and Q are true.
  2. P is true and Q is false.
  3. P is false and Q is true.
  4. Both P and Q are false.

Answer: P is true and Q is false.

The relation R is reflexive because for any pair (a,b), it holds that (a,b)R(a,b) since a ≤ a and b ≤ b. However, R is not transitive because if (a,b)R(c,d) and (c,d)R(e,f), it does not necessarily follow that (a,b)R(e,f) since the conditions can fail when combining the inequalities.

Q38. Which one of the following well-formed formulae in predicate calculus is NOT valid?

  1. (∀x p(x) ⇒ ∀x q(x)) ⇒ (∃x ¬p(x) ∨ ∀x q(x))
  2. (∃x p(x) ∨ ∃x q(x)) ⇒ ∃x (p(x) ∨ q(x))
  3. ∃x (p(x) ∧ q(x)) ⇒ (∃x p(x) ∧ ∃x q(x))
  4. ∀x (p(x) ∨ q(x)) ⇒ (∀x p(x) ∨ ∀x q(x))

Answer: ∀x (p(x) ∨ q(x)) ⇒ (∀x p(x) ∨ ∀x q(x))

The formula ∀x (p(x) ∨ q(x)) ⇒ (∀x p(x) ∨ ∀x q(x)) is not valid because it suggests that if every element satisfies either p or q, then every element must satisfy p or every element must satisfy q, which is not necessarily true; there can be elements that satisfy p and others that satisfy q.

Q39. The following function computes X^Y for positive integers X and Y. int exp(int X, int Y) { int res = 1, a = X, b = Y; while (b != 0) { if (b%2 == 0) { a = a*a; b = b/2; } else { res = res*a; b = b-1; } } return res; } Which one of the following conditions is TRUE before every iteration of the loop?

  1. (A) X^Y = a^b
  2. (B) (res*a)^Y = (res*X)^b
  3. (C) X^Y = res * a^b
  4. (D) X¹ = (res * a)^b

Answer: (C) X^Y = res * a^b

The condition X^Y = res * a^b holds true before each iteration because the algorithm progressively breaks down the exponent Y while maintaining the product of the accumulated result (res) and the current base (a) raised to the remaining exponent (b). This ensures that the overall value of X^Y is preserved throughout the loop.

Q40. In an adjacency list representation of an undirected simple graph G = (V,E), each edge (u,v) has two adjacency list entries: [v] in the adjacency list of u, and [u] in the adjacency list of v. These are called twins of each other. A twin pointer is a pointer from an adjacency list entry to its twin. If |E| = m and |V| = n, and the memory size is not a constraint, what is the time complexity of the most efficient algorithm to set the twin pointer in each entry in each adjacency list?

  1. Θ(n²)
  2. Θ(n+m)
  3. Θ(m²)
  4. Θ(n⁴)

Answer: Θ(n+m)

The time complexity is Θ(n+m) because each vertex's adjacency list is processed once to set the twin pointers, resulting in a linear traversal of all vertices (n) and edges (m) in the graph.

Q41. Consider the following two statements: I. If all states of an NFA are accepting states then the language accepted by the NFA is Σ*. II. There exists a regular language A such that for all languages B, A ∩ B is regular. Which one of the following is CORRECT?

  1. Only I is true
  2. Only II is true
  3. Both I and II are true
  4. Both I and II are false

Answer: Only II is true

Statement I is false because if all states of an NFA are accepting, it only means that the NFA accepts all strings that can be formed from the input alphabet, but it does not guarantee acceptance of all possible strings in Σ*. Statement II is true as the regular language A can be chosen as the empty set, which ensures that the intersection with any language B remains regular.

Q42. Consider the following languages: L1 = {aⁿ b^m c^(n+m): m,n ≥ 1} L2 = {aⁿ bⁿ c^(2n): n ≥ 1} Which one of the following is TRUE?

  1. Both L1 and L2 are context-free.
  2. L1 is context-free while L2 is not context-free.
  3. L2 is context-free while L1 is not context-free.
  4. Neither L1 nor L2 is context-free.

Answer: Both L1 and L2 are context-free.

Both languages L1 and L2 can be generated by context-free grammars, as they can be described by rules that allow for the correct counting and arrangement of symbols, thus satisfying the properties of context-free languages.

Q43. Which one of the following grammars is free from left recursion?

  1. S → AB A → Aa | b B → c
  2. S → Ab | Bb | c A → Bd | ε B → e
  3. S → Aa | B A → Bb | Sc | ε B → d
  4. S → Aa | Bb | c A → Bd | ε B → Ae | ε

Answer: S → Ab | Bb | c A → Bd | ε B → e

The correct option is free from left recursion because none of its productions lead to a non-terminal that can eventually derive itself as the first symbol in the derivation, thus preventing infinite loops during parsing.

Q44. Consider the following two-process synchronization solution. Process 0 -------- Entry: loop while (turn == 1); (critical section) Exit: turn = 1; Process 1 -------- Entry: loop while (turn == 0); (critical section) Exit: turn = 0; The shared variable turn is initialized to zero. Which one of the following is TRUE?

  1. This is a correct two-process synchronization solution.
  2. This solution violates mutual exclusion requirement.
  3. This solution violates progress requirement.
  4. This solution violates bounded wait requirement.

Answer: This solution violates progress requirement.

The solution violates the progress requirement because if one process enters its critical section, the other process may be indefinitely delayed if it keeps waiting for the turn variable to change, leading to a situation where neither process can proceed.

Q45. Consider the following database schedule with two transactions, T1 and T2. S = r2(X); r1(X); r2(Y); w1(X); r1(Y); w2(X); a1; a2 where ri(Z) denotes a read operation by transaction Ti on a variable Z, wi(Z) denotes a write operation by Ti on a variable Z, and ai denotes abort by transaction Ti. Which one of the following statements about the above schedule is TRUE?

  1. S is non-recoverable
  2. S is recoverable, but has a cascading abort
  3. S does not have a cascading abort
  4. S is strict

Answer: S does not have a cascading abort

The schedule does not have a cascading abort because T1 reads the values of X and Y before T2 writes to X, meaning T1's operations are not dependent on T2's writes. Therefore, if T2 were to abort, T1 would not be affected by any uncommitted changes.

Q46. For the IEEE 802.11 MAC protocol for wireless communication, which of the following statements is/are TRUE? I. At least three non-overlapping channels are available for transmissions. II. The RTS-CTS mechanism is used for collision detection. III. Unicast frames are ACKed.

  1. All I, II, and III
  2. I and III only
  3. II and III only
  4. II only

Answer: I and III only

Statement I is true because the IEEE 802.11 standard provides multiple non-overlapping channels for efficient communication. Statement III is also true as unicast frames require acknowledgment to ensure successful delivery. However, statement II is incorrect because the RTS-CTS mechanism is used for collision avoidance, not detection.

Q47. Consider the following C program. #include<stdio.h> struct Ournode{ char x,y,z; }; int main(){ struct Ournode p = {'1', '0', 'a'+2}; struct Ournode *q = &p; printf ("%c, %c", *((char*)q+1), *((char*)q+2)); return 0; } The output of this program is:

  1. 0,c
  2. 0,a+2
  3. '0','a+2'
  4. '0','c'

Answer: 0,c

The program initializes a struct with characters, where '1' is at index 0, '0' at index 1, and 'a'+2 evaluates to 'c' at index 2. The pointer arithmetic used in the printf statement accesses the second and third characters of the struct, resulting in '0' and 'c' being printed.

Q48. A queue is implemented using a non-circular singly linked list. The queue has a head pointer and a tail pointer, as shown in the figure. Let n denote the number of nodes in the queue. Let enqueue be implemented by inserting a new node at the head, and dequeue be implemented by deletion of a node from the tail. Which one of the following is the time complexity of the most time-efficient implementation of enqueue and dequeue, respectively, for this data structure?

  1. Θ(1), Θ(1)
  2. Θ(1), Θ(n)
  3. Θ(n), Θ(1)
  4. Θ(n), Θ(n)

Answer: Θ(1), Θ(n)

In this implementation, enqueueing a new node at the head can be done in constant time, Θ(1), since it only requires adjusting the head pointer. However, dequeuing from the tail requires traversing the entire list to find the second-to-last node, resulting in a linear time complexity of Θ(n).

Q49. Consider the following statements regarding the slow start phase of the TCP congestion control algorithm. Note that cwnd stands for the TCP congestion window and MSS denotes the Maximum Segment Size. (i) The cwnd increases by 2 MSS on every successful acknowledgement. (ii) The cwnd approximately doubles on every successful acknowledgement. (iii) The cwnd increases by 1 MSS every round trip time. (iv) The cwnd approximately doubles every round trip time. Which one of the following is correct?

  1. Only (ii) and (iii) are true
  2. Only (i) and (iii) are true
  3. Only (iv) is true
  4. Only (i) and (iv) are true

Answer: Only (iv) is true

During slow start cwnd increases by 1 MSS per ACK, which makes it roughly double every round-trip time. So (i) and (ii) (per-ACK doubling/+2) are false and (iii) (+1 MSS per RTT) is false; only (iv) (doubles every RTT) is true.

Q50. Assume that multiplying a matrix G1 of dimension p × q with another matrix G2 of dimension q × r requires pqr scalar multiplications. Computing the product of n matrices G1 G2 G3... Gn can be done by parenthesizing in different ways. Define G_i G_(i+1) as an explicitly computed pair for a given parenthesization if they are directly multiplied. For example, in the matrix multiplication chain G1 G2 G3 G4 G5 G6 using parenthesization ((G1(G2G3))(G4(G5G6))), G2G3 and G5G6 are the only explicitly computed pairs. Consider a matrix multiplication chain F1 F2 F3 F4 F5, where matrices F1, F2, F3, F4 and F5 are of dimensions 2×25, 25×3, 3×16, 16×1 and 1×1000, respectively. In the parenthesization of F1 F2 F3 F4 F5 that minimizes the total number of scalar multiplications, the explicitly computed pairs is/are

  1. F1F2 and F3F4 only
  2. F2F3 only
  3. F3F4 only
  4. F1F2 and F4F5 only

Answer: F3F4 only

With dimensions 2x25, 25x3, 3x16, 16x1, 1x1000, the optimal parenthesization is ((F1(F2(F3F4)))F5) with 2173 scalar multiplications. The only directly multiplied adjacent pair is F3F4, so option 2 is correct; the stored answer (F1F2 and F3F4) is wrong.

⚔️ Practice GATE Technical free + battle 1v1 →