An element of A∪B belongs to exactly one of three regions: A only, B only, or both sets. These are precisely A−B, B−A and A∩B. Their union therefore recovers A∪B. Conversely, every element in any of those three regions belongs to A or B, proving the reverse inclusion. The intersection alone omits the two exclusive regions, while the symmetric difference omits the common region. No assumption that A and B are disjoint is needed.
Count Hasse-diagram edges for {2,3,6,12,24} ordered by divisibility.
Your answer
Answer & solution
Answer: B: 4 (no official key was published)
A Hasse edge joins comparable elements only when no listed element lies strictly between them. The covers are 2<6, 3<6, 6<12 and 12<24. For example, 2<12 is not an edge because 6 is between them; similarly 6<24 is omitted because of 12. The elements 2 and 3 are incomparable. Thus there are four edges. Counting every divisibility relation would count transitive relations that the Hasse diagram deliberately suppresses.
Exactly 97 functions exist from X to Y. Determine the finite cardinalities of X and Y.
Your answer
Answer & solution
Answer: A: |X|=1, |Y|=97 (no official key was published)
If |X|=m and |Y|=n, each of the m arguments independently chooses one of n images, yielding nm functions. Here nm=97. Since 97 is prime, it cannot be an integer power with exponent at least two and base greater than one. Hence m=1 and n=97. An empty domain gives exactly one function, and an empty codomain cannot give 97 functions. This also explains why reversing the two cardinalities would give only one function.
Which claim is false: rationals under addition, integers under addition, rationals under multiplication, or nonzero reals under multiplication form an abelian group?
Your answer
Answer & solution
Answer: C (no official key was published)
A group requires an identity and an inverse for every element. Under rational multiplication, zero has no inverse because 0·q=0 for every rational q, never the multiplicative identity 1. Thus the set of all rationals is not a multiplication group. The additive inverses of rationals and integers remain in their respective sets. Every nonzero real has a nonzero reciprocal. All the indicated operations commute, so the other three groups are abelian.
Two fair independent dice are thrown. Find the probability that at least one shows 6.
Your answer
Answer & solution
Answer: D: 11/36 (no official key was published)
Use the complement event that neither die shows 6. Each die avoids 6 with probability 5/6, so independence gives probability 25/36 for neither. Subtracting from one gives 11/36. Equivalently, there are six outcomes with the first die equal to 6 and six with the second equal to 6, but (6,6) was counted twice: 6+6−1=11 of 36 equally likely outcomes. Simply adding 1/6+1/6 would fail to remove this overlap.
Choose a finite-difference approximation for f″(x) using f(x−h), f(x), f(x+h).
Your answer
Answer & solution
Answer: D: [f(x+h)−2f(x)+f(x−h)]/h² (no official key was published)
Taylor expansion gives f(x±h)=f(x)±hf′(x)+h²f″(x)/2±h³f‴(x)/6+O(h⁴). Add the two expansions: the odd derivative terms cancel, leaving 2f(x)+h²f″(x)+O(h⁴). Subtract 2f(x) and divide by h² to obtain f″(x)≈[f(x+h)−2f(x)+f(x−h)]/h², with error O(h²) for a sufficiently smooth function. The denominator must be h², not h, because the first surviving derivative term is quadratic in the spacing.
Which linear-system claim is false, including the claim that m=n and b≠0 ensure a unique solution of Ax=b?
Your answer
Answer & solution
Answer: C (no official key was published)
A square coefficient matrix does not automatically have full rank. For example A is the 2×2 zero matrix and b=(1,0)ᵀ: the system has no solution despite m=n and b≠0. In general consistency requires rank(A)=rank([A|b]), and uniqueness additionally requires rank(A)=n. A homogeneous system with fewer equations than unknowns has a nontrivial nullspace over the reals; a square full-rank homogeneous system has only the zero solution. These rank facts distinguish the other standard statements from C.
Compare (i)(00)*(ε+0), (ii)(00)*, (iii)0*, and (iv)0(00)*. Which expressions are equivalent?
Your answer
Answer & solution
Answer: C: (i) and (iii) (no official key was published)
Expression (00)* produces every even number of zeros, including zero. Appending either ε or one zero therefore produces every nonnegative length, exactly 0*. Expression (ii) alone excludes odd lengths; expression (iv) produces only odd lengths and excludes ε. Thus only (i) and (iii) describe the same language. Checking both ε and a one-symbol word already distinguishes the parity-restricted alternatives from the full unary language.
Select the false undecidability claim among TM halting, CFG ambiguity, CFG equivalence and regular-grammar equivalence.
Your answer
Answer & solution
Answer: D (no official key was published)
Regular grammars can be converted to finite automata. Determinize and complete the automata, form their product accepting the symmetric difference, and test whether any accepting product state is reachable. No reachable accepting state means the languages are equal. This is a terminating decision procedure, so saying regular-grammar equivalence is undecidable is false. TM halting, general CFG ambiguity and general CFG equivalence are undecidable problems. The finite-state restriction is what makes the fourth case different.
Which language over {a,b} is regular: (A) all words with equally many a and b symbols; (B) {a^n b^n:n≥1}; (C) all words with more a symbols than b symbols; (D) {a^m b^n:m≥1,n≥1}?
Your answer
Answer & solution
Answer: D (no official key was published)
The displayed language has no equality or inequality coupling the two block lengths. It is described by the regular expression aa*bb*: read at least one a, then at least one b. A finite automaton only needs to remember which block it is reading and reject a later a. In contrast, requiring equal block lengths or comparing their unbounded counts generally needs more than finite memory. Thus the unrestricted positive two-block choice D is regular; the independent quantifiers m,n are crucial.
Which asymptotic claim is false: (A) 100n log n=O(n log n/100); (B) sqrt(log n)=O(log log n); (C) for fixed 0<x<y, n^x=O(n^y); (D) 2^n is not O(n^k) for fixed k?
Your answer
Answer & solution
Answer: B (no official key was published)
Put t=log n. Then sqrt(log n)/(log log n)=sqrt(t)/log t tends to infinity, so no constant bounds the numerator by a multiple of the denominator eventually. Hence B is false. Multiplying n log n by fixed nonzero constants does not change its big-O class. For fixed x<y, nx/ny=nx−y tends to zero. Finally 2n eventually dominates every fixed-degree polynomial nk: the logarithm of their ratio is n log 2−k log n, which tends to infinity. Thus D is true, not the false statement sought.
Assess FIFO for stacks, broad linked-list efficiency, circular queues reusing array slots, and LIFO for queues.
Your answer
Answer & solution
Answer: A under the intended linked-list operation model: statements ii and iii (no official key was published)
A stack is LIFO, not FIFO; a queue is FIFO, not LIFO. In a circular array queue, the rear wraps around to locations freed by dequeues, so statement iii is correct. Linked lists permit constant-time insertion or deletion when the relevant node or predecessor is already known, avoiding array shifts; this motivates statement ii and the intended pair ii,iii. However, the assertion that linked lists are more efficient for almost all basic operations is not a mathematical universal: indexed access and cache-local traversal often favor arrays, and locating a node can require linear time. The operation and representation model must be specified.
Why can separate chaining be preferable to open addressing: better worst-case search, less storage, easier deletion, or another claim?
Your answer
Answer & solution
Answer: C (no official key was published)
In chaining, keys in a bucket form a separate collection. Once the key and necessary predecessor are found, deletion simply unlinks it without changing the search path for other keys. In open addressing, clearing a slot outright may incorrectly terminate a later probe, so deletion needs tombstones or careful reorganization. Both approaches can have linear worst-case search, and chaining normally incurs pointer or container overhead. The reliable advantage among these claims is therefore easier deletion, C, rather than a universal space or worst-case-time improvement.
In the pictured AVL tree, a has children b,e; b has c,d; c has g; e has f. How many nodes become unbalanced when a new child is attached below g, before rebalancing?
Your answer
Answer & solution
Answer: B: 3 (no official key was published)
The insertion increases the height of the subtree rooted at g by one. That increase propagates through c, b and a. At c, its already taller g side becomes two levels taller than its empty opposite side. The same extra level makes b and then a have height difference two. Node g itself has only one new child, so its balance magnitude is one; e and its descendants are unchanged. Thus c,b,a are the three unbalanced nodes before rotations. Counting after AVL repair would answer a different question.
For root a with left subtree b(c(g),d) and right subtree e(f), find the postorder traversal.
Your answer
Answer & solution
Answer: C: g,c,d,b,f,e,a (no official key was published)
Postorder visits the complete left subtree, then the complete right subtree, then the root. Within b, visit g before its parent c, then d, then b: g,c,d,b. Within e, visit f before e: f,e. Concatenate those two lists and finally append a, yielding g,c,d,b,f,e,a. The exact left-versus-right placement of a sole child does not affect postorder. Visiting a before its subtrees would be preorder, not the requested traversal.
Relative addressing is most relevant to writing which application: (A) coroutines, (B) position-independent code, (C) shareable code, or (D) interrupt handlers?
Your answer
Answer & solution
Answer: B: position-independent code (no official key was published)
A PC-relative instruction stores an offset rather than an absolute target address. Its effective target is PC plus that offset. If both instruction and target move by the same relocation amount, the difference between them is unchanged, so the stored offset still works. Absolute addressing instead embeds a location that generally needs relocation. This is why relative addressing is associated with position-independent control transfers, subject to the architecture’s offset range and exact PC convention.
Assign object-code generation, adding literals to the literal table, assembly listing generation, and establishing local-symbol addresses to pass 1 or 2.
Your answer
Answer & solution
Answer: B: 2,1,2,1 (no official key was published)
Pass 1 scans source statements, advances the location counter, records labels and collects literals. It therefore establishes local-symbol addresses and enters literals before final machine-code emission. Pass 2 uses those tables to encode instructions, resolve forward uses and produce object code; the final listing can include that generated code. Hence the listed order is 2,1,2,1. If the word resolution refers specifically to substituting a symbol address at its use, that substitution occurs in pass 2; the conventional matching here means establishing the symbol-table address in pass 1.
A process-state diagram includes ready→running, running→ready, running→blocked and blocked→ready. What scheduler feature does the usual diagram indicate?
Your answer
Answer & solution
Answer: B: preemptive scheduling (no official key was published)
Dispatch moves a ready process into running. An I/O or resource wait moves it into blocked, and completion moves it back to ready. In the standard scheduling diagram, the extra running→ready edge represents the scheduler taking the CPU away, for example at time-slice expiry. That is preemption, giving B. A real system may also let a process voluntarily yield into ready; the unlabeled graph alone would then not prove involuntary preemption. The answer uses the conventional interpretation of this textbook state-transition diagram.
What distinguishes a critical section of a program?
Your answer
Answer & solution
Answer: C: access to shared resources (no official key was published)
A critical section is code that accesses shared state or a shared resource in a way requiring coordination with other concurrent executions. Uncontrolled overlap can violate an invariant, so a mutual-exclusion mechanism is typically needed. The definition does not require a semaphore specifically: locks, monitors, atomic operations or other protocols may enforce the required property. Nor is every short or computationally important block a critical section. The shared-resource access is the relevant characteristic, C.
Which listed device is naturally served by spooling?
Your answer
Answer & solution
Answer: A: line printer (no official key was published)
A printer consumes output serially and relatively slowly. Spooling first stores each job in a disk-backed queue, allowing producing processes to continue while a spooler feeds complete jobs to the device in order. This avoids intermixing different jobs and decouples application execution from printing speed. A line printer is therefore the standard example. Spooling is not merely a CPU cache or an arbitrary buffer: its key role here is queued management of an exclusive sequential output device.
A ROM directly implements multiplication of two unsigned 8-bit inputs. What organization is required?
Your answer
Answer & solution
Answer: D: 64K words ×16 bits (no official key was published)
The two input bytes together provide 16 address bits, so every possible operand pair requires one of 216=65,536 entries. The largest product is 255²=65,025, which needs 16 bits; therefore every stored result is a 16-bit word. The organization is 64K×16. A ROM with only 256 entries would distinguish just one operand, not all pairs, and an 8-bit output would lose the high byte of many products.
How many machine cycles does an ordinary 8085 RET instruction require?
Your answer
Answer & solution
Answer: C: 3 (no official key was published)
RET first fetches its opcode. It then reads the two bytes of the saved return address from the stack, requiring two memory-read machine cycles. Those bytes restore the program counter and the stack pointer advances by two. Thus the total is one opcode-fetch cycle plus two memory-read cycles, or three. Machine cycles are not individual clock T-states, so counting clock periods instead would confuse two different timing measures.
Which multiplier pattern gives frequent operations in Booth multiplication, including an alternating 1010… pattern?
Your answer
Answer & solution
Answer: A: alternating bits (no official key was published)
Booth recoding examines adjacent multiplier bits, with an appended low-order zero. Equal pairs 00 and 11 require no add/subtract; transitions 01 and 10 trigger addition or subtraction. An alternating pattern therefore triggers operations at almost every position. A long run of ones is cheaper because only its boundaries trigger work. Thus the alternating candidate A is worst among the listed patterns under the ordinary radix-2 Booth operation count, even though the number of shift steps remains fixed by word width.
Does a daisy chain provide uniform priorities, nonuniform priorities, only support slow devices, or require a separate processor interrupt pin for every device?
Your answer
Answer & solution
Answer: A: nonuniform priority (no official key was published)
An interrupt acknowledgment or grant propagates down the chain. The first requesting device encountered captures it and prevents later devices from using that grant. Priority therefore depends on physical position in the chain, so devices have nonuniform priority. This scheme is attractive partly because it can share processor interrupt infrastructure; it does not require one processor pin for every device. Nothing in the chaining principle restricts it exclusively to slow devices.
An 8-bit two’s-complement exponent and 24-bit sign-magnitude mantissa are shown. Choices for magnitude include 0.5 through 1−2^−23. What range is justified?
Your answer
Answer & solution
Answer: D for the normalized fractional mantissa; not the full floating value (no official key was published)
With one sign bit and 23 fraction bits, conventional fractional normalization puts a 1 in the first fraction position. The smallest magnitude of the mantissa is therefore 0.100…₂=1/2; the largest is 0.111…₂=1−2−23. This gives choice D for the mantissa. The literal wording asks about normalized numbers, however. Including the signed exponent e∈[−128,127] gives magnitudes from 2−129 to (1−2−23)2127, assuming all exponent patterns are available. No listed short interval describes that full range. The binary-point and reserved-exponent conventions are also not stated explicitly.
Answer: C: f⁻¹(u,v)=((u+v)/2,(u−v)/2) (no official key was published)
Set u=x+y and v=x−y. Adding the equations gives u+v=2x, while subtracting gives u−v=2y. Hence x=(u+v)/2 and y=(u−v)/2. Substitution back into the original map returns (u,v), verifying both coordinates rather than only guessing a similar expression. The factors of one half are essential: omitting them produces twice the desired input. The nonzero determinant −2 also confirms that this linear map is bijective.
On a collection of sets, let A R B iff A∩B=∅, and assume the relation is nonempty. Assess symmetry and transitivity.
Your answer
Answer & solution
Answer: B as the usual “symmetric, not necessarily transitive” reading; literal universality needs qualification (no official key was published)
Disjointness is symmetric because A∩B=B∩A. It is not generally transitive: take A=C={1}, B={2}. Then A R B and B R C hold, but A R C fails. This gives the intended B. Nevertheless the statement that every such nonempty relation is nontransitive is too strong for an arbitrary collection. On the collection {∅}, the relation contains only (∅,∅) and is transitive and reflexive. The assumption that R is nonempty does not exclude that example. Thus B describes the general failure of a transitivity law, not a property forced for every possible underlying collection.
Which formula is not a tautology: (A) ((x→y)∧x)→y; (B) ((¬x→y)∧(¬x→¬y))→x; (C) x→(x∨y); (D) (x∨y)↔(¬x→¬y)? GFG supplies these formulas; the alternate changes the second implication inside B to a conjunction, which also makes B a tautology.
Your answer
Answer & solution
Answer: D (no official key was published)
Replace implication p→q by ¬p∨q. Then ¬x→¬y is x∨¬y, which is not equivalent to x∨y: at x=false,y=true the left side is true and the right side false. Thus D is not a tautology. Choice A is modus ponens written as an implication, and C is the rule that x implies x∨y. These checks establish the distinction by truth values, not symbol resemblance.
Which group claim fails: permutations under composition, nonzero residues modulo prime p, strings under concatenation, or the nonempty-subset subgroup test ab⁻¹∈S?
Your answer
Answer & solution
Answer: C for a nonempty alphabet (no official key was published)
Finite strings have identity ε under concatenation, but a nonempty string w has no inverse. For any string v, length(wv)=length(w)+length(v)>0, so wv cannot equal ε. Thus strings form a monoid, not a group. Permutations have inverse bijections; every nonzero residue modulo prime p has a multiplicative inverse. The subgroup criterion ab⁻¹∈S is valid when S is nonempty, as explicitly printed in the clearer alternate. If an empty alphabet were allowed, its sole string ε would form the trivial group; the conventional alphabet here is nonempty.
Derive Newton–Raphson iteration to find c^(1/3), c>0.
Your answer
Answer & solution
Answer: C: x_next=(2x³+c)/(3x²) (no official key was published)
Apply Newton’s method to F(x)=x³−c, whose derivative is F′(x)=3x². Thus x_next=x−(x³−c)/(3x²)=(2x³+c)/(3x²). The iteration requires a nonzero current x to avoid division by zero. It uses c in the numerator, not its already-unknown cube root; substituting the root there would defeat the purpose of the iteration. A positive initial value is a standard choice for finding the positive root.
For R=[[cosθ,−sinθ],[sinθ,cosθ]] and D=diag(a,b), determine when RD=DR.
Your answer
Answer & solution
Answer: A: a=b or θ is an integer multiple of π (no official key was published)
The diagonal entries of both products are a cosθ and b cosθ. Their off-diagonal entries agree exactly when −b sinθ=−a sinθ and a sinθ=b sinθ. Both reduce to (a−b)sinθ=0. Therefore either the scale factors are equal, making D a scalar matrix, or sinθ=0, meaning θ=nπ. This proves necessity as well as sufficiency. General unequal anisotropic scaling does not commute with an arbitrary rotation.
A uniformly shuffled standard 52-card deck is considered. What is the probability its top and bottom cards are both aces?
Your answer
Answer & solution
Answer: C: (4/52)(3/51)=1/221 (no official key was published)
The top position contains an ace with probability 4/52. Conditional on that event, three aces remain among the other 51 cards, and every remaining card is equally likely to occupy the bottom position. Multiplying conditional probabilities gives (4/52)(3/51)=1/221. The two positions are distinct, so the second denominator is 51 rather than 52. Using four aces again for the second event would incorrectly replace the already-used top card.
For CFLs L1,L2 and regular R, which need not be context-free: concatenation, L1∩L2, L1∩R, or union?
Your answer
Answer & solution
Answer: B, C (no official key was published)
Context-free languages are closed under union and concatenation by introducing an appropriate new grammar start rule. They are also closed under intersection with a regular language, using a product of a PDA and a finite automaton. But take L1={an bn cm} and L2={am bn cn}, with nonnegative exponents. Each is context-free, while their intersection is {an bn cn}, which is not. Hence intersection of two arbitrary CFLs is the exceptional operation. The paper instead repeats L1∩L2 in choice C, making both B and C valid answers to its literal options; this source discrepancy is retained.
Let init(L)={u:uv∈L for some v}. If L is the set of nonempty binary words with equally many 0s and 1s, determine init(L).
Your answer
Answer & solution
Answer: B: {0,1}* (no official key was published)
Take any binary word u. If it has more zeros than ones, append exactly enough ones to balance the counts; if it has more ones, append zeros instead. If its counts are already equal and u is nonempty, append ε; if u=ε, append 01 so the resulting balanced word is nonempty. In every case there exists a suffix v with uv∈L, so every binary word is in init(L). Conversely, every prefix of a binary word is binary. The two inclusions prove init(L)={0,1}*, without requiring the prefix itself to have balanced counts.
For stmt→if id then stmt | if id then stmt else stmt | id:=id, which listed nested-if statement is ambiguous?
Your answer
Answer & solution
Answer: D: the nested-if statement with one dangling else (no official key was published)
An else following two unfinished nested if statements can attach either to the inner if or to the outer if. These choices produce different parse trees under the given grammar: if p then (if q then s else t), versus if p then (if q then s) else t. Both yield the same token sequence. The nested statement in D has precisely this form. A language implementation may impose “else matches the nearest if,” but that extra convention does not remove ambiguity from the grammar as printed.
Similar questions1 more → · asked again: GATE 2015 Set 3, Q30
Fewest swaps to make a max-heap
Heaps & Priority Queues
Tap to enlarge
For array [89,19,40,17,12,10,2,5,7,11,6,9,70], find the minimum arbitrary pair swaps to obtain a max-heap.
Your answer
Answer & solution
Answer: C: 2 (no official key was published)
Using one-based indices, swap entries 13 and 6, then 6 and 3. The array becomes [89,19,70,17,12,40,2,5,7,11,6,9,10], and every parent is at least as large as its children. For a lower bound, initially 70 at index 13 exceeds parent 10 at index 6. Any one-swap repair must change one of those positions. Moving a sufficiently large value into position 6 either puts 70 below a smaller parent or leaves position 6 larger than its parent 40; moving 70 directly to position 3 leaves 40 at 13 above parent 10. Exhaustive checking of all 78 pairs also finds no one-swap heap. Thus two are necessary and sufficient.
Solve T(1)=2, T(n)=3T(n/4)+n asymptotically for powers of four.
Your answer
Answer & solution
Answer: A: Θ(n) (no official key was published)
At recursion depth j there are 3j subproblems of size n/4j, so the total nonrecursive work is n(3/4)j. Summing these decreasing geometric terms gives O(n), while the root alone costs n and proves Ω(n). More exactly, with k=log₄ n, the leaves contribute 2·3k and internal levels contribute 4n(1−(3/4)k). The total is 4n−2nlog₄3. Therefore the recurrence is linear, not n log n, because each successive level contributes less work than the preceding one.
A sought item is equally likely to occupy any of n positions in a sequentially searched list. Find the expected comparisons for a successful search.
Your answer
Answer & solution
Answer: D: (n+1)/2 (no official key was published)
If the item occupies position i, searching from the beginning requires i comparisons. Uniform success positions therefore give E[C]=(1+2+…+n)/n. The arithmetic-series sum is n(n+1)/2, so E[C]=(n+1)/2. This is not the unsuccessful-search cost n, because successful searches stop at their target. Nor is it a binary-search logarithm, since the stated algorithm scans sequentially rather than repeatedly halving a sorted range.
Insert 50,15,62,5,20,58,91,3,8,37,60,24 into an empty BST. Count nodes in the left and right subtrees of the root.
Your answer
Answer & solution
Answer: B: 7 and 4 (no official key was published)
Step through it (14 steps)
The first key 50 remains the root in ordinary unbalanced BST insertion. Every later key below 50 belongs somewhere in its left subtree: 15,5,20,3,8,37,24, totaling seven. Every key above 50 belongs in its right subtree: 62,58,91,60, totaling four. Internal insertion paths affect shape but not which side of the root contains each key. The root itself is excluded from both counts, and 7+4+1=12 checks the total number of inserted keys.
Compare quicksort comparisons for a list already ascending versus descending when no pivot or partition implementation is specified.
Your answer
Answer & solution
Answer: D in general; C for standard end-pivot worst-case counting (no official key was published)
With the first or last element chosen as pivot on every subarray, either monotone input can split into sizes 0 and n−1. Counting n−1 comparisons per partition gives n(n−1)/2 for both orientations, the usual equality answer C under that model. But the question does not specify pivot selection or partition code. A rule depending on input orientation can select balanced pivots in one case and extreme pivots in the other; even comparison-count conventions vary. Therefore no implementation-independent ordering follows, corresponding to D. The common equal-count result is conditional, not a universal theorem about every quicksort variant.
Macro M1 recursively invokes M1(X+1) when X=0, otherwise emits WORD X. M2 instead recursively invokes M2(X) when X=0. Which can recurse indefinitely?
Your answer
Answer & solution
Answer: A: (ii) only (no official key was published)
For M1 invoked with X=0, the recursive call receives 1. Its condition is then false, so it emits WORD 1 and stops. For any nonzero initial value it stops immediately. M2 invoked with X=0 calls itself with the same argument, so the condition never changes and expansion repeats indefinitely. Thus only the second definition has the nontermination problem, option A. This reasoning uses expansion-time integer parameter evaluation; the recursion is in the macro processor, not a runtime subroutine.
Match activation record, location counter, reference counts and address relocation with subroutine call, assembler, garbage collection and linking loader.
Your answer
Answer & solution
Answer: D: A–3,B–4,C–2,D–1 (no official key was published)
An activation record stores the state of a subroutine invocation, such as saved control information and local variables. An assembler’s location counter tracks the address assigned to successive statements. Reference counts can support garbage collection by tracking how many references target an object. Address relocation adjusts addresses when a linking loader places program units in memory. These associations give 3,4,2,1 in the listed order. Reference counting has cycle limitations, but it is still the relevant collection mechanism in this matching question.
A 1000-Kbyte variable-partition memory has two allocated partitions of 200 and 260 Kbytes, with no compaction. What smallest integer-Kbyte request could be denied?
Your answer
Answer & solution
Answer: B: 181 Kbytes (no official key was published)
Free space totals 1000−200−260=540 Kbytes. Two occupied contiguous partitions divide linear memory into at most three free holes. Therefore at least one hole has size at least 540/3=180 Kbytes, so every request of at most 180 Kbytes can fit somewhere. This bound is attainable by arranging hole 180,allocation 200,hole 180,allocation 260,hole 180. In that layout a request of 181 Kbytes fails despite sufficient total free memory. Thus 181 is the smallest integer request that could fail; the question asks a possible worst layout, not a guarantee for every layout.
Which fork-taking rule prevents dining-philosopher deadlock: all left first, all right first, or one philosopher reversing the order used by everyone else?
Your answer
Answer & solution
Answer: C: one reverses the order (no official key was published)
If every philosopher takes the same side first, all can hold one fork and wait for the next, forming a circular wait. Reversing one philosopher’s order breaks that directed cycle: the neighboring philosophers compete for a common first fork, so they cannot all simultaneously hold distinct first forks while each awaits the next. Consequently the full circular-wait deadlock is impossible in the standard ring model. This prevents deadlock, not necessarily starvation without a fairness assumption. The uniform-left and uniform-right rules both retain the circular wait.
Similar questions1 more → · asked again: GATE 1993, Q7.10
Completion time under round robin
CPU Scheduling
Tap to enlarge
At time 0, jobs A,B,C,D arrive in that order with CPU bursts 4,1,8,1. With quantum 1 and no overhead, when does A complete?
Your answer
Answer & solution
Answer: D: time 9 (no official key was published)
The first four one-unit slices execute A,B,C,D, ending at time 4. B and D have now finished; A has three units left and C has seven. The next slices are A from 4–5, C from 5–6, A from 6–7, C from 7–8, and A from 8–9. A’s fourth unit therefore finishes at time 9. Counting four slices for A alone would ignore the CPU time given to other ready jobs. The result assumes the stated arrival order determines the initial queue and there is no context-switch cost.
The pictured four-bit adder receives b3…b0 and adds 0100 when b3b2=1, otherwise 0000; carry-in is zero. Its five output bits represent which conversion?
Your answer
Answer & solution
Answer: D: binary to radix 12 (no official key was published)
The condition b3b2=1 holds exactly for input values 12 through 15. For inputs 0 through 11, adding zero leaves the low four-bit digit unchanged and the carry zero. For inputs 12 through 15, adding four produces 16 through 19, so the output is carry 1 with low digit 0 through 3. Interpreting these as radix-12 digits gives 10₁₂ through 13₁₂, equal to decimal 12 through 15. BCD would instead correct at decimal 10 and add six, so it does not match this wiring.
A,B select mux inputs 0…3. In GFG the data inputs are C,¬C,¬C,C. Find f; the alternate loses the complement bars.
Your answer
Answer & solution
Answer: C: A⊕B⊕C (no official key was published)
When A=B, select 0 or 3, so f=C. When A≠B, select 1 or 2, so f=¬C. Thus f equals C toggled precisely when A⊕B=1, giving A⊕B⊕C. This evaluates all four selector cases and proves the parity expression. Both source readings are disclosed rather than silently treating the damaged alternate as identical.
For inputs 0,1, the next-state/output pairs are A:(D,0),(B,1); B:(A,0),(C,1); C:(A,0),(B,1); D:(A,1),(C,1). How many states remain?
Your answer
Answer & solution
Answer: B: 3 (no official key was published)
First group states by their immediate output pairs. A,B,C output (0,1), while D outputs (1,1), so D is separate. On input 0, A moves to D but B and C move to A, which belongs to the other initial group; therefore A must split from B,C. Now B and C both move to A on 0 and to the block {B,C} on 1, with identical outputs. They remain equivalent and no further split occurs. The stable partition is {A},{B,C},{D}, giving three states.
The K-map has rows CD=00,01,11,10 and columns AB=00,01,11,10; its 1s occur exactly where B≠D. Find a product-of-sums expression.
Your answer
Answer & solution
Answer: C: (B+D)(¬B+¬D) (no official key was published)
The displayed 1s occupy both B=1 columns when D=0 and both B=0 columns when D=1, independent of A and C. Hence the function is B XOR D. For a product-of-sums derivation, group the zeros with B=D=0 to obtain maxterm B+D, and group the zeros with B=D=1 to obtain maxterm ¬B+¬D. Their product is the required function. The paper option C prints this expression.
A microprogram unit has 25 control signals, at most two active in a word. Find the minimum bits; listed choices are 2,25,10,12.
Your answer
Answer & solution
Answer: 9 unrestricted; C:10 only under a two-selector-field architecture (no official key was published)
The legal output patterns are no active signal, one of 25 single signals, or one of C(25,2)=300 pairs: 326 patterns altogether. An unrestricted binary code therefore needs ceil(log₂326)=9 bits, since 256<326≤512. A decoder can map 326 of the 512 codes to these patterns, proving sufficiency. The listed 10-bit choice instead uses two independent five-bit selectors, each able to select one of 25 signals or a no-op. That practical architecture is sufficient but not information-theoretically minimal. No such field restriction is stated, so the missing 9-bit option is an explicit question/model discrepancy.
Let f(x)=x² for x≤1, ax²+bx+c for 1<x≤2, and x+d for x>2. Find a,b,c,d making f continuous and differentiable on the real line.
Answer & solution
Answer: a=−1/2, b=3, c=−3/2, d=1/2. (no official key was published)
Each branch is a polynomial, so only the joining points 1 and 2 can cause trouble. Continuity at 1 requires a+b+c=1. Equality of the left and right derivatives at 1 requires 2a+b=2, because the derivative of x² is 2x. At 2, continuity gives 4a+2b+c=2+d, while equality of derivatives gives 4a+b=1.
Subtract the derivative equation at 1 from that at 2: 2a=−1, hence a=−1/2. Then 2a+b=2 gives b=3. Substituting in a+b+c=1 gives c=−3/2. The middle branch at 2 is −2+6−3/2=5/2, so 2+d=5/2 and d=1/2.
As a direct check, the middle branch has value 1 and derivative 2 at x=1, and value 5/2 and derivative 1 at x=2. These match the adjacent branches exactly. The four linear matching conditions determine the four constants uniquely. Continuity is needed in addition to matching formal derivative formulas: derivative agreement alone would not rule out jumps in the function.
A BST is searched for key 43. Determine whether the probe sequence 61, 52, 14, 17, 40, 43 can occur, and explain. GFG instead prints 11 in place of 17 at the fourth probe.
Answer & solution
Answer: Impossible (no official key was published)
A search path obeys every ancestor constraint, not merely the immediately preceding comparison. Maintain an open interval of permissible keys, initially (−∞,+∞). When a probe is below 43, searching right raises the lower bound to that probe. When a probe is above 43, searching left lowers the upper bound.
After 61, every later probe must lie in (−∞,61). After 52, every later probe must lie in (−∞,52). After 14, every later probe must lie in (14,52). After 17, every later probe must lie in (17,52). After 40, every later probe must lie in (40,52). The final probe is 43, so the search succeeds.
All probes meet the bounds. A witnessing BST can be built as a chain with these keys, taking the left or right child according to each comparison with 43. Thus the bound test proves existence, rather than just failing to find an error.
With 17 the sequence is valid. With 11 it is invalid, because after visiting 14 the search for 43 must stay in the right subtree of 14, whose keys exceed 14. The 11 variant therefore has the opposite answer.
A BST is searched for key 43. Determine whether the probe sequence 2, 3, 50, 40, 60, 43 can occur, and explain.
Answer & solution
Answer: Impossible. (no official key was published)
A search path obeys every ancestor constraint, not merely the immediately preceding comparison. Maintain an open interval of permissible keys, initially (−∞,+∞). When a probe is below 43, searching right raises the lower bound to that probe. When a probe is above 43, searching left lowers the upper bound.
After 2, every later probe must lie in (2,+∞). After 3, every later probe must lie in (3,+∞). After 50, every later probe must lie in (3,50). After 40, every later probe must lie in (40,50). Probe 60 violates the inherited interval (40,50); the sequence is impossible.
The violated bound comes from an earlier ancestor. A later comparison cannot discard it: every node subsequently visited remains inside that ancestor’s chosen subtree. No choice of unvisited nodes can repair this path.
A BST is searched for key 43. Determine whether the probe sequence 10, 65, 31, 48, 37, 43 can occur, and explain.
Answer & solution
Answer: Possible. (no official key was published)
A search path obeys every ancestor constraint, not merely the immediately preceding comparison. Maintain an open interval of permissible keys, initially (−∞,+∞). When a probe is below 43, searching right raises the lower bound to that probe. When a probe is above 43, searching left lowers the upper bound.
After 10, every later probe must lie in (10,+∞). After 65, every later probe must lie in (10,65). After 31, every later probe must lie in (31,65). After 48, every later probe must lie in (31,48). After 37, every later probe must lie in (37,48). The final probe is 43, so the search succeeds.
All probes meet the bounds. A witnessing BST can be built as a chain with these keys, taking the left or right child according to each comparison with 43. Thus the bound test proves existence, rather than just failing to find an error.
A BST is searched for key 43. Determine whether the probe sequence 81, 61, 52, 14, 41, 43 can occur, and explain.
Answer & solution
Answer: Possible. (no official key was published)
A search path obeys every ancestor constraint, not merely the immediately preceding comparison. Maintain an open interval of permissible keys, initially (−∞,+∞). When a probe is below 43, searching right raises the lower bound to that probe. When a probe is above 43, searching left lowers the upper bound.
After 81, every later probe must lie in (−∞,81). After 61, every later probe must lie in (−∞,61). After 52, every later probe must lie in (−∞,52). After 14, every later probe must lie in (14,52). After 41, every later probe must lie in (41,52). The final probe is 43, so the search succeeds.
All probes meet the bounds. A witnessing BST can be built as a chain with these keys, taking the left or right child according to each comparison with 43. Thus the bound test proves existence, rather than just failing to find an error.
A BST is searched for key 43. Determine whether the probe sequence 17, 77, 27, 66, 18, 43 can occur, and explain.
Answer & solution
Answer: Impossible. (no official key was published)
A search path obeys every ancestor constraint, not merely the immediately preceding comparison. Maintain an open interval of permissible keys, initially (−∞,+∞). When a probe is below 43, searching right raises the lower bound to that probe. When a probe is above 43, searching left lowers the upper bound.
After 17, every later probe must lie in (17,+∞). After 77, every later probe must lie in (17,77). After 27, every later probe must lie in (27,77). After 66, every later probe must lie in (27,66). Probe 18 violates the inherited interval (27,66); the sequence is impossible.
The violated bound comes from an earlier ancestor. A later comparison cannot discard it: every node subsequently visited remains inside that ancestor’s chosen subtree. No choice of unvisited nodes can repair this path.
Inputs A,B and control bits C1,C0 specify F: 00→NOT(A OR B), 01→A OR B, 10→A XOR B, 11→A AND B. Implement using one 4:1 multiplexer, one two-input OR, one XOR, one AND, and one inverter. This is the complete GFG table; GateForum omits the last row.
Answer & solution
Answer: MUX selects I0=NOT(A+B), I1=A+B, I2=A XOR B, I3=AB with selectors C1,C0. (no official key was published)
First compute P=A OR B using the single OR gate. Fan out P to the multiplexer input I1 and to the inverter; connect the inverter output NOT(P) to I0. Compute X=A XOR B with the XOR gate and connect it to I2. Compute G=A AND B with the AND gate and connect it to I3. Use C1 as the high-order select bit and C0 as the low-order select bit. The multiplexer output is F.
Text circuit: A,B→OR→P→I1; P→NOT→I0; A,B→XOR→I2; A,B→AND→I3; (C1,C0)→MUX select; MUX→F. A common wire may drive multiple inputs, so sharing the OR result does not require another gate.
The four select codes choose I0,I1,I2,I3 respectively, directly reproducing the complete table. Algebraically F=(NOT C1)(NOT C0)NOT(P)+(NOT C1)C0P+C1(NOT C0)X+C1C0G. These outer products describe the multiplexer and do not demand extra physical gates.
For an 8085-style system with output port 00H, analyze the program ORG 0100H; MVI A,00H; LXI H,0105H; OUT 00H; INR A; PCHL; HLT. What does it do to the port? GFG includes OUT and INR but calls the CPU 8052; GateForum calls it 8085 but omits OUT and INR.
Answer & solution
Answer: Outputs 00H, 01H, …, FFH repeatedly (no official key was published)
Interpret the instructions as 8085 instructions: PCHL copies HL into the program counter. The byte addresses are 0100–0101 for MVI A,00H and 0102–0104 for LXI H,0105H. Therefore the next instruction, OUT 00H, starts at 0105H. OUT occupies two bytes, INR A one, PCHL one, so the loop is OUT at 0105H, INR at 0107H, PCHL at 0108H. HLT at 0109H is never reached.
Initialization sets A=0 and HL=0105H once. Each iteration writes A to the port, increments A modulo 256, then jumps back to OUT. Consequently the port receives 0,1,2,…,255,0,…, an indefinitely repeating eight-bit count. An external DAC would turn this into a staircase ramp, but a DAC is not part of the stated hardware.
The two reproductions cannot be treated as one literal program. Thus the port remains at its previous value, which is unspecified.
For the output-port program ORG 0100H; MVI A,00H; LXI H,0105H; OUT 00H; INR A; PCHL; HLT., show the three least significant output-bit waveforms. Account for the differing GateForum program without OUT and INR.
Answer & solution
Answer: D0=01010101…, D1=00110011…, D2=00001111… (no official key was published)
Sample immediately after successive OUT instructions. The low-three-bit output words are 000,001,010,011,100,101,110,111,000,… . Reading each column gives D0: 0 1 0 1 0 1 0 1; D1: 0 0 1 1 0 0 1 1; D2: 0 0 0 0 1 1 1 1. These eight samples repeat. Between output writes the port latch holds its previous value, so each column is a rectangular waveform, not a series of impulses.
If Δ is the interval between writes, D0 has period 2Δ, D1 period 4Δ and D2 period 8Δ, all with 50% steady-state duty cycle. In normal 8085 timing OUT takes 10 T-states, INR A takes 4 and PCHL takes 6, so Δ=20 T-states without interrupts or wait states. Their periods are therefore 40,80,160 T-states. If only qualitative waveforms are required, the relative periods suffice.
Initialization precedes the first write, so the output before that write is not specified. This result belongs to the instruction stream interpreted as 8085.
A demand-paged system has 16-bit virtual addresses, 256-byte pages, 1 KiB physical memory, and LRU order [17,1,63] from least to most recent. Process hexadecimal addresses 00FF,010D,10FF,11B0 in order. Only three initial residents are listed, so assume the fourth frame is free. Give the new list after each access.
Answer & solution
Answer: [17,1,63,0]; [17,63,0,1]; [63,0,1,16]; [0,1,16,17]. (no official key was published)
The offset occupies eight bits because a page has 28 bytes. Discard the low two hexadecimal digits to obtain decimal page references 0,1,16,17. Physical memory holds 1024/256=4 pages.
At 00FF, page 0 is absent: fault, load into the free frame, order [17,1,63,0]. At 010D, page 1 is present: hit, remove it from its old LRU position and append it, order [17,63,0,1]. At 10FF, page 16 is absent and memory is full: evict 17, append 16, order [63,0,1,16]. At 11B0, page 17 is absent because the previous reference evicted it: evict 63, append 17, order [0,1,16,17].
A page fault need not cause a replacement when a free frame exists; this distinction matters for the first reference. The initial figure shows three residents despite four-frame capacity. If an unprinted fourth resident was intended instead, its identity and recency are necessary for a unique trace. We do not invent that page or silently change memory capacity to three frames.
A demand-paged system has 16-bit virtual addresses, 256-byte pages, 1 KiB physical memory, and LRU order [17,1,63] from least to most recent. Process hexadecimal addresses 00FF,010D,10FF,11B0 in order. Only three initial residents are listed, so assume the fourth frame is free. Identify the accesses causing page faults.
Answer & solution
Answer: Faults at 00FF,10FF,11B0; 010D is a hit. (no official key was published)
The offset occupies eight bits because a page has 28 bytes. Discard the low two hexadecimal digits to obtain decimal page references 0,1,16,17. Physical memory holds 1024/256=4 pages.
At 00FF, page 0 is absent: fault, load into the free frame, order [17,1,63,0]. At 010D, page 1 is present: hit, remove it from its old LRU position and append it, order [17,63,0,1]. At 10FF, page 16 is absent and memory is full: evict 17, append 16, order [63,0,1,16]. At 11B0, page 17 is absent because the previous reference evicted it: evict 63, append 17, order [0,1,16,17].
A page fault need not cause a replacement when a free frame exists; this distinction matters for the first reference. The initial figure shows three residents despite four-frame capacity. If an unprinted fourth resident was intended instead, its identity and recency are necessary for a unique trace. We do not invent that page or silently change memory capacity to three frames.
A demand-paged system has 16-bit virtual addresses, 256-byte pages, 1 KiB physical memory, and LRU order [17,1,63] from least to most recent. Process hexadecimal addresses 00FF,010D,10FF,11B0 in order. Only three initial residents are listed, so assume the fourth frame is free. Identify page replacements, if any.
Answer & solution
Answer: 00FF: free frame; 010D: none; 10FF: replace 17 with 16; 11B0: replace 63 with 17. (no official key was published)
The offset occupies eight bits because a page has 28 bytes. Discard the low two hexadecimal digits to obtain decimal page references 0,1,16,17. Physical memory holds 1024/256=4 pages.
At 00FF, page 0 is absent: fault, load into the free frame, order [17,1,63,0]. At 010D, page 1 is present: hit, remove it from its old LRU position and append it, order [17,63,0,1]. At 10FF, page 16 is absent and memory is full: evict 17, append 16, order [63,0,1,16]. At 11B0, page 17 is absent because the previous reference evicted it: evict 63, append 17, order [0,1,16,17].
A page fault need not cause a replacement when a free frame exists; this distinction matters for the first reference. The initial figure shows three residents despite four-frame capacity. If an unprinted fourth resident was intended instead, its identity and recency are necessary for a unique trace. We do not invent that page or silently change memory capacity to three frames.
F consists of all functions {1,2,3}→{1,2,3}. Define f~g iff f(3)=g(3). How many equivalence classes are there?
Answer & solution
Answer: 3. (no official key was published)
A class is determined completely by the value at input 3. This value can be 1,2 or 3. Define Cr={f∈F:f(3)=r}, for r∈{1,2,3}. Each Cr is nonempty, for example because the constant function with value r lies in it. Every function belongs to exactly one Cr, since f(3) is a single well-defined value.
Within Cr, any two functions have the same value at 3 and are related. Functions from different Cr sets are not related. Thus these three sets are precisely the equivalence classes, not merely three arbitrary subsets. The assignments at 1 and 2 can vary freely without changing class membership.
The relation is reflexive because f(3)=f(3), symmetric because equality is symmetric, and transitive because equal values at 3 remain equal through an intermediate function. There are 3³=27 total functions, but the number of functions is not the number of classes. The quotient groups them by only one of their three output coordinates.
For functions {1,2,3}→{1,2,3} with f~g iff f(3)=g(3), find the size of each equivalence class.
Answer & solution
Answer: 9 functions per class. (no official key was published)
Fix one class Cr, so f(3)=r is fixed. There are three independent choices for f(1) and three for f(2). By the multiplication principle the class contains 3×3=9 functions. No injectivity or surjectivity restriction is stated, so the two values may coincide with each other or with r.
One can enumerate the free pair (f(1),f(2)) as (1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3). Appending the fixed third coordinate r gives nine distinct functions, and every function in Cr is represented once. The same argument works for r=1,2,3, so all three classes have the same size.
As a consistency check, 3 classes times 9 members gives 27=3³, the number of all functions from a three-element set to a three-element set. A common mistake is to count only permutations, which would wrongly impose a one-to-one condition absent from the question. The complete equality f(3)=g(3) comes from the paper.
Let f1=f2=1 and f_(n+2)=f_(n+1)+f_n for n≥1. Prove by induction that every third term is even.
Answer & solution
Answer: For every k≥1, f_(3k) is even. (no official key was published)
Use induction on k, not on the original index one step at a time. The base case is f3=f2+f1=2, which is even. For the induction step, derive a recurrence connecting terms three positions apart: fm+3=fm+2+fm+1=(fm+1+fm)+fm+1=2f_(m+1)+fm.
Assume f3k is even. Set m=3k in this identity. Then f3k+3=2f_(3k+1)+f3k is the sum of two even integers, hence even. This proves the claim for k+1 and completes the induction.
The proof deliberately does not assume anything about f3k+1: multiplying any integer by 2 makes it even. An alternative stronger invariant is that each consecutive block has parity odd,odd,even. Starting from 1,1,2, the recurrence gives the next block odd,odd,even again. This additionally proves that exactly the multiples of three have even terms, but the weaker requested conclusion already follows from the simpler induction above.
A and B are 2×2 matrices with AB=I. Let C=A[[1,0],[1,1]] and CD=I. Express D in terms of entries b11,b12,b21,b22 of B.
Answer & solution
Answer: D=[[b11,b12],[b21−b11,b22−b12]]. (no official key was published)
Write M=[[1,0],[1,1]], so C=AM. Because A and B are square and AB=I, A is invertible and B=A−1. Also det(M)=1, so M is invertible, with M−1=[[1,0],[−1,1]]. Inverting a product reverses the order: D=C−1=(AM)−1=M−1A−1=M−1B.
Multiply on the left explicitly. The first row of M−1B is the first row of B, (b11,b12). The second row is the second row of B minus its first row, (b21−b11,b22−b12). Hence D has the stated entries.
For verification, M D=B, because adding D's first row to its second gives B's second row, while its first row is unchanged. Then CD=A(MD)=AB=I. This check uses only the identities in the question and avoids introducing unknown entries of A. Multiplying B by M−1 on the right instead would subtract columns, not rows, and generally would not satisfy CD=I. The matrix order is therefore essential.
Transform S→ABAC, A→aA|ε, B→bB|ε, C→d into an equivalent CFG with no ε-productions and no unit productions.
Answer & solution
Answer: S→ABAC|BAC|AAC|ABC|AC|BC|d; A→aA|a; B→bB|b; C→d. (no official key was published)
The nullable nonterminals are A and B. C is not nullable because it must produce d; S is consequently not nullable. In S→ABAC, independently retain or omit each of the two occurrences of A and the one occurrence of B. The distinct right sides are ABAC, BAC, AAC, ABC, AC, BC and C. The side AC arises twice because either A can be the sole retained A, but duplicate productions need only be written once.
Removing A→ε and B→ε requires adding the terminating alternatives A→a and B→b: their old recursive rules could previously terminate by using the nullable final nonterminal. Keep A→aA|a and B→bB|b, so these variables now generate positive rather than arbitrary nonnegative repetitions. Keep C→d.
The only unit production introduced is S→C. Substitute C's nonunit right side to obtain S→d, then delete S→C. The resulting grammar is S→ABAC|BAC|AAC|ABC|AC|BC|d, A→aA|a, B→bB|b, C→d.
Every rule now has a nonempty right side; none has a sole nonterminal. The original language is {ai bj ak d:i,j,k≥0}. The seven start alternatives cover exactly which of the three repetition blocks are empty, with the all-empty case producing d. Thus the transformation preserves the language, including the shortest word d.
M1 has states A(start,final),B(nonfinal), with A→B and B→A on either 0 or 1. M2 has C(start,final),D(final),E(nonfinal): C loops on a, C→D on b, D loops on b, D→E on a, and E loops on a,b. Construct an ε-NFA recognizing L1L2 using no new states and only added ε-transitions.
Answer & solution
Answer: Use start A, final states C,D; add A→C on ε, retaining every original transition. (no official key was published)
M1 accepts binary strings of even length: each 0 or 1 toggles A and B, and A is accepting. M2 accepts a*b*: it stays at C through a's, moves to D at the first b, and a later a leads to rejecting sink E. Both languages contain ε.
For concatenation, retain all original symbol-labelled edges and add A→C on ε, because A is the only accepting state of M1 and C is the initial state of M2. The combined machine has just one initial state, A. Its accepting states are C and D, the former accepting states of M2. A is no longer designated accepting, although ε is still accepted via the new ε-edge to C. B and E remain nonaccepting.
Any accepting run first follows a run of M1 ending at A, then uses the ε-edge and follows an accepting run in M2. The consumed string therefore factors as uv with u∈L1 and v∈L2. Conversely every such factorization gives an accepting run. This proves equivalence rather than just providing a diagram recipe.
Text diagram addition: A --ε--> C. Initial/final annotations must be updated as stated; “only add ε-transitions” refers to edges and state count, not to keeping two independent initial-state markings. No new states or symbol transitions are required.
M1 has states A(start,final),B(nonfinal), with A→B and B→A on either 0 or 1. M2 has C(start,final),D(final),E(nonfinal): C loops on a, C→D on b, D loops on b, D→E on a, and E loops on a,b. Starting with the concatenation machine (start A, finals C,D, added ε-edge A→C), recognize (L1L2)* without new states.
Answer & solution
Answer: Add C→A and D→A on ε; keep start A and final states C,D. (no official key was published)
In the concatenation machine, reaching either C or D after consuming input means one complete L1L2 factor has been recognized. To permit another factor, add ε-edges from both accepting states back to the start A. Retain A→C and all original symbol edges. The complete added-edge set relative to the original two diagrams is A→C, C→A and D→A, all labelled ε.
An accepting run can now consist of any finite number of concatenation runs separated by the new return edges. Each segment consumes a word of L1L2; conversely a concatenation of such words is realized by joining their accepting runs through these ε-edges. Since L1 and L2 already contain ε, the start A can reach accepting C without consuming input, so the zero-factor case is accepted without adding a new accepting start state.
Keep C,D as final states. Making A final as well would also be harmless here because A already has an ε-path to a final state, but it is unnecessary. Adding only D→A would be insufficient as a general concatenation construction because C is also a valid final state, for example after a factor ending with only a's. ε-cycles cause no language-theoretic problem; an implementation computes finite ε-closures rather than following such cycles forever.
A PDA with states q1,q2, alphabet {a,b}, stack alphabet {a,b,Z}, initial state q1 and stack Z accepts nonempty even palindromes by empty stack. Stack top is at the right. Given δ(q1,a,Z)={(q1,Za)}, δ(q1,b,Z)={(q1,Zb)}, δ(q2,a,a)={(q2,ε)}, δ(q2,b,b)={(q2,ε)}, δ(q2,ε,Z)={(q2,ε)}, fill the two alternatives in each of δ(q1,a,a) and δ(q1,b,b). Discuss whether the displayed list is sufficient.
Answer & solution
Answer: δ(q1,a,a)={(q1,aa),(q2,ε)}; δ(q1,b,b)={(q1,bb),(q2,ε)}. Also require δ(q1,a,b)={(q1,ba)} and δ(q1,b,a)={(q1,ab)}. (no official key was published)
In state q1, the machine is guessing and storing the first half. On a matching input/top pair, it has two nondeterministic choices: push that input as another first-half symbol, or treat it as the first symbol of the reversed second half and pop the matching top while entering q2. Thus the displayed blanks are (q1,aa) and (q2,ε) for input a/top a, and (q1,bb) and (q2,ε) for input b/top b.
Those fillings alone do not recognize all even palindromes. The paper omits the mixed push transitions δ(q1,a,b)={(q1,ba)} and δ(q1,b,a)={(q1,ab)}. With rightmost stack top, ba means retain b and push a. For example abba requires pushing b over a; it is rejected if the missing transitions are absent. This is a defect in the printed specification, not an additional blank that can be silently filled.
With these two additional rules, q1 pushes an arbitrary nonempty first half. It switches to q2 only while reading and popping a matching character, then q2 can only pop further matching characters. Finally it removes Z by ε. Acceptance requires both empty stack and exhausted input. The first symbol must be pushed, so the empty word cannot be accepted; each push corresponds to exactly one later matched input, enforcing even length. The accepted strings are exactly wwR with nonempty w. No literal filling of just the four displayed blanks repairs the missing mixed cases.
An n×n integer array is intended to increase along every row and every column. Where is its minimum? The reproduction quantifies both inequalities only for i,j∈[1,n−1], which is narrower than full row/column sorting.
Answer & solution
Answer: Under the intended full row/column order: i=j=1. Under the literal restricted quantifier: not guaranteed. (no official key was published)
Under the standard partially sorted matrix interpretation, A[1,1]≤A[i,j] for every cell: move downward from (1,1) to (i,1), then rightward to (i,j), using monotonicity at each step. With strict comparisons and n>1 this makes A[1,1] the unique minimum; the requested blanks are i=1 and j=1. For n=1 the only cell is trivially the minimum.
There is a literal specification issue. The paper attach i,j∈[1,n−1] to both comparisons A[i,j]<A[i,j+1] and A[i,j]<A[i+1,j]. This does not constrain the last row horizontally or the last column vertically. In particular, A[n,n] appears in neither type of comparison. For n=2, the matrix [[1,2],[3,−100]] satisfies the printed comparisons 1<2 and 1<3, yet its minimum is at (2,2).
The usual intended definition instead quantifies horizontal comparisons for 1≤i≤n,1≤j<n, and vertical comparisons for 1≤i<n,1≤j≤n. The answer (1,1) follows from that corrected definition, not from the restricted literal one. This caveat also applies to the insertion procedure in the next subpart.
Delete the smallest element of an n×n row- and column-increasing array. Insert x, smaller than every item of the last row and last column, in O(n) time. Complete: i:=1;j:=1;A[i,j]:=x; while (x>blank or x>blank) do if A[i+1,j]<blank then begin A[i,j]:=A[i+1,j];i:=i+1 end else begin blank end; A[i,j]:=blank. Assume the intended full monotonicity and distinct inserted value.
Answer & solution
Answer: Compare x to A[i+1,j],A[i,j+1]; choose their minimum; shift it up/left; advance i or j; finally write x. (no official key was published)
A complete hole-moving version is:
i:=1; j:=1; A[i,j]:=x;
while (x>A[i+1,j]) or (x>A[i,j+1]) do
begin
if A[i+1,j]<A[i,j+1] then
begin A[i,j]:=A[i+1,j]; i:=i+1 end
else
begin A[i,j]:=A[i,j+1]; j:=j+1 end
end;
A[i,j]:=x.
Treat the current cell as a hole until the final assignment. If both children are greater than x, x belongs there. Otherwise the smaller of the downward and rightward neighbors is the smallest candidate that can fill the hole without violating either row or column order. Move it into the hole, advance to its old position, and repeat. Along the moved path, predecessors remain smaller than the element shifted into place; untouched cells preserve their old comparisons. The terminal hole receives x.
Each iteration increases i+j by one, hence there are O(n) iterations and O(1) extra storage. The given strict upper bound on x prevents the hole from entering the last row or last column: a boundary neighbor is greater than x and cannot be the smaller neighbor selected while the loop is true. Thus the two neighbor accesses are safe for n≥2. Without that promise use explicit bounds or +∞ sentinels.
Distinct x is a sufficient extra condition for preserving strict order. Without it the guarantee can fail: consider [[0,10,40],[20,30,50],[60,70,80]] with x=10. Here x is below every last-row/column entry, yet the procedure stops with adjacent equal values in the first row. Equal entries can sometimes occupy incomparable cells, but strict preservation is not guaranteed by the printed promise. If duplicates are allowed, interpret sorted as nondecreasing instead. Finally, the literal source quantifier omits boundary comparisons, so the algorithm relies on the intended full row/column definition discussed in part (a).
Insert K,R,P,C,S,N,Y,T,J,M in that order into slots 0,…,9 using linear probing and h(x)=(ord(x)−ord('a')+1) mod10. The input is uppercase while the formula uses lowercase a; distinguish alphabet-position normalization from literal uppercase ASCII. Which insertions collide?
Answer & solution
Answer: J and M under either stated convention. (no official key was published)
With alphabet positions (equivalently lowercasing each character before applying the formula), the home slots are K1,R8,P6,C3,S9,N4,Y5,T0,J0,M3. The first eight insertions find empty slots. J collides at 0 with T and at 1 with K, then occupies 2. M collides at 3,4,5,6, occupied respectively by C,N,Y,P, then occupies 7. Thus J and M are exactly the insertions that encounter collisions.
The final normalized table is 0:T,1:K,2:J,3:C,4:N,5:Y,6:P,7:M,8:R,9:S. Every character appears once and all ten slots are filled.
For literal uppercase ASCII with the printed lowercase 'a', ord(uppercase)=ord(lowercase)−32. Therefore each home slot is shifted by −32≡−2 modulo 10. Linear probing is circular and the whole table rotates by the same amount. Homes become 9,6,4,1,7,2,3,8,8,1, and the final table is 0:J,1:C,2:N,3:Y,4:P,5:M,6:R,7:S,8:T,9:K. J and M still collide. This literal result uses mathematical nonnegative modulo; a language whose remainder operator returns negative values needs normalization before indexing. Neither the paper resolves the case/encoding convention, so both answers are disclosed rather than silently changing the formula.
Insert K,R,P,C,S,N,Y,T,J,M in that order into slots 0,…,9 using linear probing and h(x)=(ord(x)−ord('a')+1) mod10. The input is uppercase while the formula uses lowercase a; distinguish alphabet-position normalization from literal uppercase ASCII. Give the final table.
Answer & solution
Answer: Alphabet positions: [T,K,J,C,N,Y,P,M,R,S]. Literal uppercase ASCII: [J,C,N,Y,P,M,R,S,T,K]. (no official key was published)
With alphabet positions (equivalently lowercasing each character before applying the formula), the home slots are K1,R8,P6,C3,S9,N4,Y5,T0,J0,M3. The first eight insertions find empty slots. J collides at 0 with T and at 1 with K, then occupies 2. M collides at 3,4,5,6, occupied respectively by C,N,Y,P, then occupies 7. Thus J and M are exactly the insertions that encounter collisions.
The final normalized table is 0:T,1:K,2:J,3:C,4:N,5:Y,6:P,7:M,8:R,9:S. Every character appears once and all ten slots are filled.
For literal uppercase ASCII with the printed lowercase 'a', ord(uppercase)=ord(lowercase)−32. Therefore each home slot is shifted by −32≡−2 modulo 10. Linear probing is circular and the whole table rotates by the same amount. Homes become 9,6,4,1,7,2,3,8,8,1, and the final table is 0:J,1:C,2:N,3:Y,4:P,5:M,6:R,7:S,8:T,9:K. J and M still collide. This literal result uses mathematical nonnegative modulo; a language whose remainder operator returns negative values needs normalization before indexing. Neither the paper resolves the case/encoding convention, so both answers are disclosed rather than silently changing the formula.
A complete undirected graph on vertices 0,1,…,n−1 has weight w(u,v)=|u−v| for distinct vertices. Draw a minimum spanning tree.
Answer & solution
Answer: Path 0—1—2—…—(n−1), total weight n−1. (no official key was published)
Every edge joins distinct integers, so its weight is at least 1. A spanning tree on n vertices contains exactly n−1 edges. Consequently every spanning tree has total weight at least n−1.
Connect consecutive vertices: (0,1),(1,2),…,(n−2,n−1). This is a connected path with no cycles, so it is a spanning tree. Each of its n−1 edges has weight 1, giving total n−1 and attaining the lower bound. Text diagram: 0 --1-- 1 --1-- 2 --1-- … --1-- (n−1), where the labels between dashes are edge weights.
For n≥2 it is also the unique MST. Achieving the lower bound requires every selected edge to have weight 1, and the only weight-1 edges in this graph are exactly the consecutive pairs. There are n−1 of them, so all must be selected. Alternatively, for the cut {0,…,k}|{k+1,…,n−1}, edge (k,k+1) is the unique minimum crossing edge and is mandatory by the cut property. When n=1 the empty tree has cost 0; the same n−1 formula applies.
A complete undirected graph on vertices 0,1,…,n−1 has weight w(u,v)=u+v for distinct vertices. Draw a minimum spanning tree.
Answer & solution
Answer: Star centered at 0, edges (0,v) for 1≤v<n; total n(n−1)/2. (no official key was published)
For each vertex v>0, consider the cut separating v from every other vertex. Its incident edges have weights v+u, with u≠v. The smallest possible u is 0, so (v,0) is the unique minimum-weight edge across this cut. By the cut property every MST must contain it.
Doing this for every v=1,…,n−1 gives exactly the star centered at 0. These n−1 edges connect all vertices and have no cycle, so the mandatory set itself is a spanning tree. Its weight is Σ_(v=1)n−1 v=n(n−1)/2. Text diagram: center 0 with a spoke to each v; spoke (0,v) has label v.
A second lower-bound proof roots any spanning tree at 0. Each nonroot vertex v has one parent p(v)≥0, so its parent edge costs v+p(v)≥v. Summing over all nonroot vertices gives total at least Σv. The star attains equality by taking every parent to be 0. This argument also shows uniqueness for n≥2: equality requires all parents 0. For n=1 there are no spokes and the minimum weight is 0. The complete graph assumption guarantees that every required spoke exists.
In the GFG p9 directed graph, edges with weights are A→B:6, A→C:90, A→F:2, A→E:70, B→D:41, C→B:12, C→E:10, D→C:12, F→B:22, F→C:60, F→D:50, E→F:15. GateForum p15 swaps the names E and F while keeping these positions and weights. Start at A. Give the Dijkstra settlement order.
Answer & solution
Answer: A, F, B, D, C, E (no official key was published)
Use the the paper labels first. Initialize d(A)=0 and all other labels to infinity. Settle A: tentative B=6,C=90,F=2,E=70. Settle F (2): B via F would be 24 and does not improve 6; C improves to 62 and D becomes 52. Settle B (6): D improves to 6+41=47. Settle D (47): C improves to 47+12=59. Settle C (59): E improves to 59+10=69; the edge back to B gives 71 and changes nothing. Finally settle E (69), whose edge to F gives 84 and changes nothing.
Thus the settlement order is A,F,B,D,C,E, with final distances 0,2,6,47,59,69 in that order. Predecessors for the E path are E←C←D←B←A, giving A→B→D→C→E and cost 6+41+12+10=69. This improves on the direct A→E cost 70 and the route A→F→C→E cost 72. All weights are nonnegative, so Dijkstra's settled distances are final.
A material the paper difference changes the answer to the named destination. Applying that relabelling, its settlement order is A,E,B,D,C,F. Its shortest A→E path is the direct edge of weight 2; the 69-cost bottom-vertex path ends at F there. The answers must remain tied to the chosen diagram. Decimal labels 90,60,50,70,10 contain zero glyphs, not an added symbolic variable.
In the GFG p9 directed graph, edges with weights are A→B:6, A→C:90, A→F:2, A→E:70, B→D:41, C→B:12, C→E:10, D→C:12, F→B:22, F→C:60, F→D:50, E→F:15. GateForum p15 swaps the names E and F while keeping these positions and weights. Start at A. Give the shortest A→E vertex sequence.
Answer & solution
Answer: A, B, D, C, E (no official key was published)
Use the the paper labels first. Initialize d(A)=0 and all other labels to infinity. Settle A: tentative B=6,C=90,F=2,E=70. Settle F (2): B via F would be 24 and does not improve 6; C improves to 62 and D becomes 52. Settle B (6): D improves to 6+41=47. Settle D (47): C improves to 47+12=59. Settle C (59): E improves to 59+10=69; the edge back to B gives 71 and changes nothing. Finally settle E (69), whose edge to F gives 84 and changes nothing.
Thus the settlement order is A,F,B,D,C,E, with final distances 0,2,6,47,59,69 in that order. Predecessors for the E path are E←C←D←B←A, giving A→B→D→C→E and cost 6+41+12+10=69. This improves on the direct A→E cost 70 and the route A→F→C→E cost 72. All weights are nonnegative, so Dijkstra's settled distances are final.
A material the paper difference changes the answer to the named destination. Applying that relabelling, its settlement order is A,E,B,D,C,F. Its shortest A→E path is the direct edge of weight 2; the 69-cost bottom-vertex path ends at F there. The answers must remain tied to the chosen diagram. Decimal labels 90,60,50,70,10 contain zero glyphs, not an added symbolic variable.
In the GFG p9 directed graph, edges with weights are A→B:6, A→C:90, A→F:2, A→E:70, B→D:41, C→B:12, C→E:10, D→C:12, F→B:22, F→C:60, F→D:50, E→F:15. GateForum p15 swaps the names E and F while keeping these positions and weights. Start at A. Give the shortest A→E cost.
Answer & solution
Answer: 69 (no official key was published)
Use the the paper labels first. Initialize d(A)=0 and all other labels to infinity. Settle A: tentative B=6,C=90,F=2,E=70. Settle F (2): B via F would be 24 and does not improve 6; C improves to 62 and D becomes 52. Settle B (6): D improves to 6+41=47. Settle D (47): C improves to 47+12=59. Settle C (59): E improves to 59+10=69; the edge back to B gives 71 and changes nothing. Finally settle E (69), whose edge to F gives 84 and changes nothing.
Thus the settlement order is A,F,B,D,C,E, with final distances 0,2,6,47,59,69 in that order. Predecessors for the E path are E←C←D←B←A, giving A→B→D→C→E and cost 6+41+12+10=69. This improves on the direct A→E cost 70 and the route A→F→C→E cost 72. All weights are nonnegative, so Dijkstra's settled distances are final.
A material the paper difference changes the answer to the named destination. Applying that relabelling, its settlement order is A,E,B,D,C,F. Its shortest A→E path is the direct edge of weight 2; the 69-cost bottom-vertex path ends at F there. The answers must remain tied to the chosen diagram. Decimal labels 90,60,50,70,10 contain zero glyphs, not an added symbolic variable.
For N>1, the following Pascal-like program searches an array a[1..N]: initialize i=1,j=N; repeatedly set k=floor((i+j)/2), then if a[k]<x set i=k, otherwise set j=k; stop when a[k]=x or i>=j. Finally print success if a[k]=x and failure otherwise. Determine when it fails. For the intended binary-search interpretation assume a is sorted in nondecreasing order. GFG prints the success message correctly; GateForum instead prints failure in both final branches.
Answer & solution
Answer: It loops when x>a[1] and x is not in positions 1..N−1; in particular a unique match at the last element is missed (no official key was published)
The defect is that the lower update keeps the already examined element: i=k instead of i=k+1. When j=i+1, integer division gives k=i. If a[i]<x, setting i=k changes nothing; j also stays unchanged, a[k] is not x, and i<j remains true. The loop repeats forever.
In fact the final array position N is never examined: while i<j, floor((i+j)/2)<j<=N, so k<=N−1. On a nondecreasing array, the exact classification is: every x occurring among a[1],...,a[N−1] is eventually found; every x<a[1] terminates with failure; every x>a[1] absent from a[1..N−1] loops forever. The latter includes absent values between array entries, values above the maximum, and x=a[N] when that value occurs only at the last position. Duplicates matter: x=a[N] is found if the same value occurs earlier.
For example a=[1,3], x=3 gives (i,j,k)=(1,2,1) forever. With x=0, the first iteration instead sets j=1 and terminates correctly. For a=[1,3,5], x=3 is examined immediately and succeeds. These examples distinguish the actual bug from the inaccurate claim that all unsuccessful searches fail.
A robust repair uses while i<=j, tests equality first, then sets i=k+1 when a[k]<x and j=k−1 otherwise, reporting failure after the interval becomes empty. This also permits examining N.
Global b is set to 3 and test1(b) is called. Procedure test1(a) sets a=5, prints “point 1:” followed by a,b, calls test2, then prints “point 2:” followed by a,b. Procedure test2 sets the global b=10. After test1 returns, the main program prints “point 3:” followed by b. Assume the displayed lexical scope and determine the output with a passed by reference.
Answer & solution
Answer: point 1: 5 5; point 2: 10 10; point 3: 10. (no official key was published)
A reference parameter is another name for the caller's variable, not a private copy of its value. Here the actual parameter is the global b, so a and b designate the same storage throughout test1. Initially that cell contains 3. Executing a:=5 updates the cell itself, which means both a and b now read as 5. Consequently the first output is point 1: 5 5.
Next test2 executes b:=10. It refers to the global b by the displayed lexical scope; this is the same cell already aliased by a. Therefore both reads at the second output produce 10, giving point 2: 10 10. Returning from test1 requires no copy-back for a reference parameter. The global value remains 10, and the final output is point 3: 10.
The important reasoning is storage identity: a:=5 changes b immediately, and test2's assignment to b changes what a observes immediately. The procedure nesting does not create a second b or hide the global declaration. Spaces and line breaks may depend on Pascal's output formatting; the value sequences, in order, are (5,5), (10,10), and (10).
Global b is set to 3 and test1(b) is called. Procedure test1(a) sets a=5, prints “point 1:” followed by a,b, calls test2, then prints “point 2:” followed by a,b. Procedure test2 sets the global b=10. After test1 returns, the main program prints “point 3:” followed by b. Assume the displayed lexical scope and determine the output with a passed by value-result (copy-in/copy-out).
Answer & solution
Answer: point 1: 5 3; point 2: 5 10; point 3: 5. (no official key was published)
Value-result creates a separate local parameter cell. At entry to test1, the current actual value b=3 is copied into a. The assignment a:=5 changes only that private cell; the global b remains 3. Thus the first output is point 1: 5 3.
The call to test2 then assigns 10 to the global b. It does not refer to the private parameter a of its caller, so a stays 5. The second output is consequently point 2: 5 10. This is the observable difference from call-by-reference: a is not an alias for b during the call.
At normal return from test1, the result phase copies the final local a back to the original actual parameter location b. That overwrites test2's value 10 with 5. The main program therefore prints point 3: 5. The chronological storage states are (a,b)=(3,3) at entry, (5,3) after assigning a, (5,10) after test2, and b=5 after copy-out. No conflict among multiple value-result actuals arises because the procedure has just one parameter. If it were ordinary call-by-value instead, there would be no final copy-back and point 3 would show 10; the word “result” is essential.
Use the SDTS E→E+E {print “+”}, E→E*E {print “.”}, E→id {print id.name}, E→(E) {no action}. An LR parser executes a production's action immediately after reducing by it. Draw the parse tree and give the translation of (a+b)*(c+d).
Answer & solution
Answer: Literal output ab+cd+. (final dot is emitted); root multiplication with two parenthesized addition subtrees. (no official key was published)
The root production is E→E*E. Its left E derives (E), whose inner E derives E+E with identifier leaves a and b. Its right E derives (E), whose inner E derives E+E with identifier leaves c and d. Thus a textual description of the full parse tree is E(E('(',E(E(id a),'+',E(id b)),')'), '*', E('(',E(E(id c),'+',E(id d)),')')). Parentheses are terminal children of their E→(E) nodes, not emitted characters.
Actions run on reduction, after the right-hand-side subexpressions have been recognized. Reducing id a prints a, reducing id b prints b, and reducing their addition prints +. The parenthesized left operand therefore emits a b +. The E→(E) reduction emits nothing. Similarly the right operand emits c d +. Only after both operand E nodes exist can the root multiplication reduce and print the dot specified by its action.
The literal complete output is a b + c d + ., or ab+cd+. when concatenated without separators. The final dot is an emitted multiplication token, not sentence punctuation. It is postfix notation: each operation follows its operands. As a check, a postfix evaluator pushes a and b, combines them by +, pushes c and d, combines them by +, then multiplies the two resulting values. The grammar is ambiguous in general for unparenthesized mixed operators, but these explicit parentheses fix the intended tree for this particular sentence. Conventional postfix ab+cd+* expresses the same multiplication, but it is not the exact string emitted by the printed SDTS and must not replace it silently.
fork L creates a new process starting at label L while the original continues. join V atomically decrements V and terminates the arriving process unless the new value is zero. For N=2; M=2; fork L3; fork L4; S1; L1: join N; S3; L2: join M; S5; goto next; L3: S2; goto L1; L4: S4; goto L2; next:, draw the precedence graph for S1..S5. The goto next after S5 is present in GFG but omitted in GateForum.
Answer & solution
Answer: Edges S1→S3, S2→S3, S3→S5, S4→S5 (no official key was published)
After the two forks there are three branches. The original executes S1, the L3 branch executes S2, and the L4 branch executes S4. There is no synchronization among those three statements, so they can occur in any order or overlap.
The S1 and S2 branches both reach join N. Because N starts at 2, the first arrival changes N to 1 and terminates; the second changes N to 0 and survives. Exactly one process therefore continues to S3, and S3 cannot start until both S1 and S2 have finished. This gives edges S1→S3 and S2→S3. The identity of the surviving process is irrelevant to the statement ordering.
The branch completing S3 and the branch completing S4 both reach join M. The same counting argument, with M initially 2, permits S5 exactly once, after both predecessors finish. Add edges S3→S5 and S4→S5. These four edges form the transitive reduction: draw S1 and S2 feeding S3, then S3 and S4 feeding S5. The additional transitive relations S1→S5 and S2→S5 need not be drawn.
This finite five-statement interpretation uses the paper's explicit goto next after S5. Its execution is not captured by the intended one-node-per-statement DAG. Omitting the jump is a material control-flow variant, not harmless punctuation.
Three processes P0,P1,P2 share resource types R0,R1,R2. Maximum total claims are P0=(4,1,2), P1=(1,5,1), P2=(1,2,3). Current allocations are P0=(1,0,2), P1=(0,3,1), P2=(1,0,2), and Available=(2,2,0). Show that this can be a state admitted by the Banker’s algorithm.
Answer & solution
Answer: Safe sequence P1→P2→P0; Work evolves (2,2,0)→(2,5,1)→(3,5,3)→(4,5,5). (no official key was published)
Step through it (5 steps)
The table heading “Maximum Need” gives total claims, not outstanding requests. Subtract each allocation to obtain remaining Need: P0=(3,1,0), P1=(1,2,0), P2=(0,2,1). The total resource vector is Available plus all allocations, namely (4,5,5); every maximum is individually within this total.
Run the safety test with Work=(2,2,0). P0 cannot finish yet because it needs 3 units of R0 but only 2 are free. P2 cannot finish because it needs one R2 while none is free. P1 can finish since (1,2,0) is componentwise at most (2,2,0). After it finishes, Work increases by its current allocation (0,3,1), yielding (2,5,1). Adding allocation, rather than maximum, is correct: its extra temporary requests are returned too, leaving the net increase equal to the allocation it already held.
Now P2's need (0,2,1) fits, so its completion releases (1,0,2) and Work becomes (3,5,3). Finally P0's need (3,1,0) fits; releasing (1,0,2) yields (4,5,5). Thus P1,P2,P0 is a safe sequence, proving that all claims can be satisfied in a suitable order. Safety does not assert that every possible future request is immediately grantable; it establishes at least one completion schedule from the current allocations.
Three processes P0,P1,P2 share resource types R0,R1,R2. Maximum total claims are P0=(4,1,2), P1=(1,5,1), P2=(1,2,3). Current allocations are P0=(1,0,2), P1=(0,3,1), P2=(1,0,2), and Available=(2,2,0). Determine what happens when P0 requests one unit of R1.
Answer & solution
Answer: Defer P0’s request: tentative Available=(2,1,0) is unsafe although the unit is available. (no official key was published)
Step through it (4 steps)
The request vector is R=(0,1,0). First check R<=Need0=(3,1,0), so the request does not exceed P0's remaining claim. Also R<=Available=(2,2,0), so the requested unit is physically available. These necessary checks alone do not justify granting it.
Tentatively allocate the unit. Available becomes (2,1,0), P0's allocation becomes (1,1,2), and P0's remaining need becomes (3,0,0). The other needs remain P1=(1,2,0), P2=(0,2,1). Begin the safety test with Work=(2,1,0). P0 cannot finish because 3>2 in R0; P1 cannot finish because 2>1 in R1; P2 cannot finish because it needs 2 R1 and 1 R2, while only 1 R1 and 0 R2 are free. No process can be the first in a guaranteed completion sequence.
The tentative state is therefore unsafe. The Banker rolls back the tentative change and makes P0 wait, preserving Available=(2,2,0) and the original safe allocations. This is not a claim that the request is invalid or that an actual deadlock has already occurred. It is a refusal to enter a state from which completion under all declared maximum claims cannot be guaranteed. The one free unit's availability is precisely why a full safety test, rather than a simple availability check, is needed.
A one-level file system uses 4K-byte disk blocks. Disk block 0 contains a FAT with one 8-bit next-data-block address entry per data block. Disk block 1 is a directory with one 32-bit entry per file. Disk blocks 2,3,... are data blocks 1,2,... . Take K=1024. Find the maximum possible number of files.
Answer & solution
Answer: 1024 directory entries/files when empty files are permitted; nonempty-file capacity is additionally data-block limited. (no official key was published)
The directory occupies one block, so its storage is 4×1024=4096 bytes. A directory entry uses 32 bits=4 bytes. Hence it contains 4096/4=1024 entries and can name at most 1024 files. This is a directory-capacity bound; the FAT entry count must not be substituted into this division.
Attaining that many named files does not require one data block for every file if zero-length files are allowed. Empty files can occupy directory entries without owning data blocks, so the customary directory-capacity interpretation gives 1024 files. If instead the question requires every file to be nonempty, the result also depends on the number of addressable data blocks and the unspecified pointer conventions. Under a uniform 8-bit data-block address convention with all 256 patterns usable, at most 256 one-block nonempty files fit, and reserved FAT markers reduce that number.
There is a related source-design omission: a 4096-byte FAT can physically hold 4096 one-byte entries, but one-byte next pointers cannot name all 4096 positions under a uniform address scheme. Thus table capacity, pointer addressability, and directory capacity are three distinct quantities. The problem does not specify empty-file policy, reserved values, or actual disk capacity; 1024 is the unambiguous maximum directory entry count, not a proof that 1024 nonempty files can simultaneously occupy the disk.
A one-level file system uses 4K-byte disk blocks. Disk block 0 contains a FAT with one 8-bit next-data-block address entry per data block. Disk block 1 is a directory with one 32-bit entry per file. Disk blocks 2,3,... are data blocks 1,2,... . Take K=1024. Find the maximum possible file size in data blocks.
Answer & solution
Answer: Conventional answer: 256 data blocks (1 MiB), conditional on uniform 8-bit identifiers without reserved codes; literal exact bound depends on unspecified encoding. (no official key was published)
A FAT-linked file is a chain: its directory entry identifies the first data block, and each block's FAT entry identifies the next. With a uniform 8-bit data-block addressing convention there are 28=256 possible address values. If all values are usable data-block identifiers and termination is represented separately (for example by known file length), a file can traverse at most 256 distinct data blocks. It would occupy 256×4096=1,048,576 bytes. This is the conventional intended pointer-width answer.
The 4KB FAT itself has room for 4096 one-byte entries, but room to store an entry is not the same as enough pointer bits to address its block. Therefore 4096 blocks is not justified merely by dividing FAT size by entry size. A pointer width of at least 12 bits would be required to name 4096 data blocks uniformly.
The literal question does not define end-of-file encoding or whether addresses refer to physical disk blocks or data-block ordinals. Reserving one of the 256 values for EOF leaves at most 255 usable uniform data-block addresses. If physical block numbers 0 and 1 are also excluded as metadata locations, the usable range changes again. These are specification choices, not values established by the paper. Accordingly 256 blocks is conditional on the standard all-patterns-usable data-block model; an exact implementation-level maximum cannot be certified without the address and termination conventions. The directory entry's 32 bits do not by themselves repair the short next pointers.
A synchronous circuit has three D flip-flops with common clock. Q1 feeds D2, Q2 feeds D3, and Q2 XOR Q3 feeds D1 through the feedback gate. State Si denotes the binary value i of Q1Q2Q3, so S0=000,...,S7=111. Draw its state-transition diagram.
Answer & solution
Answer: S0 self-loop; S1→S4→S2→S5→S6→S7→S3→S1. (no official key was published)
A D flip-flop takes its next output from its D input on the common active clock edge. All three updates use the old outputs simultaneously. Reading the circuit wires gives Q1(next)=Q2 XOR Q3, Q2(next)=Q1, and Q3(next)=Q2. In particular, do not feed the newly computed Q1 into Q2 during the same clock edge.
To draw the diagram, put a self-loop on S0 and draw the separate seven-state directed cycle S1→S4→S2→S5→S6→S7→S3→S1. There is no external input, so each state has exactly one outgoing edge and there are no input labels to choose. The zero state is a fixed point because shifting zeros and XORing zeros still gives zeros. As a consistency check, the listed targets contain all eight states once; the transition function is invertible, since the old Q1 and Q2 are read from the new Q2 and Q3 and old Q3 is recovered by XORing new Q1 with new Q3.
States unreachable from the initial register state
Finite-State Machine Design
Tap to enlarge
A synchronous circuit has three D flip-flops with common clock. Q1 feeds D2, Q2 feeds D3, and Q2 XOR Q3 feeds D1 through the feedback gate. State Si denotes the binary value i of Q1Q2Q3, so S0=000,...,S7=111. Starting at S4, identify all unreachable states.
Answer & solution
Answer: Only S0 is unreachable; the seven nonzero states form the cycle containing S4. (no official key was published)
The next-state equations are (Q1,Q2,Q3)→(Q2 XOR Q3,Q1,Q2). Begin with S4=100 and repeatedly apply them. The successive states are S4=100, S2=010, S5=101, S6=110, S7=111, S3=011, S1=001, and then S4=100 again.
Once a deterministic state repeats, its subsequent trajectory repeats too; there is no input capable of taking a different branch. Therefore the reachable set is exactly {S1,S2,S3,S4,S5,S6,S7}, including the initial state itself at time zero. The only member of the eight-state space not visited is S0=000. It is unreachable from S4, although it is a perfectly valid state and would remain at zero forever if chosen as an initial state.
One can verify the exclusion algebraically. If the next state were 000, then new Q2=old Q1=0 and new Q3=old Q2=0. New Q1=old Q2 XOR old Q3=0 then forces old Q3=0. Thus only 000 can transition to 000; no nonzero state can enter it. The enumerated seven-state cycle proves that no additional state is excluded. The paper labels this subpart separately as question 73, but it is part (b) of original question 24 and shares that question's circuit and five-mark group allocation.
A 50 MHz processor uses DMA for a disk transferring 2000 Kbytes/s continuously. The average DMA block is 4 Kbytes. Each transfer needs 1000 processor cycles for setup and 500 processor cycles for its completion interrupt. What fraction of CPU time is consumed by disk handling?
Answer & solution
Answer: 0.015 of processor time, i.e. 1.5%. (no official key was published)
First count transfers rather than bytes: 2000 Kbytes/s divided by 4 Kbytes/transfer is 500 transfers/s. The same meaning of K occurs in both quantities and cancels, so decimal versus binary K does not change this rate.
The processor performs 1000+500=1500 cycles of administrative work for every transfer. At 500 transfers/s this costs 750,000 CPU cycles/s. A 50 MHz processor supplies 50,000,000 cycles/s, so the fraction used is 750,000/50,000,000=0.015, or 1.5 percent.
An equivalent time calculation checks the units. Each processor cycle lasts 1/(50×106) s=20 ns. Setup takes 20 microseconds and the completion handler takes 10 microseconds, totaling 30 microseconds per transfer. Transferring 4K bytes at 2000K bytes/s takes 0.002 s=2 milliseconds; 30 microseconds/2 milliseconds again equals 0.015. The transfer uses DMA, so the CPU is not charged for executing an instruction per byte. The calculation counts only the specified setup and completion overhead; additional bus-contention stalls, queuing effects, or other driver costs are not given and should not be invented. The statement that the disk transfers continuously fixes the block rate at its full throughput.
A three-level hierarchy has level-1 access time 50 ns/byte and options 8KB (hit .80), 16KB (.90), 64KB (.95); level-2 access time 200 ns/byte and options 4MB (hit .98), 16MB (.99), 64MB (.995); level 3 has access time 5 microseconds/byte, size 250MB, hit 1.0. Use the GFG table; GateForum has inconsistent duplicated tables, KB/MB units and 250/260MB labels. The question does not explicitly state whether lower-level access times include earlier failed probes. Choose minimum level-1 and level-2 sizes giving average access time strictly below 100 ns.
Answer & solution
Answer: Complete-service-time model: 8KB L1 and 4MB L2 (99.2 ns). Sequential probing gives different feasible minima; see solution. (no official key was published)
If the tabulated times are complete service times for a hit at the corresponding level, and h2 is conditional on missing level 1, then T=h1·50+(1−h1)h2·200+(1−h1)(1−h2)·5000. Try the smallest options first: h1=.80 and h2=.98. Their mutually exclusive outcome probabilities are .80, .196, and .004, summing to one. Hence T=40+39.2+20=99.2 ns, strictly below 100. Since 8KB and 4MB are individually the smallest listed sizes, this pair is componentwise minimal in that model.
A different standard convention treats 50,200,5000 as incremental sequential probe times. Then every access pays 50, every L1 miss pays another 200, and a miss in both pays another 5000: Tseq=50+(1−h1)[200+(1−h2)5000]. The same 8KB/4MB pair gives 110 ns and fails. At 8KB, increasing L2 to 16MB gives exactly 100 ns, still failing the strict inequality; 64MB gives 95 ns. At 16KB, the smallest L2=4MB already gives 80 ns. Thus the nondominated feasible pairs in the sequential model are (8KB,64MB) and (16KB,4MB); neither is smaller in both coordinates. Minimizing total installed bytes selects (16KB,4MB), whereas minimizing L1 first selects (8KB,64MB).
Therefore the familiar 8KB/4MB answer requires the complete-service-time interpretation. Without specifying the timing convention, the literal question has no single model-independent answer. The lower-level hit ratio is also taken as conditional, not as an additional unconditional probability.
A three-level hierarchy has level-1 access time 50 ns/byte and options 8KB (hit .80), 16KB (.90), 64KB (.95); level-2 access time 200 ns/byte and options 4MB (hit .98), 16MB (.99), 64MB (.995); level 3 has access time 5 microseconds/byte, size 250MB, hit 1.0. Use the GFG table; GateForum has inconsistent duplicated tables, KB/MB units and 250/260MB labels. The question does not explicitly state whether lower-level access times include earlier failed probes. Calculate the average time for the sizes selected to satisfy the strict 100 ns bound.
Answer & solution
Answer: 99.2 ns in the complete-service-time model; sequential alternatives are 80 ns for 16KB/4MB or 95 ns for 8KB/64MB. (no official key was published)
For the complete-service-time interpretation, select the smallest listed capacities, L1=8KB and L2=4MB. An access hits L1 with probability .80 and takes 50 ns. It misses L1 and hits L2 with probability .20×.98=.196 and takes 200 ns. It misses both with probability .20×.02=.004 and takes 5000 ns. The mean is therefore .80×50+.196×200+.004×5000=40+39.2+20=99.2 ns per byte. This is 0.8 ns below the required bound. Notice that even the rare .4 percent accesses to level 3 contribute 20 ns to the mean.
This calculation uses exclusive end-to-end outcomes. If the table instead lists incremental sequential access times, earlier failed probes must also be charged: 50+.20×200+.004×5000=110 ns for these same capacities, so they would not be a valid choice. In that model, the (16KB,4MB) pair gives 50+.10×200+(.10×.02)×5000=80 ns. The alternative nondominated (8KB,64MB) pair gives 50+.20×200+(.20×.005)×5000=95 ns. The (8KB,16MB) pair gives exactly 100 ns, which is excluded by “less than”.
Thus report 99.2 ns together with its timing assumption, rather than presenting it as a verified official value.
Relations are USERS(User#,UserName,HomeTown), BOOKS(Book#,BookTitle,AuthorName), and ISSUED(Book#,User#,Date). Natural joins match the identically named key attributes. Explain in one English sentence the query σ_User#=6(π_User#,BookTitle((USERS ⋈ ISSUED) ⋈ BOOKS)). This paraphrase uses GFG's legible relational operators; GateForum's reproduction drops join symbols and degrades projection typography.
Answer & solution
Answer: Returns (6, title) pairs for books recorded as issued to user 6. (no official key was published)
One-sentence answer: It returns user number 6 together with the titles of books recorded as issued to that user.
To see why, USERS ⋈ ISSUED first connects each issue record with the user whose User# matches. Joining this result with BOOKS on Book# adds the associated BookTitle and AuthorName. The projection π_User#,BookTitle retains just the user identifier and title, discarding names, dates, book identifiers and author names. Finally σ_User#=6 keeps only rows whose user identifier is 6.
Selection occurs after projection here without losing its input attribute, because User# is explicitly retained. It could equivalently be pushed earlier to restrict the user or issue records before the joins. Under ordinary set-based relational algebra, projection removes duplicate pairs: borrowing the same titled book more than once does not produce multiple identical (6,title) rows, and distinct books with the same title also collapse at this projection. No return-date or current-loan condition exists in the schema, so “recorded as issued” is more precise than claiming these are necessarily the user's currently unreturned books. The query yields titles with the fixed identifier 6, not a count of loans, author names, or all users who borrowed the same books.
Relations are USERS(User#,UserName,HomeTown), BOOKS(Book#,BookTitle,AuthorName), and ISSUED(Book#,User#,Date). Natural joins match the identically named key attributes. Explain in one English sentence the query π_AuthorName(BOOKS ⋈ σ_HomeTown='Delhi'(USERS ⋈ ISSUED)). Use the projection and natural-join symbols visible in GFG; GateForum misprints/degrades these operators.
Answer & solution
Answer: Names of authors with at least one book issued to a Delhi-hometown user. (no official key was published)
One-sentence answer: It returns the names of authors having at least one book recorded as issued to a user whose hometown is Delhi.
The inner natural join USERS ⋈ ISSUED matches each issue to its borrower through User#. Selecting HomeTown='Delhi' retains issue records belonging to Delhi users; the condition describes the borrower's hometown, not the author's residence or the book's publication place. The join with BOOKS matches Book# and adds the author of each surviving issued book. Projection onto AuthorName then discards every other attribute.
Under set semantics each distinct author name appears once, even if several Delhi users borrowed that author's books or one user borrowed several such books. The condition is existential: one qualifying issue suffices. It does not require that all books by the author have been issued, that every Delhi user has read the author, or that the author is popular by any numerical threshold. Likewise nothing in the given schema tests whether a book has since been returned. If no Delhi user has any issue record, the result is empty. Two different people who happen to share AuthorName are not distinguished by this schema and projection; the result is a set of names rather than necessarily unique real-world author identities.