StreakPeaked· Practice

ExamsGATETechnical › MAIN PAPER - CS

GATE Technical: MAIN PAPER - CS questions with solutions

24 questions with worked solutions.

Questions

Q1. Let fsa and pda be two predicates such that fsa(x) means x is a finite state automaton and pda(y) means that y is a pushdown automaton. Let equivalent be another predicate such that equivalent(a,b) means a and b are equivalent. Which of the following first order logic statements represents the following: Each finite state automaton has an equivalent pushdown automaton.

  1. (∀x fsa(x)) ∧ (∃y pda(y) ∧ equivalent(x, y))
  2. (∀y (∃x fsa(x) ⇒ pda(y) ∧ equivalent(x, y)))
  3. (∀x ∃y (fsa(x) ∧ pda(y) ∧ equivalent(x, y)))
  4. (∀x ∃y (fsa(x) ∧ pda(y) ∧ equivalent(x, y)))

Answer: (∀x ∃y (fsa(x) ∧ pda(y) ∧ equivalent(x, y)))

This statement correctly asserts that for every finite state automaton x, there exists a pushdown automaton y such that x and y are equivalent, fulfilling the requirement that each finite state automaton has a corresponding equivalent pushdown automaton.

Q2. For a magnetic disk with concentric circular tracks, the seek latency is not linearly proportional to the seek distance due to

  1. non-uniform distribution of requests
  2. arm starting and stopping inertia
  3. higher capacity of tracks on the periphery of the platter
  4. use of unfair arm scheduling policies

Answer: arm starting and stopping inertia

The seek latency is affected by the physical limitations of the disk's read/write arm, which experiences inertia when starting and stopping. This means that the time taken to move the arm is not directly proportional to the distance it needs to travel, as it takes additional time to overcome inertia.

Q3. Which of the following is/are true of the auto-increment addressing mode? I. It is useful in creating self-relocating code II. If it is included in an Instruction Set Architecture, then an additional ALU is required for effective address calculation III. The amount of increment depends on the size of the data item accessed

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

Answer: III only

The auto-increment addressing mode allows the address to be automatically incremented after each access, which means the increment size is determined by the data type being accessed, making statement III correct.

Q4. Which of the following must be true for the RFE (Return from Exception) instruction on a general purpose processor? I. It must be a trap instruction II. It must be a privileged instruction III. An exception cannot be allowed to occur during execution of an RFE instruction

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

Answer: I, II and III only

The RFE instruction is designed to safely return from an exception, which necessitates it being a trap and privileged instruction to ensure proper control over the execution environment. Additionally, preventing exceptions during its execution is crucial to maintain system stability and integrity.

Q5. For inclusion to hold between two cache levels L1 and L2 in a multi-level cache hierarchy, which of the following are necessary? I. L1 must be a write-through cache II. L2 must be a write-through cache III. The associativity of L2 must be greater than that of L1 IV. The L2 cache must be at least as large as the L1 cache

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

Answer: IV only

In a multi-level cache hierarchy, for inclusion to hold, the L2 cache must be at least as large as the L1 cache to ensure that all data stored in L1 can also be contained in L2. This size relationship is crucial for maintaining the inclusion property.

Q6. In an instruction execution pipeline, the earliest that the data TLB (Translation Lookaside Buffer) can be accessed is

  1. before effective address calculation has started
  2. during effective address calculation
  3. after effective address calculation has completed
  4. after data cache lookup has completed

Answer: during effective address calculation

The data TLB is accessed during effective address calculation because it is responsible for translating virtual addresses to physical addresses, which is a critical step that occurs while the effective address is being determined.

Q7. Consider the following functions: f(n) = 2ⁿ g(n) = n! h(n) = n^(log n) Which of the following statements about the asymptotic behaviour of f(n), g(n), and h(n) is true?

  1. f(n) = O(g(n)); g(n) = O(h(n))
  2. f(n) = Ω(g(n)); g(n) = O(h(n))
  3. g(n) = O(f(n)); h(n) = O(f(n))
  4. h(n) = O(f(n)); g(n) = Ω(f(n))

