Exams › GATE › Technical › COMPUTER – CS
45 questions with worked solutions.
Answer: G2 = (V,E2) where E2 = {(u,v) | (v,u) ∈ E}
G2 represents the transpose of the original graph G, where the direction of all edges is reversed. This operation preserves the strongly connected components, as the reachability between vertices remains intact in both directions.
Answer: On execution, the value printed is 5 more than the integer value entered.
The program correctly reads an integer value into the variable 'i' using a pointer, and then it prints the value of 'i' increased by 5, which means the output is indeed 5 more than the integer value entered by the user.
Answer: Θ(n²)
When a graph is represented as an adjacency matrix, checking for the existence of edges requires examining each entry in the n x n matrix. This results in a time complexity of Θ(n²) for Depth First Search, as every vertex and its potential connections must be considered.
Answer: t1 > t2
For [1 2 3 4 5] (sorted, first-element pivot) comparisons are 4+3+2+1=10. For [4 1 5 3 2], pivot 4 makes 4 comparisons, then [1 3 2] makes 2+1=3 and [5] makes 0, total 7. So t1=10 > t2=7, i.e. t1 > t2.
Q5. Which one of the following is TRUE ?
Answer: The language L = {w | w has 3k + 1 b's for some k ∈ N with Σ = {a, b}} is regular.
This language can be recognized by a finite automaton because it only requires counting the number of 'b's modulo 3, which is a finite condition. Regular languages can be defined by such finite counting, making this language regular.
Answer: 1-d, 2-a, 3-b, 4-c
The Waterfall model is characterized by its rigid structure, dividing the project into distinct stages, hence option 1-d. The Evolutionary model allows for incremental development of specifications, matching option 2-a. Component-based software engineering often involves trade-offs and compromises in requirements, aligning with option 3-b. Lastly, the Spiral development model incorporates risk assessment as a core element, corresponding to option 4-c.
Answer: 3
Starting at 100 with SSTF, the service order by nearest-seek is 100, then 105, then 110, then 90 (distance 20, closer than 135 at 25). Thus cylinder 90 is the 4th serviced, i.e. after servicing 3 requests, so the answer is 3.
Answer: {E, F, H}
The correct option {E, F, H} is a key for relation R because it can determine all other attributes in the relation through the given functional dependencies. Specifically, {E, F} can derive {G, I, J}, and adding {H} allows us to derive {K, L}, which in turn can derive {M} and {N}, thus covering all attributes.
Answer: Both S1 and S2 are FALSE.
S1 is false because while a foreign key can enforce referential integrity, it cannot always be replaced by a check constraint, which has different limitations. S2 is also false because the primary key defined on column 'd' does not include 'a' or 'b', which are necessary for proper referencing to the primary key of table R.
Answer: S1 and S3 are true, but S2 is false.
Link state protocols require more computational resources because they maintain a complete view of the network topology, leading to higher overhead compared to distance vector protocols, which only share information with neighbors. Additionally, link state protocols can quickly adapt to changes in the network, resulting in faster convergence after topology changes. However, distance vector protocols can indeed avoid persistent loops with techniques like split horizon, which is not a limitation of link state protocols.
Answer: Q and S only
SHA-1 and MD5 are cryptographic hash functions specifically designed to produce message digests, which are used to ensure data integrity. RSA and DES, on the other hand, are encryption algorithms and do not generate message digests.
Answer: 4,2,1,3
The correct order begins with the web browser resolving the domain name through DNS, which is necessary to find the server's IP address. Next, it establishes a TCP connection to ensure reliable communication. After the connection is established, the browser sends an HTTP request for the webpage, and finally, the server responds by sending the requested webpage back to the browser.
Answer: r2(x); w2(x); r3(x); r1(x); w1(x)
The correct option is conflict serializable because it can be transformed into a serial schedule without violating the order of conflicting operations. In this case, the writes and reads are arranged such that the dependencies between transactions do not create cycles, allowing for a consistent execution order.
Answer: Both L and L̄ are r.e. but not recursive.
Option C is not viable because if both L and its complement L are recursively enumerable but not recursive, it would imply that neither can be decided, leading to a contradiction with the properties of recursive languages.
Answer: (A)
If a polynomial time algorithm exists for the largest clique problem, which is NP-complete, it implies that all problems in NP can also be solved in polynomial time, thus making P equal to NP. This situation is accurately represented in option (A), where NP-complete problems are a subset of P.
Answer: 3, 0, and 1
The maximum chain length is 3 because the keys 5, 15, and 33 all hash to the same slot, creating the longest chain. The minimum chain length is 0 since some slots remain empty after all insertions. The average chain length is 1, calculated by dividing the total number of keys by the number of non-empty slots.
Answer: maximum possible sum of elements in any sub-array of array E.
The function calculates the maximum sum of all possible contiguous sub-arrays by iterating through each possible sub-array and comparing their sums to find the highest one, which is stored in Y.
Answer: One-sixth of the product of the 3 consecutive integers.
The correct option is right because the nested loops iterate in such a way that the total number of multiplications corresponds to the combination of choosing 3 distinct integers from a set of n, which mathematically is represented as n(n-1)(n-2)/6, equating to one-sixth of the product of three consecutive integers.
Answer: 1/N
The miss ratio is determined by the proportion of unique accesses to the total number of accesses. Since there are N unique block addresses and each access is unique, the miss ratio simplifies to 1/N, indicating that each access results in a cache miss until the cache can accommodate the accessed blocks.
Answer: (3, 3, 3, 1, 0, 0)
The 6-tuple (3, 3, 3, 1, 0, 0) is not graphic because the sum of the degrees (10) is odd, which violates the Handshaking Lemma that states the sum of the degrees of a graph must be even, as each edge contributes two to the total degree count.
Answer: (~(p ↔ q) ∧ r) ∨ (p ∧ q ∧ ~r)
The correct option is true because it captures the scenario where exactly two of the variables are true: it allows for the case where p and q are true while r is false, and also the case where p and r are true while q is false, ensuring that only two variables are true at any time.
Answer: Q̅ S̅ + Q S
The correct option, Q̅ S̅ + Q S, represents a simplified form of the function F by combining the relevant minterms while utilizing the 'do not care' conditions to eliminate unnecessary terms, thus achieving minimal representation.
Answer: Multiplexor
The function described selects between two inputs, a and b, based on the value of x, which is characteristic of a multiplexor. A multiplexor routes one of its multiple inputs to the output depending on the control signal, making it the most suitable choice for this logic function.
Answer: P3
Peak clock period is set by the slowest stage: P1=2ns, P2=1.5ns, P3=1ns, P4=1.1ns. P3 has the smallest maximum stage latency (1ns), giving the highest peak clock frequency (1 GHz).
Answer: O(n²)
Choosing the central element as the pivot in quicksort can lead to unbalanced partitions, especially if the array is already sorted or nearly sorted, resulting in a worst-case scenario where the algorithm behaves like selection sort, thus having a time complexity of O(n²).
Answer: 2^Σ* is uncountable and Σ* is countable
The set Σ* consists of all finite strings over a finite alphabet Σ, making it countable since it can be listed. However, the power set 2^Σ*, which includes all possible subsets of Σ*, is uncountable, as it has a greater cardinality than Σ* itself.
Q27. One of the purposes of using intermediate code in compilers is to
Answer: increase the chances of reusing the machine-independent code optimizer in other compilers.
Using intermediate code allows for a separation between the front-end and back-end of the compiler, enabling the machine-independent code optimizer to be reused across different compilers, thus enhancing efficiency and reducing development time.
Answer: 1 and 3 only
Static allocation of data areas does indeed hinder recursion because it limits the ability to create new activation records for each recursive call. Additionally, dynamic allocation of activation records is crucial for recursion, as it allows each call to maintain its own state without overwriting previous calls.
Q29. In the context of modular software design, which one of the following combinations is desirable?
Answer: High cohesion and low coupling
High cohesion within a module means that its components are closely related and work together effectively, while low coupling between modules indicates that they are independent and can function without relying heavily on each other. This combination enhances maintainability, scalability, and reusability in software design.
Answer: πA1(σ(F1∧F2)(r))
The correct option is optimized because it first applies the selection of both conditions F1 and F2 together, which reduces the dataset before projecting only the attributes in A1. This minimizes the amount of data processed in the projection step, making the operation more efficient.
Q31. A prime attribute of a relation scheme R is an attribute that appears
Answer: in some candidate key of R.
A prime attribute is defined as an attribute that is part of at least one candidate key, which means it plays a crucial role in uniquely identifying tuples within the relation.
Q32. In the following pairs of OSI protocol layer/sub-layer and its functionality, the INCORRECT pair is
Answer: Data Link Layer and Bit synchronization
The Data Link Layer primarily focuses on node-to-node data transfer and error detection, while bit synchronization is more closely associated with the Physical Layer, which handles the transmission of raw bit streams over a physical medium.
Answer: 0111110101
The correct option is right because in bit-stuffing, a '0' is inserted after every sequence of five consecutive '1's to prevent confusion with the delimiter. The output string 01111100101 contains a stuffed '0' after the five '1's, indicating that the original input string must have been 0111110101.
Answer: (i), (ii) and (iii)
All three fields can change during the transmission of an IP datagram. The Time to Live (TTL) decreases as the packet traverses routers, the Checksum is recalculated at each hop to ensure data integrity, and the Fragment Offset may change if the datagram is fragmented during transmission.
Answer: 1
131.23 in binary is 10000011.00010111. The /15 entry 131.22.0.0 masks to 10000011.0001011x, and 131.23 (...0001011 1) matches it, so it qualifies; the /12 entry also matches but /15 is longer. Among the four entries only /12 and /15 match, and longest-prefix routing chooses /15, giving output interface 1 (index 3).
Answer: MF bit: 0; Datagram Length: 1444; Offset: 370
Payload = 4404 - 20 = 4384 bytes, split into 1480 + 1480 + 1424. The third fragment carries 1424 data bytes, total length 1424 + 20 = 1444, byte offset 2960 so fragment offset 2960/8 = 370, and MF = 0 since it is last. That is option (A), not the stored option.
Answer: all of his/her dependents.
The query subtracts the empIds of employees who have at least one dependent younger than or equal to them from the set of all empIds, resulting in only those employees whose age is greater than that of all their dependents.
Answer: solvable in polynomial time by reduction to directed graph reachability.
The correct option is right because 2CNFSAT can be transformed into a directed graph problem where the satisfiability of the formula corresponds to finding a path in the graph, allowing it to be solved efficiently in polynomial time.
Answer: (97 × 97 × 97)/100³
The correct option calculates the probability that each of the first three slots remains unfilled after three insertions, assuming uniform hashing. Since there are 100 slots and 97 of them are available for each insertion, the probability for each of the three slots to remain unfilled is (97/100), leading to (97 × 97 × 97)/100³.
Answer: number of leaf nodes in the tree.
The function counts leaf nodes by checking if a node has no children (leftMostChild is NULL) and returns 1 for each leaf. It recursively processes the leftmost child and right sibling, ensuring all leaf nodes are counted.
Answer: It is an implementation of binary search.
The function uses a divide-and-conquer approach to efficiently search for the element x within the sorted array listA, which is characteristic of binary search. It repeatedly narrows down the search range by comparing x with the middle element until it either finds x or determines that it is not present.
Answer: Only Q and R are true
Statement Q is true because if f(f(i)) = i, then there must be at least one value i for which f(i) equals i, indicating a fixed point. Statement R is also true since the function must map every element in the domain to an element in the codomain, ensuring that it is onto. However, statement P is false because it is possible for f(i) to be different from i while still satisfying f(f(i)) = i.
Q43. If G is a forest with n vertices and k connected components, how many edges does G have?
Answer: n − k
In a forest, which is a collection of trees, the number of edges is always one less than the number of vertices in each connected component. Therefore, for k components, the total number of edges is n (the total number of vertices) minus k (the number of components), resulting in n - k.
Q44. The CORRECT formula for the sentence, "not all rainy days are cold" is
Answer: ∃d (Rainy(d) ∧ ~Cold(d))
The correct option indicates that there exists at least one day that is rainy and not cold, which accurately reflects the meaning of the original sentence that not all rainy days are cold.
Answer: Names of all the employees with all their customers having a 'GOOD' rating.
The query checks for employees who do not have any customers with a rating other than 'GOOD'. Therefore, it returns the names of employees whose customers all have a 'GOOD' rating.