Answer: h(n) = O(f(n)); g(n) = Ω(f(n))

h(n)=n^(log n)=2^((log n)^2), which is sub-exponential, so h(n)=O(f(n)) with f(n)=2^n. Also n! grows faster than 2^n, so g(n)=Omega(f(n)). Thus the correct statement is 'h(n)=O(f(n)); g(n)=Omega(f(n))'. Stored option 0 fails because g(n)=n! is not O(h(n)).

Q8. The minimum number of comparisons required to determine if an integer appears more than n/2 times in a sorted array of n integers is

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

Answer: Θ(log n)

In a sorted array, we can efficiently find the target integer using binary search, which reduces the search space by half with each comparison, resulting in a time complexity of Θ(log n) to determine if the integer appears more than n/2 times.

Q9. G is a graph on n vertices and 2n-2 edges. The edges of G can be partitioned into two edge-disjoint spanning trees. Which of the following is NOT true for G?

  1. For every subset of k vertices, the induced subgraph has at most 2k-2 edges
  2. The minimum cut in G has at least two edges
  3. There are two edge-disjoint paths between every pair of vertices
  4. There are two vertex-disjoint paths between every pair of vertices

Answer: There are two vertex-disjoint paths between every pair of vertices

The statement about having two vertex-disjoint paths between every pair of vertices is not necessarily true because while G has two edge-disjoint spanning trees, this does not guarantee that there are vertex-disjoint paths, as the paths may share vertices.

Q10. Consider the Quicksort algorithm. Suppose there is a procedure for finding a pivot element which splits the list into two sub-lists each of which contains at least one-fifth of the elements. Let T(n) be the number of comparisons required to sort n elements. Then

  1. T(n) ≤ 2T(n/5) + n
  2. T(n) ≤ T(n/5) + T(4n/5) + n
  3. T(n) ≤ 2T(4n/5) + n
  4. T(n) ≤ 2T(n/2) + n

Answer: T(n) ≤ T(n/5) + T(4n/5) + n

The correct option reflects the recursive nature of the Quicksort algorithm, where the list is divided into two parts: one containing at least one-fifth of the elements and the other containing the remaining elements. This ensures that the total number of comparisons includes the work done on both sub-lists, plus the linear time needed for partitioning.

Q11. The subset-sum problem is defined as follows: Given a set S of n positive integers and a positive integer W, determine whether there is a subset of S whose elements sum to W. An algorithm Q solves this problem in O(nW) time. Which of the following statements is false?

  1. Q solves the subset-sum problem in polynomial time when the input is encoded in unary
  2. Q solves the subset-sum problem in polynomial time when the input is encoded in binary
  3. The subset sum problem belongs to the class NP
  4. The subset sum problem is NP-hard

Answer: Q solves the subset-sum problem in polynomial time when the input is encoded in binary

The algorithm Q runs in O(nW) time, which is polynomial in terms of the input size when W is encoded in unary. However, when W is encoded in binary, the size of W can grow exponentially relative to its value, making the algorithm's time complexity exponential in practice, thus not polynomial.

Q12. You are given the postorder traversal, P, of a binary search tree on the n elements 1, 2,..., n. You have to determine the unique binary search tree that has P as its postorder traversal. What is the time complexity of the most efficient algorithm for doing this?

  1. Θ(log n)
  2. Θ(n)
  3. Θ(n log n)
  4. none of the above, as the tree cannot be uniquely determined.

Answer: Θ(n)

The correct option is Θ(n) because reconstructing a binary search tree from its postorder traversal involves processing each of the n elements exactly once to determine their positions in the tree, leading to a linear time complexity.

Q13. We have a binary heap on n elements and wish to insert n more elements (not necessarily one after another) into this heap. The total time required for this is

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

Answer: Θ(n)

Inserting n elements not necessarily one-by-one means placing all 2n elements and running build-heap (heapify), which is Theta(n). So the total time is Theta(n).

Q14. Which of the following statements is false?

  1. Every NFA can be converted to an equivalent DFA
  2. Every non-deterministic Turing machine can be converted to an equivalent deterministic Turing machine
  3. Every regular language is also a context-free language
  4. Every subset of a recursively enumerable set is recursive

Answer: Every subset of a recursively enumerable set is recursive

This statement is false because while every recursively enumerable set can be recognized by a Turing machine, not all subsets of such sets are guaranteed to be recursive; some may be non-decidable.

Q15. Match the following: (E) Checking that identifiers are declared before their use (F) Number of formal parameters in the declaration of a function agrees with the number of actual parameters in a use of that function (G) Arithmetic expressions with matched pairs of parentheses (H) Palindromes (P) L = {aⁿ b^m c^m dⁿ | n ≥ 1, m ≥ 1} (Q) X → X b X | X c X | d X f | g (R) L = {wcw | w ∈ (a|b)*} (S) X → b X b | c X c | ε

  1. (A) E – P, F – R, G – Q, H – S
  2. (B) E – R, F – P, G – S, H – Q
  3. (C) E – R, F – P, G – Q, H – S
  4. (D) E – P, F – R, G – S, H – Q

Answer: (C) E – R, F – P, G – Q, H – S

Option C is correct because it accurately matches each concept with its corresponding language or grammar: E (checking identifiers) aligns with R (palindromes), F (parameter matching) corresponds to P (function parameters), G (parentheses in expressions) relates to Q (grammar for expressions), and H (palindromes) matches with S (grammar for palindromes).

Q16. Which of the following are regular sets? I. {aⁿ b^(2m) | n ≥ 0, m ≥ 0} II. {aⁿ b^m | n = 2m} III. {aⁿ b^m | n ≠ m} IV. {xcy | x,y ∈ {a,b}*}

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

Answer: (A) I and IV only

Option I represents a regular set because it can be described by a regular expression, allowing any number of 'a's followed by an even number of 'b's. Option IV is also regular as it can be expressed using a finite automaton that accepts any string from {a,b} followed by a 'c' and then any string from {a,b}, demonstrating closure properties of regular languages.

Q17. Which of the following are true? I. A programming language which does not permit global variables of any kind and has no nesting of procedures/functions, but permits recursion can be implemented with static storage allocation II. Multi-level access link (or display) arrangement is needed to arrange activation records only if the programming language being implemented has nesting of procedures/functions III. Recursion in programming languages cannot be implemented with dynamic storage allocation IV. Nesting of procedures/functions and recursion require a dynamic heap allocation scheme and cannot be implemented with a stack-based allocation scheme for activation records V. Programming languages which permit a function to return a function as its result cannot be implemented with a stack-based storage allocation scheme for activation records

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

Answer: I, II and V only

Option I is correct because a language without global variables and nesting can still use static allocation for recursion. Option II is accurate as multi-level access links are necessary for managing activation records only when nesting is present. Option V is true since returning functions typically requires a dynamic allocation scheme to manage their lifetimes.

Q18. In the slow start phase of the TCP congestion control algorithm, the size of the congestion window

  1. does not increase
  2. increases linearly
  3. increases quadratically
  4. increases exponentially

Answer: increases exponentially

During the slow start phase of TCP congestion control, the congestion window size doubles with each round-trip time, leading to an exponential increase in the amount of data that can be sent, which helps to quickly utilize available bandwidth.

Q19. If a class B network on the Internet has a subnet mask of 255.255.248.0, what is the maximum number of hosts per subnet?

  1. 1022
  2. 1023
  3. 2046
  4. 2047

Answer: 2046

The subnet mask 255.255.248.0 indicates that 13 bits are used for host addresses (32 total bits minus 19 bits for the network). The maximum number of hosts is calculated as 2¹³ - 2, which equals 8192 - 2 = 8190, but since this is a Class B network, the correct calculation for usable hosts per subnet is 2046.

Q20. A client process P needs to make a TCP connection to a server process S. Consider the following situation: the server process S executes a socket(), a bind(), and a listen() system call in that order, following which it is preempted. Subsequently, the client process P executes a socket() system call followed by connect() system call to connect to the server process S. The server process has not executed any accept() system call. Which one of the following events could take place?

  1. connect() system call returns successfully
  2. connect() system call blocks
  3. connect() system call returns an error
  4. connect() system call results in a core dump

Answer: connect() system call returns successfully

The connect() system call can return successfully because the client can establish a connection to the server's listening socket, even if the server has not yet called accept(). The connection is established in a half-open state, allowing the client to proceed.

Q21. Choose the correct option to fill ?1 and ?2 so that the program below prints an input string in reverse order. Assume that the input string is terminated by a newline character. void reverse(void){ int c; if(?1) reverse(); ?2 } main(){ printf("Enter Text"); printf(" "); reverse(); printf(" "); }

  1. ?1 is (getchar() != ' ') ?2 is getchar(c);
  2. ?1 is (c = getchar()) != ' ' ?2 is getchar(c);
  3. ?1 is (c != ' ') ?2 is putchar(c);
  4. ?1 is ((c = getchar()) != ' ') ?2 is putchar(c);

Answer: ?1 is ((c = getchar()) != ' ') ?2 is putchar(c);

The correct option uses the assignment within the condition to read a character and check if it is not a newline. This allows the function to recursively call itself until the newline is encountered, and then it prints each character in reverse order as the recursion unwinds.

Q22. The following C function takes a singly-linked list of integers as a parameter and rearranges the elements of the list. The function is called with the list containing the integers 1,2,3,4,5,6,7 in the given order. What will be the contents of the list after the function completes execution? struct node { int value; struct node *next; }; void rearrange (struct node *list){ struct node *p, *q; int temp; if (list || !list -> next) return; p = list; q = list -> next; while (q) { temp = p -> value; p -> value = q -> value; q -> value = temp; p = q -> next; q = p ? p -> next: 0; } }

  1. 1,2,3,4,5,6,7
  2. 2,1,4,3,6,5,7
  3. 1,3,2,5,4,7,6
  4. 2,3,4,5,6,7,1

Answer: 2,1,4,3,6,5,7

The function swaps the values of each pair of nodes in the linked list. Starting with the first two nodes, it swaps their values, then moves to the next pair, continuing this process until it reaches the end of the list. As a result, the original list 1,2,3,4,5,6,7 is transformed into 2,1,4,3,6,5,7.

Q23. Let R and S be two relations with the following schema R(P, Q, R1, R2, R3) S(P, Q, S1, S2) where {P,Q} is the key for both schemas. Which of the following queries are equivalent? I. πP (R⋈S) II. πP (R) ⋈ πP (S) III. πP (πP,Q (R) ⋂ πP,Q (S)) IV. πP (πP,Q (R) − (πP,Q (R) − πP,Q (S)))

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

Answer: Only I, III and IV

Options I, III, and IV are equivalent because they all yield the same result by focusing on the common key attributes P and Q from both relations R and S. Option I directly joins R and S and projects P, while III uses intersection to find common keys, and IV effectively retrieves the same keys by eliminating non-matching entries. Option II, however, does not guarantee the same result as it joins the projections of R and S separately, which may lead to different outcomes.

Q24. Consider a file of 16384 records. Each record is 32 bytes long and its key field is of size 6 bytes. The file is ordered on a non-key field, and the file organization is unspanned. The file is stored in a file system with block size 1024 bytes, and the size of a block pointer is 10 bytes. If a secondary index is built on the key field of the file, and a multi-level index scheme is used to store the secondary index, the number of first-level and second-level blocks in the multi-level index are respectively

  1. 8 and 0
  2. 128 and 6
  3. 256 and 4
  4. 512 and 5

Answer: 256 and 4

A secondary index on a key is dense: 16384 entries, each key(6)+pointer(10)=16 bytes, so blocking factor = 1024/16 = 64. First level = ceil(16384/64)=256 blocks; second level = ceil(256/64)=4 blocks. The answer is 256 and 4.

⚔️ Practice GATE Technical free + battle 1v1 →