Find the rank of the matrix [[1, 1], [0, 0]]. (A) 4; (B) 2; (C) 1; (D) 0.
Your answer
Answer & solution
Answer: C (no official key was published)
Step 1: Count independent rows, not nonzero entries.
Step 2: The row (1,1) spans every row of the matrix, so the row-space dimension is one. Rank cannot be negative; rank two would require two independent rows, while rank zero would require the zero matrix.
Conclusion: The first row is nonzero and the second row is zero. There is exactly one linearly independent row, so the rank is 1, C.
For which polynomial degrees does the trapezoidal integration rule give an exact result? (A) 0 but not 1; (B) 1 but not 0; (C) 0 or 1; (D) 2.
Your answer
Answer & solution
Answer: C (no official key was published)
Step 1: Check what the trapezoidal formula integrates.
Step 2: On [a,b], the approximation is (b−a)(f(a)+f(b))/2. Substituting f(x)=c gives c(b−a), and substituting f(x)=mx+c gives m(b²−a²)/2+c(b−a), both exact integrals. For f(x)=x² on [0,1], it gives 1/2 instead of 1/3, ruling out degree two.
Conclusion: The trapezoidal rule integrates the straight line joining the endpoint values. It is exact for every polynomial of degree 0 or 1, C. A quadratic such as x² already has a nonzero error on a nondegenerate interval.
Step 1: Remove the powers of two from the argument.
Step 2: Writing out S(1)=4, S(2)=13, S(3)=40 reveals the repeated multiply-by-three pattern. In general the homogeneous contribution is 3kS(0), while the added ones contribute 1+3+…+3k−1. Evaluating that geometric sum gives the stated formula; at k=0 it correctly returns1.
Conclusion: Put S(k)=T(2k). Then S(k)=3S(k−1)+1 with S(0)=1. Iteration gives 3k+sum_(j=0)k−13j=(3k+1−1)/2, B.
What is the fewest colors needed for the vertices of an n-node cycle if adjacent vertices must receive different colors? (A) 2; (B) 3; (C) 4; (D) n − 2⌊n/2⌋ + 2.
Your answer
Answer & solution
Answer: D (no official key was published)
Step 1: Separate even and odd cycle lengths.
Step 2: Label successive vertices alternately red and blue. When n is even the last vertex is blue and the first red, so the closing edge is legal. When n is odd both would be red; recolor the last vertex with a third color. The expression n−2floor(n/2) is exactly zero or one, so the option captures both cases rather than claiming one constant color count.
Conclusion: An even cycle alternates two colors. An odd cycle cannot alternate consistently around the closing edge and needs a third color, which suffices. Thus χ=2+(n mod2)=n−2floor(n/2)+2, D, for an ordinary cycle n≥3.
How many comparisons are needed in the worst case to find a specified element in a singly linked list with n elements? (A) log₂ n; (B) n/2; (C) log₂ n − 1; (D) n.
Your answer
Answer & solution
Answer: D (no official key was published)
Step 1: Identify a worst-case input.
Step 2: Put the target in the final node. Before examining that node, none of the earlier comparisons succeeds, so there are n−1 failed comparisons and one successful comparison. If the target is absent there are n failed comparisons instead. Binary-search logarithmic bounds require positional access and ordering not supplied here; n/2 is not a worst-case bound.
Conclusion: An absent key or a key only at the final node requires examining all n nodes. Each node entails one comparison with the search key, so the worst case is n, D.
Select the true statement about multiplication. (A) All negative rational numbers form a group. (B) All nonsingular matrices form a group. (C) All matrices form a group. (D) Both (B) and (C).
Your answer
Answer & solution
Answer: B (no official key was published)
Step 1: Test the four group axioms.
Step 2: For invertible A,B, the inverse of AB is B⁻¹A⁻¹, establishing closure as well as an inverse construction. The identity is the fixed-size identity matrix. In contrast, (−1)(−1)=1 leaves the set of negative rationals, and a zero matrix has no inverse. This rules out A,C and therefore the combined option D.
Conclusion: For a fixed dimension over a field, nonsingular matrices are closed under multiplication, matrix multiplication is associative, I is the identity, and each member has a nonsingular inverse. Thus B under this conventional fixed-dimension interpretation. Negative rationals are not closed under multiplication, and singular matrices lack inverses; matrices of mixed dimensions would not form the claimed group.
A pushdown automaton is restricted to at most 10 stack items. Which class best describes the language it accepts? (A) Context-free; (B) Regular; (C) Deterministic context-free; (D) Recursive.
Your answer
Answer & solution
Answer: B (no official key was published)
Step 1: Turn stack contents into finite control.
Step 2: If the stack alphabet has s symbols, at most 1+s+…+s10 stack words are possible. With q control states, at most q(1+s+…+s10) combined configurations are needed, apart from fixed acceptance bookkeeping. Every push/pop transition can be represented between these finite states, so an unbounded-memory PDA advantage is absent.
Conclusion: A fixed finite stack alphabet and maximum stack height 10 allow only finitely many stack strings. Pairing each with the finite control state yields a finite automaton, including epsilon transitions if needed. Hence the language is regular, B; the larger language classes listed are less precise.
Choose the propositional formula for “If X then Y unless Z.” Here ¬ means negation, ∧ conjunction, and → implication. (A) (X ∧ ¬Z) → Y; (B) (X ∧ Y) → ¬Z; (C) X → (Y ∧ ¬Z); (D) (X → Y) ∧ ¬Z.
Your answer
Answer & solution
Answer: A (no official key was published)
Step 1: Translate the exceptional case before forming the implication.
Step 2: Only the case X=true,Z=false activates the requirement. The formula must therefore be false exactly when X=true,Z=false,Y=false. Option A has exactly this truth condition. A formula additionally demanding ¬Z when X is false, or forbidding Y whenever Z holds, would add an unstated requirement.
Conclusion: The obligation Y applies when X holds and the exception Z does not. This is (X∧¬Z)→Y, A, equivalently ¬X∨Z∨Y. The exception does not itself require ¬Y.
A device requests an interrupt through INTR. While which signal is active does it place a CALL instruction on the data bus? (A) INTA (active-low interrupt acknowledge); (B) HOLD; (C) READY; (D) None of these.
Your answer
Answer & solution
Answer: A (no official key was published)
Step 1: Distinguish request from acknowledgment.
Step 2: INTR requests CPU service. Once accepted, INTA tells the external device when it may drive the instruction information onto the data bus. HOLD instead requests bus-master control, and READY indicates whether a transfer can finish without wait states. Their roles do not provide the interrupt-instruction handshake.
Conclusion: For an 8085 INTR request, the external device supplies the instruction during the interrupt-acknowledge sequence, when active-low INTA is asserted. Thus A. HOLD concerns bus ownership and READY controls wait states.
Which 8085 instructions modify the program counter? (A) Only PCHL; (B) Only ADD instructions; (C) Only JMP and CALL; (D) All instructions.
Your answer
Answer & solution
Answer: D (no official key was published)
Step 1: Include the fetch phase, not only the instruction’s explicit operation.
Step 2: An arithmetic instruction still consumes its opcode and possibly operand bytes from the instruction stream. The PC must move beyond those bytes so execution can continue. A jump changes where execution continues, but this extra change does not make jumps the only PC-modifying instructions.
Conclusion: The program counter advances during instruction fetching even for instructions that do not explicitly branch. Branch, call and PCHL instructions additionally replace its value. Therefore it is not modified only by a special instruction subset: D in the ordinary 8085 instruction-fetch model.
Similar questions2 more → · asked again: GATE 1992, Q2(v)
Start and stop bits in serial transmission
Data Link, Framing, Error Control & ARQ
Tap to enlarge
In serial transmission, a byte is preceded by 0 and followed by one or two 1 bits. What is the purpose? (A) Synchronize the receiver for byte reception. (B) Recover lost 0s and 1s from those extra bits. (C) Use those extra bits for parity calculation. (D) None of these.
Your answer
Answer & solution
Answer: A (no official key was published)
Step 1: Explain why each byte needs a framing event.
Step 2: The receiver and transmitter need not share one continuously aligned clock. The falling transition into the start bit establishes the reference for sampling the following data bits; the stop interval checks framing and separates successive bytes. A fixed start/stop pattern cannot reconstruct arbitrary lost bits and does not calculate whether the data contains an odd or even number of ones.
Conclusion: Asynchronous reception detects the low start bit to establish the bit-sampling phase for that byte; the high stop interval returns the line to its idle condition and permits framing. These bits synchronize byte reception, A. They are not parity or recovery codes.
Find the minimum sum-of-products form of f(w,x,y,z) from this Karnaugh map. Columns wx are 00, 01, 11, 10; rows yz are 00, 01, 11, 10. The respective rows of entries are [0,1,1,0], [X,0,0,1], [X,0,0,1], [0,1,1,X], where X is a don’t-care. Prime denotes complement. (A) xz + y′z; (B) xz′ + zx′; (C) x′y + zx′; (D) None of these.
Your answer
Answer & solution
Answer: B (no official key was published)
Step through it (12 steps)
Step 1: Read the map using its Gray-code axes.
Step 2: The clearer alternate labels columns wx=00,01,11,10 and rows yz=00,01,11,10. Rows with z=0 have specified ones where x=1; rows with z=1 have ones where x=0, with don’t-cares available to complete the groups. Each four-cell group removes the two variables that change inside it. The two resulting product terms have opposite x,z values, identifying XOR rather than an expression depending on y.
Conclusion: Group the four cells with x=0,z=1 to obtain x′z. Group the four cells with x=1,z=0, using the displayed don’t-care cells, to obtain xz′. The remaining specified cells are zero. Thus f=xz′+x′z, B. Each implicant is needed to cover its separate group, and w,y disappear.
Which item is not a kind of memory? (A) Instruction cache; (B) Instruction register; (C) Instruction opcode; (D) Translation lookaside buffer.
Your answer
Answer & solution
Answer: C (no official key was published)
Step 1: Separate a stored field from a storage device.
Step 2: The instruction register can hold an entire instruction, including its opcode; an instruction cache holds instruction bytes. A TLB holds cached address translations. The opcode is the information inside such storage, just as a number written in a register is not itself a register.
Conclusion: A cache, an instruction register, and a translation lookaside buffer are storage structures. An instruction opcode is a bit field identifying an operation, not itself a memory structure. Therefore C.
Which statement describes decimal 0.25? (A) It equals binary 0.1. (B) It equals binary 0.01. (C) It equals binary 0.00111… . (D) It cannot be represented exactly in binary.
Your answer
Answer & solution
Answer: B and C if the trailing ones continue forever (no official key was published)
Step 1: Evaluate both binary expansions as real numbers.
Step 2: In0.001111…, the first one is in the third fractional position, so its value is 1/8+1/16+1/32+… . Multiplying this sum by 1/2 and subtracting leaves half the sum equal to 1/8, hence the sum is 1/4. No finite truncation equals 1/4, but the infinite expansion does. The ellipsis is therefore essential to the recorded ambiguity.
Conclusion: The terminating binary representation is 0.01₂=2−2=1/4, B. But the printed alternative C,0.001111..., also equals sum_(j=3)^∞2−j=(1/8)/(1−1/2)=1/4 when the ellipsis means infinitely repeated ones. Thus both are exact real-number representations, analogous to decimal 0.999...=1. B is the unique terminating representation, but the prompt does not restrict to terminating representations. This is an overlapping-options issue, not an official-key claim.
Twos-complement representation of negative fifteen
Number Systems & Computer Arithmetic
Tap to enlarge
Which bit string is a two’s-complement representation of decimal −15? (A) 1111; (B) 11111; (C) 111111; (D) 10001.
Your answer
Answer & solution
Answer: D (no official key was published)
Step through it (10 steps)
Step 1: Choose a width that can represent the value.
Step 2: The n-bit two’s-complement range is−2n−1 through 2n−1−1. Four bits cannot hold−15, while five bits can. At width five, +15 is 01111; complementing gives 10000 and adding one gives 10001. Interpreting10001 as unsigned 17 and subtracting 32 independently checks−15.
Conclusion: At least 5 bits are needed because the 4-bit signed range is−8 through 7. In5 bits, −15 is 25−15=17=10001₂, D. Strings consisting entirely of ones represent−1, not−15.
In which operation is sign extension a step? (A) Floating-point multiplication; (B) Signed 16-bit integer addition; (C) Arithmetic left shift; (D) Conversion of a signed integer from one size to another.
Your answer
Answer & solution
Answer: D (no official key was published)
Step 1: Compare zero extension with sign extension.
Step 2: For a positive number, the sign bit is zero, so sign extension simply adds leading zeros. For a negative number, adding leading ones preserves the signed interpretation: 10001 has unsigned value 17−32=−15, and 11110001 has unsigned value 241−256=−15. Zero-extending 10001 would instead yield+17.
Conclusion: When a signed two’s-complement integer is widened, copy its sign bit into the new high-order positions. This preserves the numerical value; for example 10001₂ (5-bit−15) becomes 11110001₂ (8-bit−15). This is the size-conversion operation in D.
Select the correct statement about C. (A) At most one activation record lies between the current record and main’s record. (B) The number of activation records between the current record and main’s record depends on the actual sequence of function calls. (C) Visibility of global variables depends on the actual sequence of function calls. (D) Before a recursive call, the recursive function’s activation record must be saved on another stack.
Your answer
Answer & solution
Answer: B (no official key was published)
Step 1: Trace a concrete call chain.
Step 2: If main calls f and f calls g, the active stack contains main,f,g. If g recursively calls itself, another g activation is needed while the earlier one remains active. Thus the number of intervening records changes with actual calls. Lexical visibility is determined by declarations and scopes, not by this stack depth.
Conclusion: The runtime activation chain follows the actual sequence of function calls. Its depth between the current function and main therefore depends on that sequence, B. C uses lexical rather than dynamic scope for global names, and recursive calls can use successive records on the same runtime stack.
Compare function results under value-result and reference parameter passing. They: (A) Never differ; (B) Differ when loops are present; (C) Differ in every case; (D) May differ when exceptions are present.
Your answer
Answer & solution
Answer: D (no official key was published)
Step 1: Use an exceptional exit to distinguish parameter mechanisms.
Step 2: Suppose an actual variable initially holds 0 and the function sets its formal to 1 before raising an exception. Reference passing has already changed the actual to 1. Under copy-restore with copying back only at normal return, the actual remains 0. This is a possible difference, not a claim that all calls differ or that exceptions have one universal language-independent copy-out policy.
Conclusion: With reference passing, updates immediately affect the actual argument. With value-result (copy-in/copy-out), they can remain in the local formal until normal return. If an exception exits before copy-out, the visible results can differ, D, under the conventional no-copy-out-on-exception rule. Aliasing can also distinguish these mechanisms; loops alone neither force nor exclude a difference.
Relation R, with functional dependencies F, is decomposed into BCNF. How much redundancy caused by functional dependencies remains in the resulting relations? (A) Zero; (B) Positive, but less than in an equivalent 3NF decomposition; (C) Proportional to the size of F⁺; (D) Cannot be determined.
Your answer
Answer & solution
Answer: A (no official key was published)
Step 1: Identify the redundancy that BCNF targets.
Step 2: A dependency such as Department→Office repeats an office value across employee rows when Department is not a key. Decomposition can put that dependency in a relation where Department is a key, eliminating that particular repetition. BCNF applies this superkey condition to every nontrivial projected FD; it does not promise absence of multivalued or application-level redundancy.
Conclusion: BCNF requires the determinant of every nontrivial projected functional dependency to be a superkey. Therefore the usual within-relation redundancy caused by a nonkey determinant is eliminated, A. This claim is specifically about FD-based redundancy in the decomposed relations, not all possible redundancy or guaranteed dependency preservation.
Which comparison of expressive power is true for formal relational query languages? (A) Relational algebra is more powerful than relational calculus. (B) Relational algebra and relational calculus have equal power. (C) Relational algebra and safe relational calculus have equal power. (D) None of these.
Your answer
Answer & solution
Answer: C (no official key was published)
Step 1: Check the safety restriction in the equivalence statement.
Step 2: A safe query restricts its results to values justified by the finite database and query constants. An unrestricted formula such as “x is not in R” over an infinite ambient domain can return infinitely many values. Relational algebra cannot produce that infinite result from finite input relations, explaining why the safe-calculus qualifier selects C over the unrestricted claim.
Conclusion: The expressive-equivalence theorem relates relational algebra to safe/domain-independent relational calculus, C. An unrestricted calculus expression can describe an infinite or domain-dependent result, which ordinary relational algebra over finite input relations cannot produce.
Which statement about overflow in two’s-complement addition is correct? (A) A carry from the sign-bit addition always flags overflow. (B) Adding a positive value to a negative value cannot overflow. (C) Overflow is flagged when the carries from the sign bit and the preceding bit agree. (D) None of these.
Your answer
Answer & solution
Answer: B (no official key was published)
Step 1: Contrast carry with signed overflow.
Step 2: In four bits, 0111+0001=1000 overflows the signed range even though there is no final carry. Conversely, 1111+0001=0000 with a carry represents−1+1=0 without signed overflow. These examples rule out a carry-only test. Opposite-sign operands always have a sum between the two operands and therefore within range.
Conclusion: If a≥0 and b<0 are representable, their sum lies between b and a and remains representable. Thus opposite-sign addition cannot overflow, B. For two’s complement, overflow is the XOR of the carry into and out of the sign position, not simply the outgoing carry or equality of those carries.
Similar questions1 more → · asked again: GATE 2026 Set 2, Q23
Nonpreemptive scheduling policy
CPU Scheduling
Tap to enlarge
Which scheduling method is nonpreemptive? (A) Round robin; (B) First-in first-out; (C) Multilevel queue scheduling; (D) Multilevel queue scheduling with feedback.
Your answer
Answer & solution
Answer: B (no official key was published)
Step 1: Identify the event that removes the running process.
Step 2: Under FIFO, arrival of another ready process does not by itself interrupt the current one. The current process relinquishes the CPU by blocking or finishing. Round robin deliberately introduces timer preemption. A multilevel policy needs additional rules before one can decide whether it preempts, so its name is not an unconditional alternative to FIFO.
Conclusion: FIFO/FCFS lets the running job continue until it blocks or completes, so B. Round robin preempts at a time quantum. Multilevel scheduling families depend on their specified interqueue and intraqueue policies and are not, by name alone, the fixed nonpreemptive policy sought.
Which page does optimal page replacement evict? (A) The one unused for the longest past interval. (B) The one whose next use is farthest in the future. (C) The one used the fewest times. (D) The one used the most times.
Your answer
Answer & solution
Answer: B (no official key was published)
Step 1: Compare future reuse times.
Step 2: If resident pages will next be requested after 2,5 and 10 accesses, evict the page needed after 10. Evicting the page needed after 2 causes a miss sooner while retaining a page that is not yet useful. This exchange argument can be repeated to match an optimal schedule. The method is a theoretical benchmark because the future reference string is generally unavailable online.
Conclusion: Choose the resident page whose next use lies farthest in the future, treating no further use as infinity. Exchanging any earlier-needed victim for this one cannot increase future faults, yielding Belady’s optimal policy, B. Past recency describes LRU instead.
In absolute addressing, which statement is correct? (A) The instruction contains the operand. (B) The instruction contains the operand’s address. (C) The instruction specifies a register that holds the operand’s address. (D) The operand’s location is implicit.
Your answer
Answer & solution
Answer: B (no official key was published)
Step 1: Locate the address in each addressing mode.
Step 2: For a conceptual instruction LOAD R,[1000], the instruction’s address field 1000 identifies memory containing the operand: absolute addressing. LOAD R,#1000 instead uses 1000 itself as an immediate value. LOAD R,[S] obtains the address from register S. These distinctions correspond to the different answer descriptions.
Conclusion: In absolute/direct addressing the instruction supplies the operand’s address, B. Supplying the operand value is immediate addressing; naming a register containing its address is register-indirect addressing.
What is the maximum edge count in an undirected n-vertex graph without self-loops? (A) n²; (B) n(n−1)/2; (C) n−1; (D) n(n+1)/2.
Your answer
Answer & solution
Answer: B under the simple-graph convention (no official key was published)
Step 1: Count unordered vertex pairs.
Step 2: Vertex one can pair with n−1 others, vertex two with n−2 new others, and so on, giving(n−1)+(n−2)+…+1=n(n−1)/2. Dividing the ordered count n(n−1) by two gives the same result. The complete simple graph realizes every pair. If parallel edges are allowed, adding another edge between an existing pair defeats any fixed maximum.
Conclusion: There is one possible edge for each unordered pair of distinct vertices, so the maximum is binomial(n,2)=n(n−1)/2, B, achieved by Kn. This uses the conventional simple-graph interpretation. Excluding self-loops alone does not prohibit parallel edges in a multigraph, for which no finite bound follows.
A circuit connects f₁ and f₂ to a two-input NAND gate, inverts f₃ with a NOT gate, and feeds these two outputs to another two-input NAND gate whose output is f. Given f₁(x,y,z)=Σm(0,1,3,5), f₂(x,y,z)=Σm(6,7), and f(x,y,z)=Σm(1,4,5), find f₃. (A) Σm(1,4,5); (B) Σm(6,7); (C) Σm(0,1,3,5); (D) None of these.
Your answer
Answer & solution
Answer: A (no official key was published)
Step 1: Apply De Morgan’s law at the final gate.
Step 2: The first NAND outputs¬(f1f2), and the lower inverter outputs¬f3. The final NAND complements their conjunction, giving f1f2+f3. Because no minterm belongs to both{0,1,3,5} and{6,7}, the product f1f2 is identically zero. Therefore the third input must equal the required output, not either of the two earlier input functions.
Conclusion: The network computes f=¬(¬(f1f2)·¬f3)=f1f2+f3. The minterm sets of f1 and f2 are disjoint, so f1f2=0. Hence f3=f=Σ(1,4,5), A.
A 4-to-1 multiplexer selects I₀,I₁,I₂,I₃ for A₁A₀=00,01,10,11 respectively. The diagram connects I₀=I₁=x, I₂=y, I₃=y′, A₁=y′, A₀=z, and enable EN=z′. Its output is f(x,y,z). Which function is implemented? (A) xyz′; (B) xy+z; (C) x+y; (D) None of these. The drawing labels EN as an enable input but does not explicitly state the disabled-output convention.
Your answer
Answer & solution
Answer: A under the conventional enable model (no official key was published)
Step 1: Split by enable, then by the select bit.
Step 2: For z=1, EN=0 and the assumed Boolean disabled output is 0. For z=0, A0=0; if y=0 then A1=1, selecting input I2=0, while y=1 makes A1=0 and selects I0=x. Thus the only way to output 1 is x=y=1,z=0. The explicit disabled-output convention is needed because a high-impedance device is not modeled by this truth table.
Conclusion: The shown connections are I0=I1=x, I2=y, I3=y′, A1=y′, A0=z, and EN=z′. With active-high enable and output forced 0 while disabled, z=1 makes f=0. When z=0, y=0 selects I2=0 and y=1 selects I0=x. Thus f=xyz′, A. A tristate disabled output would instead be high impedance; that behavior is not the Boolean-output model used here.
Define the Boolean function f(A,B)=A′+B, where prime is complement and + is OR. Simplify f(f(x+y,y),z). (A) x′+z; (B) xyz; (C) xy′+z; (D) None of these.
Your answer
Answer & solution
Answer: C (no official key was published)
Step 1: Simplify one function application at a time.
Step 2: First substitute A=x+y,B=y into A′+B. De Morgan gives x′y′+y, and absorption y+x′y′=y+x′ simplifies it. Now use that entire expression as the first argument of the outer function: (x′+y)′+z=xy′+z. Complementing only one component of the inner result would give the wrong expression.
Conclusion: The inner function is f(x+y,y)=(x+y)′+y=x′y′+y=x′+y. Applying f again gives (x′+y)′+z=xy′+z, C.
Determine the auxiliary carry AC and carry CY flags after this 8085 instruction sequence: MVI H, 5DH MVI L, 6BH MOV A, H ADD L (A) AC=0, CY=0; (B) AC=1, CY=1; (C) AC=1, CY=0. (D) Source variant: GFG prints AC=0, CY=0 (duplicating A), whereas GateForum prints AC=0, CY=1. Original official wording is not verified.
Your answer
Answer & solution
Answer: C (no official key was published)
Step 1: Perform both the nibble sum and the full sum.
Step 2: At the low nibble, hexadecimal D+B=13+11=24=16+8, so a carry crosses the bit3 boundary. At the high nibble,5+6+1=12=C, without a carry beyond the byte. Hence the result is C8, auxiliary carry 1, full carry 0. Source option D differs between reproductions, but neither version competes with the computed option C.
Conclusion: A receives 5D₁₆ and ADD L adds 6B₁₆, yielding C8₁₆. The low nibbles D+B=18₁₆ generate a carry out of bit3, so AC=1. The full sum is below 100₁₆, so CY=0. Thus C.
A finite-state machine starts in A. Transition labels are input/output, with a one-bit input and two-bit output. The diagram gives A --0/00--> A, A --1/01--> B, B --0/01--> A, B --1/10--> C, C --0/01--> A, and C --1/10--> C. What does it do? (A) Output the sum of the current and preceding input bits. (B) Output 01 whenever the input sequence contains 11. (C) Output 00 whenever the input sequence contains 10. (D) None of these.
Your answer
Answer & solution
Answer: A (no official key was published)
Step 1: Verify all possible current/previous bit pairs.
Step 2: Previous0/current 0 produces 00; previous 0/current 1 produces 01; previous 1/current 0 produces 01; previous 1/current 1 produces 10. State A is the previous-zero class and B,C the previous-one class. On input 110, the output is 01,10,01, so claims of 01 for the final 11 pair or 00 for 10 are contradicted directly.
Conclusion: State A represents previous input 0 (also the initial assumed bit); states B and C both represent previous input 1. From A, input 0 outputs 00 and input 1 outputs 01. From B or C, input 0 outputs 01 and input 1 outputs 10. These are the two-bit encodings of previous bit plus current bit, A. The extra distinction between B and C does not change this behavior.
Which condition harms pipelined-processor performance? (A) Unequal stage delays; (B) Dependencies between consecutive instructions; (C) Shared hardware resources among stages; (D) All of these.
Your answer
Answer & solution
Answer: D (no official key was published)
Step 1: Separate three causes of lost pipeline throughput.
Step 2: Stage imbalance makes the clock period depend on the slowest stage. A dependence can make an instruction wait until its operand is available. A structural conflict occurs when two stages need one shared resource simultaneously. These are independent mechanisms, so an answer listing only one omits other valid possibilities.
Conclusion: Unequal stage delays leave faster stages waiting for the slowest. Data dependence can require stalls, and shared hardware can create structural conflicts. Each can reduce performance, so D. Suitable forwarding, scheduling or duplicated resources may mitigate particular cases, rather than making the hazards impossible.
Which statement describes horizontal microprogramming? (A) Signal decoders are unnecessary. (B) Microinstructions are larger than in vertical microprogramming. (C) Each control signal has its own bit. (D) All of these.
Your answer
Answer & solution
Answer: D (no official key was published)
Step 1: Compare direct bits with encoded control fields.
Step 2: With k directly controlled signals, a fully horizontal word can devote k bits to asserting them. A vertical word can use a shorter encoded field for mutually exclusive alternatives, but then requires decoding to recover the individual control lines. The width-versus-decoder tradeoff explains why all three descriptions hold together in the stated model.
Conclusion: In the fully horizontal model, each control signal has its own bit, so no encoded-control-field decoder is needed. This makes instructions wider than a vertical encoding. All three statements apply to that model, D; sequencing/address decoding is not thereby eliminated.
C declares char a[100][100]. Memory is byte-addressable, and the array starts at address 0. What is the address of a[40][50]? (A) 4040; (B) 4050; (C) 5040; (D) 5050.
Your answer
Answer & solution
Answer: B (no official key was published)
Step 1: Compute the linear index before the byte address.
Step 2: There are 40 complete rows before row40, each contributing 100 characters, and 50 earlier characters within that row. Therefore the zero-based linear index is 4000+50=4050. Since sizeof(char)=1, no further scale factor is needed. The5040 alternative reverses the row and column roles.
Conclusion: C lays out rows contiguously in row-major order. Each char occupies one byte, and each row has 100 elements. The offset of a[40][50] is 40×100+50=4050 bytes, giving address 4050 from the stipulated zero base, B.
A rooted tree has n nodes, each with either zero or three children. How many leaves does it have? (A) n/2; (B) (n−1)/3; (C) (n−1)/2; (D) (2n+1)/3.
Your answer
Answer & solution
Answer: D (no official key was published)
Step 1: Count edges in two ways.
Step 2: Every vertex except the root has exactly one parent edge, so there are n−1 edges. Every internal node has three children, so there are 3I edges. Equating gives I=(n−1)/3. Subtracting internal nodes from all nodes gives leaves L=n−(n−1)/3=(2n+1)/3. For the smallest nontrivial case n=4, this correctly returns three leaves.
Conclusion: Let I be the internal-node count and L the leaves. Each internal node supplies 3 child edges, while a tree has n−1 edges, so 3I=n−1. Hence L=n−I=(2n+1)/3, D, for n admitting such a tree.
An unsorted array A[1..n] contains n distinct values and contains x. A search repeatedly chooses i uniformly from 1..n, compares A[i] with x, stops on equality, and otherwise repeats the random choice. What is its expected comparison count before stopping? (A) n; (B) n−1; (C) 2n; (D) n/2.
Your answer
Answer & solution
Answer: A (no official key was published)
Step 1: Recognize independent repeated trials.
Step 2: After any failed draw, the algorithm restarts with the same success probability 1/n; it has not removed that position from future draws. Thus the comparison count is geometric, P(N=k)=(1−1/n)k−1/n. Its mean is 1/(1/n)=n, agreeing with the recurrence E=1+(1−1/n)E.
Conclusion: Each independently sampled index hits the unique target with probability 1/n. If E is the expected number of comparisons including the successful comparison, E=1+(1−1/n)E, giving E=n, A. Resampling already examined positions is allowed; this is not a random permutation scan.
For procedure A(n), if n≤2 return 1; otherwise return A(⌈√n⌉). Which listed bound best describes its running time? (A) O(n); (B) O(log n); (C) O(log log n); (D) O(1).
Your answer
Answer & solution
Answer: C (no official key was published)
Step 1: Take logarithms of the argument shrinkage.
Step 2: Let m=log₂n. Taking a square root approximately halves m, so the recursion needs about log₂m halvings to make m constant. Therefore the number of constant-work calls is Θ(log log n). This count concerns runtime, not the returned value, which is always 1. Arbitrary-precision root computation would require a different per-call cost model.
Conclusion: Ignoring integer rounding initially, after k calls the argument is n1/2^k. It becomes bounded once 2k is of order log n, so the recursion depth is Θ(log log n). Ceiling rounding changes only constants, and the small integer arguments reach the base case. With constant-time root/rounding operations per call, C is the tight listed growth bound, even though looser O(n) and O(log n) bounds are also true.
A weight-balanced binary tree is defined so that, at every node, the left subtree’s node count is at least half and at most twice the right subtree’s count. Which expression best describes its maximum possible height with n nodes, counting nodes along the root-to-farthest-leaf path? (A) log₂ n; (B) log₂⁄₃ n; (C) log₃ n; (D) log₃⁄₂ n.
Your answer
Answer & solution
Answer: D as the standard growth-bound expression (no official key was published)
Step 1: Use the heavier child on a deepest path.
Step 2: If child sizes are a≥b, the weight constraint gives a≤2b. Since a+b=n−1, this implies a≤2(n−1)/3. Repeating the inequality along a path yields geometric shrinkage and a logarithmic height. Integer rounding prevents the option from being an exact height formula; its role is to express the extremal shrinkage factor rather than a literal answer for every small n.
Conclusion: A child subtree contains at most 2(n−1)/3 nodes. Following a deepest branch therefore shrinks the remaining size by at least a constant factor 3/2, yielding height at most log3/2n+O(1). Maximally skewed admissible weight splits attain the same leading logarithmic growth, so D is the conventional expression. The displayed logarithm is a growth bound, not an exact integer height for every n; rounding and admissible tree sizes matter.
How many states does the smallest finite automaton need to accept all strings whose lengths are divisible by 3? (A) 2; (B) 3; (C) 4; (D) 5.
Your answer
Answer & solution
Answer: B (no official key was published)
Step 1: Explain both construction and minimality.
Step 2: Label states 0,1,2 and send each state to its successor modulo 3 for every input symbol. Start and accept at 0. To distinguish residues r≠s, append a word of length(3−r) mod3: the state r accepts afterward and s does not. Thus no two residue states can be merged in a deterministic automaton.
Conclusion: Use three states for the input length modulo 3, advance the residue on every symbol, and accept residue 0. The three residues are distinguishable: append a length that brings one chosen residue to 0; it does not bring a different residue to 0. Thus a minimal DFA has 3 states, B, over a nonempty alphabet.
Which statement is true? (A) The complement of a recursive language is recursive. (B) The complement of a recursively enumerable language is recursively enumerable. (C) The complement of a recursive language is either recursive or recursively enumerable. (D) The complement of a context-free language is context-free.
Your answer
Answer & solution
Answer: A; C is also true with inclusive or (no official key was published)
Step 1: Separate mathematical closure from multiple-choice wording.
Step 2: A recursive decider halts on every input; reversing its output gives another total decider. A recognizer for an arbitrary RE language need not halt on nonmembers, so merely reversing its states is not a complement recognizer. Option C nevertheless remains true as a weak inclusive disjunction because its first alternative already holds; it is not made false simply by being less informative than A.
Conclusion: A decider always halts, so swapping its accept and reject answers decides the complement. Thus A is true. Recursive languages are also recursively enumerable, making C’s printed claim that the complement is either recursive or recursively enumerable true as an inclusive disjunction as well. If C intends recursive or merely-RE-but-not-recursive, its imprecise wording is hiding that distinction. General RE languages are not closed under complement (otherwise dovetailing both recognizers decides every RE language), and CFLs are not closed under complement. A is the strongest precise statement, but the literal single-choice options overlap.
Similar questions5 more → · asked again: GATE 2008, Q22
Identifying a Newton iteration
Numerical Methods
Tap to enlarge
The Newton–Raphson iteration Xₙ₊₁ = Xₙ/2 + 3/(2Xₙ) can solve which equation? (A) X²=3; (B) X³=3; (C) X²=2; (D) X³=2.
Your answer
Answer & solution
Answer: A (no official key was published)
Step 1: Derive the Newton step from the candidate equation.
Step 2: For x²−3=0, derivative 2x gives x_next=x−(x²−3)/(2x). Splitting the fraction gives x−x/2+3/(2x)=x/2+3/(2x). A cubic would instead involve a derivative 3x² and a2x/3 term, so it cannot produce the displayed iteration.
Conclusion: For g(x)=x²−3, Newton’s formula is x−g(x)/g′(x)=x−(x²−3)/(2x)=x/2+3/(2x). This is the displayed iteration, so it solves x²=3, A, with a suitable nonzero initial value.
Four fair coins are tossed together. What is the probability of obtaining at least one head and at least one tail? (A) 1/16; (B) 1/8; (C) 7/8; (D) 15/16.
Your answer
Answer & solution
Answer: C (no official key was published)
Step 1: Count the complement event.
Step 2: Failure to have both outcomes means either no heads, namely TTTT, or no tails, namely HHHH. Each sequence has probability(1/2)4=1/16, and they are disjoint. Subtract their total 1/8 from one to obtain 7/8. Counting only one exceptional sequence would incorrectly give 15/16.
Conclusion: The16 equally likely outcomes exclude only HHHH and TTTT. Therefore P(at least one head and one tail)=1−2/16=7/8, C, assuming the four fair tosses are independent.
Let S be the empty binary relation on A={1,2,3}. Which description applies? (A) Neither reflexive nor symmetric; (B) Symmetric and reflexive; (C) Transitive and reflexive; (D) Transitive and symmetric.
Your answer
Answer & solution
Answer: D (no official key was published)
Step 1: Apply the quantified definitions.
Step 2: Symmetry says every(a,b) in S has(b,a) in S; there is no(a,b) to violate it. Transitivity says any(a,b),(b,c) in S imply(a,c); again no antecedent occurs. Reflexivity instead positively requires(1,1),(2,2),(3,3), all missing. Thus vacuous truth applies to the first two properties but not the third.
Conclusion: Symmetry and transitivity are implications whose antecedents require relation pairs. With no pairs both properties hold vacuously. Reflexivity fails on the nonempty set{1,2,3} because no diagonal pairs occur. Thus D.
Classify the C programming language. (A) Context-free; (B) Context-sensitive; (C) Regular; (D) Fully parsable only by a Turing machine.
Your answer
Answer & solution
Answer: B under the usual syntax-plus-static-constraints interpretation (no official key was published)
Step 1: Distinguish parsing from all static validity checks.
Step 2: A phrase-structure grammar can describe expression and statement shapes while a symbol table checks whether identifier uses agree with their declarations. The latter checks depend on context not captured by merely recognizing those shapes. The answer’s scope is this conventional language-classification question, not a claim that a context-free parser alone proves a C program fully valid or that it decides termination.
Conclusion: C includes context-dependent restrictions such as consistent declarations and uses of identifiers, beyond a context-free phrase-structure grammar. The usual classification including such static checks is context-sensitive, B. A compiler may still use a context-free parser supplemented by symbol-table analysis; this does not make all well-formed C programs a context-free syntax-only language. Runtime behavior and whether a program halts are separate from this classification.
To evaluate an expression containing no embedded function calls, which claim is correct? (A) One stack suffices. (B) Two stacks are required. (C) The number of required stacks equals the expression-tree height. (D) A Turing machine is required in the general case.
Your answer
Answer & solution
Answer: A (no official key was published)
Step 1: Walk through a one-stack evaluation.
Step 2: For postfix tokens a b + c *, push a then b, pop them and push a+b, then push c, and finally replace the top two values with(a+b)c. The same procedure handles arbitrary finite postfix expressions by induction on the expression tree. Extra stacks can help conversion or implementation, but are not inherently required for evaluation.
Conclusion: For a postfix representation, push operands and replace the required top operands by the result whenever an operator is encountered. One evaluation stack suffices for any finite expression tree without embedded calls, A. Infix parsing can use a combined stack representation or first produce postfix; two separate stacks are a convenient implementation, not a necessity.
Why can dynamic linking raise security concerns? (A) Security is dynamic. (B) The search path for dynamic libraries is not known until runtime. (C) Linking is insecure. (D) Cryptographic procedures are unavailable for dynamic linking.
Your answer
Answer & solution
Answer: B (no official key was published)
Step 1: Describe the actual attack surface.
Step 2: A loader may search directories in an order influenced by environment variables, configuration or application location. If an attacker can place a library earlier in that search, the program may execute unintended code under its privileges. Restricting search paths and validating loaded libraries addresses this risk. The problem is runtime resolution policy, not an intrinsic absence of cryptographic techniques.
Conclusion: Dynamic linking may resolve library paths at runtime. If untrusted directories or mutable search-path settings influence resolution, an unintended library can be loaded. This is the security concern described by B, not a claim that every dynamic-linking configuration is insecure or that cryptography is unavailable.
Which combination suffices to characterize a multiprogrammed operating system? Features: (i) Multiple programs may be loaded into main memory simultaneously for execution; (ii) when a program waits for an event such as I/O, another is immediately scheduled; (iii) when a program terminates, another is immediately scheduled. (A) (i); (B) (i) and (ii); (C) (i) and (iii); (D) (i), (ii), and (iii).
Your answer
Answer & solution
Answer: B as the minimal defining combination (no official key was published)
Step 1: Test the weaker feature combinations.
Step 2: Multiple resident programs alone do not ensure the CPU switches away from a waiting one. Starting another program only after termination also describes a serial batch system that wastes time during I/O. Combining residency with switching on a wait supplies the distinguishing behavior. Adding termination scheduling does not logically destroy sufficiency, which is why the minimal-feature reading must be stated rather than pretending D is an impossible system.
Conclusion: Keeping multiple programs resident, (a), and switching to another ready program when one waits, (b), permit useful CPU work while I/O proceeds: the characteristic multiprogramming behavior. Thus the minimal defining combination is B. Scheduling another job after termination, (c), occurs in ordinary serial batch processing too. Literally D contains this sufficient combination as well; the usual question asks which features distinguish the model, not all logical supersets. An available ready job is implicit in the scheduling statements.
In indexed file-block allocation, on what does the maximum possible file size depend? (A) Block size and block-address size. (B) Number of index blocks and block size. (C) Block size, number of index blocks, and block-address size. (D) None of these.
Your answer
Answer & solution
Answer: C (no official key was published)
Step 1: Track the dimensions of the capacity calculation.
Step 2: Each index block contains floor(B/p) addresses. I such blocks contain I·floor(B/p) addresses in a flat organization, and each address identifies a B-byte data block. Multiplying gives I·floor(B/p)·B bytes. Omitting address size ignores how many pointers fit, while omitting index-block count ignores how many such pointer containers are available.
Conclusion: If I index blocks of B bytes store addresses of p bytes each, a simple flat index addresses I·floor(B/p) data blocks, giving roughly IB²/p file bytes. Thus block size, index-block count and address size all affect capacity, C. Multilevel structures alter the detailed formula, not the need to account for these quantities.
Build a B⁺-tree index on STUDENT.Name. Each name occupies 8 bytes, a disk block holds 512 bytes, and an index pointer occupies 4 bytes. What is the best degree, defined as pointers per node? (A) 16; (B) 42; (C) 43; (D) 44.
Your answer
Answer & solution
Answer: C (no official key was published)
Step 1: Check the limiting integers explicitly.
Step 2: For43 pointers there are 42 keys, using 43×4+42×8=172+336=508 bytes, which fits 512. For44 pointers and 43 keys, storage is 176+344=520 bytes, which does not fit. Thus43 is the maximum under the stated layout;42 is unnecessarily conservative, and 16 leaves substantial unused space.
Conclusion: An internal node with m child pointers has m−1 separator keys. Its storage is 4m+8(m−1)=12m−8 bytes. Requiring this to fit 512 bytes gives m≤43⅓, so the largest integer fanout is 43, C. This uses the stated idealized node layout without extra header bytes;44 would need 520 bytes.
R is decomposed using functional dependencies F, and S using dependencies G. One decomposition is stated to be BCNF and the other 3NF, without identifying which. Given the closures of F and G, which test should be applied to guarantee identification? (A) Dependency preservation; (B) Lossless join; (C) BCNF definition; (D) 3NF definition.
Your answer
Answer & solution
Answer: C under the intended exclusive classification (no official key was published)
Step 1: Explain why the other tests do not identify the form.
Step 2: A lossless decomposition can be either BCNF or 3NF, and BCNF decomposition can fail to preserve dependencies. Testing only 3NF also fails because BCNF implies 3NF. The stronger BCNF determinant test directly determines whether any nontrivial dependency has a non-superkey left side. If both pass it, the original nonexclusive premise cannot distinguish them.
Conclusion: Test each resulting relation for every nontrivial projected dependency X→Y: X must be a superkey for BCNF. This direct definition gives C; neither dependency preservation nor losslessness distinguishes BCNF from 3NF in general, and every BCNF relation also satisfies 3NF. To identify exactly one decomposition, the premise must mean the other is 3NF but not BCNF. If it only says 3NF, both might be BCNF and no unique classification follows.
What a relation instance proves about dependencies
Functional Dependencies & Keys
Tap to enlarge
An instance of R(A,B,C) lists rows (1,1,1), (1,1,0), (2,3,2), (2,3,2), including the repeated displayed row. What can be concluded? (A) A functionally determines B, and B functionally determines C. (B) A functionally determines B, and B does not functionally determine C. (C) B does not functionally determine C. (D) A does not functionally determine B, and B does not functionally determine C.
Your answer
Answer & solution
Answer: C for schema-level inference (no official key was published)
Step 1: Use a counterexample to distinguish failure from confirmation.
Step 2: The two rows(1,1,1) and(1,1,0) agree on B but disagree on C, immediately witnessing failure of B→C. No displayed pair violates A→B, but an additional legal row(1,2,0) would violate it unless a schema constraint forbids that row. Observing the current sample cannot establish that prohibition. This is why schema inference selects C while instance-only testing supports the stronger conjunction B.
Conclusion: The rows with B=1 have different C values 1 and 0, disproving B→C for any schema constraint meant to hold on all legal instances containing this one. The displayed rows do satisfy A→B, but a single positive example cannot establish that dependency for all legal instances. Therefore the guaranteed schema conclusion is C. If the question instead asks only which dependencies hold on this particular instance, B’s conjunction is true too. The duplicate(2,3,2) row does not affect either observation.
A has n>0 elements. Let Nᵣ be the number of binary relations on A and N𝒻 the number of functions A→A. Express Nᵣ in terms of n.
Shared context
A is a finite set of n > 0 elements. N_r counts all binary relations on A, and N_f counts all total functions A → A.
Answer & solution
Answer: N_r = 2^(n²) (no official key was published)
1. Identify what is being counted. A binary relation on a set A is any subset R of A × A; there are no requirements such as reflexivity or symmetry in this question.
2. Count the possible ordered pairs. The first coordinate has n choices and the second also has n choices. The product rule therefore gives |A × A| = n². Reversed pairs are distinct when their coordinates differ.
3. Make an independent yes/no decision for every pair. Each of the n² pairs can be included in R or omitted. Multiplying the two choices for all pairs gives Nr = 2 × ⋯ × 2 = 2n².
4. Check the boundary case n = 1. If A = {a}, the two relations are ∅ and {(a,a)}. This agrees with 21² = 2. For n = 2 there are four possible pairs and therefore 16 relations.
A has n>0 elements. Let Nᵣ be the number of binary relations on A and N𝒻 the number of functions A→A. Express N𝒻 in terms of n.
Shared context
A is a finite set of n > 0 elements. N_r counts all binary relations on A, and N_f counts all total functions A → A.
Answer & solution
Answer: N_f = n^n (no official key was published)
1. Apply the definition of a total function. For every element x of the n-element set A, a function f:A → A must select exactly one image f(x). An element may not be left without an image, unlike an arbitrary relation.
2. Count the image choices. There are n possible values of f(x), because the codomain is also A. The images of different domain elements need not be distinct: the question counts all functions, not only injective functions.
3. Apply the product rule over the n domain elements. Independent choices give Nf = n × n × ⋯ × n = nn, with n factors.
4. Check a small example. For A = {a,b}, the ordered pair (f(a),f(b)) can be (a,a), (a,b), (b,a), or (b,b), giving 4 = 2² functions. Using n! would incorrectly discard the two constant functions.
A has n>0 elements. Let Nᵣ be the number of binary relations on A and N𝒻 the number of functions A→A. Which is larger, Nᵣ or N𝒻, for every possible n?
Shared context
A is a finite set of n > 0 elements. N_r counts all binary relations on A, and N_f counts all total functions A → A.
Answer & solution
Answer: N_r > N_f for every integer n > 0 (no official key was published)
1. Recall both counts in this leaf. For an n-element nonempty set, the number of relations is Nr = 2n², and the number of total functions A → A is Nf = nn. We must compare them for every positive integer n, not just for large n.
2. Embed the functions into the relations. Map f to its graph {(x,f(x)):x ∈ A}. Different functions differ at some input and therefore have different graphs. This is an injection into the set of binary relations, proving Nf ≤ Nr.
3. Show the inequality is strict. The empty relation is a binary relation, but it cannot be the graph of a total function on a nonempty domain. Thus there is at least one relation outside the image of that injection.
4. Conclude Nr > Nf for every n > 0, including n = 1, where the counts are 2 and 1. Algebraically, the same comparison follows from 2n > n and raising both positive sides to the power n.
On A={1,2,3}, let S={(1,2),(2,1)}. Is S irreflexive? Add as few ordered pairs as possible to make it an equivalence relation, and give the resulting relation.
Shared context
Part (a) concerns S = {(1,2),(2,1)} on A = {1,2,3}. Part (b) separately concerns the power set of {a,b}, ordered by inclusion.
Answer & solution
Answer: Irreflexive; add (1,1), (2,2), (3,3), for 3 added pairs (no official key was published)
1. Test the original relation, not the completed relation. Here A = {1,2,3} and S = {(1,2),(2,1)}. Irreflexivity means (x,x) ∉ S for every x ∈ A. None of (1,1), (2,2), (3,3) is present, so the original S is irreflexive.
2. Obtain a lower bound on the additions. Any equivalence relation must be reflexive on all of A. Therefore all three missing diagonal pairs must be added; fewer than three additions cannot work.
3. Add exactly those necessary pairs. The candidate is S′ = {(1,1),(1,2),(2,1),(2,2),(3,3)}.
4. Verify every equivalence property. Reflexivity holds because all three diagonal pairs are present. Symmetry holds because the only non-diagonal pairs, (1,2) and (2,1), occur together. Transitivity holds because the pairs on {1,2} include every ordered pair within that class, while 3 relates only to itself. A chain of related elements therefore never crosses between the classes {1,2} and {3}.
5. Three additions are both necessary and sufficient. The minimum is 3, with completed relation S′ as above. The completed relation is reflexive; irreflexivity described the starting relation only.
Let S={a,b}. Order its power set P(S) by set inclusion. Draw the Hasse diagram of the lattice (P(S),⊆).
Shared context
Part (a) concerns S = {(1,2),(2,1)} on A = {1,2,3}. Part (b) separately concerns the power set of {a,b}, ordered by inclusion.
Answer & solution
Answer: Diamond with bottom ∅, middle {a} and {b}, top {a,b} (no official key was published)
1. Enumerate the elements of the power set of S = {a,b}: ∅, {a}, {b}, and {a,b}. The order is set inclusion, not the order of writing the symbols a and b.
2. Determine the cover relations. ∅ is immediately below each singleton, and each singleton is immediately below {a,b}. Neither {a} nor {b} contains the other, so they are incomparable.
3. Draw the Hasse diagram with larger sets above smaller ones:
{a,b}
/ \
{a} {b}
\ /
∅
4. Check why there are exactly four edges. The covers are ∅ < {a}, ∅ < {b}, {a} < {a,b}, and {b} < {a,b}. A Hasse diagram omits reflexive loops and the transitive relation ∅ < {a,b}, since the latter is already represented by upward paths.
5. Confirm the lattice interpretation: any two subsets have intersection as their greatest lower bound and union as their least upper bound. For example, {a} ∧ {b} = ∅ and {a} ∨ {b} = {a,b}.
Find the eigenvalues of A with rows [1,2,34,49], [0,2,43,94], [0,0,−2,104], [0,0,0,−1].
Shared context
Part (a) asks for eigenvalues of a 4 × 4 upper-triangular matrix. Part (b) independently classifies three propositional formulas as tautologies, contradictions, or neither.
Answer & solution
Answer: 1, 2, −2, −1 (no official key was published)
All entries below the main diagonal are zero, so A is upper triangular.
2. Form λI − A. It is also upper triangular, with diagonal entries λ−1, λ−2, λ+2, and λ+1. The determinant of a triangular matrix is the product of its diagonal entries; the displayed entries above the diagonal do not contribute additional factors.
3. Compute the characteristic polynomial: det(λI − A) = (λ−1)(λ−2)(λ+2)(λ+1) = (λ²−1)(λ²−4).
4. Set the determinant to zero. Each factor supplies one eigenvalue, giving λ ∈ {1,2,−2,−1}, each with algebraic multiplicity one.
5. As a consistency check, the eigenvalues sum to 0, matching the trace 1+2−2−1. Their product is 4, matching the product of the diagonal entries and hence det(A). This leaf is supplemental linear algebra rather than one of the requested twelve subjects.
Classify the following formula as a tautology, a contradiction, or neither. Here ∨ is OR, ∧ is AND, ¬ is NOT, → is implication, and ↔ is biconditional. A ↔ (A ∨ A).
Shared context
Part (a) asks for eigenvalues of a 4 × 4 upper-triangular matrix. Part (b) independently classifies three propositional formulas as tautologies, contradictions, or neither.
Answer & solution
Answer: Tautology (no official key was published)
1. Identify the formula: A ↔ (A ∨ A). A biconditional is true exactly when the expressions on its two sides have the same truth value.
2. Apply idempotence of disjunction. Repeating a proposition does not change it: A ∨ A = A. The formula therefore becomes A ↔ A.
3. Check both assignments explicitly:
A A∨A A↔(A∨A)
F F T
T T T
4. The last column is true for every assignment, so the formula is a tautology. This is stronger than merely finding an assignment that makes it true; a contradiction would require every assignment to make it false, and a contingent formula would have both outcomes.
Classify the following formula as a tautology, a contradiction, or neither. Here ∨ is OR, ∧ is AND, ¬ is NOT, → is implication, and ↔ is biconditional. (A ∨ B) → B.
Shared context
Part (a) asks for eigenvalues of a 4 × 4 upper-triangular matrix. Part (b) independently classifies three propositional formulas as tautologies, contradictions, or neither.
Answer & solution
Answer: Neither a tautology nor a contradiction (no official key was published)
1. Identify the formula: (A ∨ B) → B. An implication is false only when its antecedent is true and its consequent is false.
2. Eliminate the implication and simplify: (A ∨ B) → B = ¬(A ∨ B) ∨ B = (¬A ∧ ¬B) ∨ B = (¬A ∨ B) ∧ (¬B ∨ B) = ¬A ∨ B.
3. Evaluate all four assignments, or equivalently use the implication’s false-case rule:
A B A∨B (A∨B)→B
F F F T
F T T T
T F T F
T T T T
4. The row A = T, B = F rules out a tautology. Any true row, such as A = F, B = F, rules out a contradiction. Therefore the formula is neither; it is contingent. In particular, a false antecedent in the first row makes the implication true, not false.
Classify the following formula as a tautology, a contradiction, or neither. Here ∨ is OR, ∧ is AND, ¬ is NOT, → is implication, and ↔ is biconditional. A ∧ ¬(A ∨ B).
Shared context
Part (a) asks for eigenvalues of a 4 × 4 upper-triangular matrix. Part (b) independently classifies three propositional formulas as tautologies, contradictions, or neither.
Answer & solution
Answer: Contradiction (no official key was published)
1. Identify the formula: A ∧ ¬(A ∨ B). For a conjunction to be true, both A and ¬(A ∨ B) would have to be true simultaneously.
2. Apply De Morgan’s law: ¬(A ∨ B) = ¬A ∧ ¬B. Substitution gives A ∧ ¬A ∧ ¬B.
3. Isolate the impossible requirement. The conjunction contains both A and ¬A, whose conjunction is false under every assignment. Multiplying by the remaining condition ¬B cannot make a false conjunction true.
4. Alternatively inspect the two cases for A. If A is false, the original outer conjunction is false immediately. If A is true, then A ∨ B is true for either value of B, so its negation is false. Both cases give false.
5. Hence the formula is a contradiction, not merely a contingent formula that happens to fail on one input.
Draw every binary tree with exactly three labeled nodes A, B, C for which preorder traversal visits C, B, A in that order.
Shared context
Find every ordered binary tree containing exactly the distinct labels A, B, C whose preorder sequence is C,B,A. Left and right child positions are distinguished.
Answer & solution
Answer: Exactly 5 ordered binary trees (no official key was published)
1. Use the first preorder symbol to fix the root. Preorder visits root, then left subtree, then right subtree. Therefore every requested tree must have C at its root.
2. Partition the two remaining nodes between C’s subtrees. The possible left/right subtree sizes are (2,0), (0,2), and (1,1). These cases exhaust the possibilities because there are exactly two nodes besides C.
3. Handle the two single-subtree cases. For sizes (2,0), B is C’s left child, and A is either B’s left child or B’s right child: two trees. For sizes (0,2), B is C’s right child, and A again has two child positions: two more trees. B must precede A because their subtree’s preorder must be B,A.
4. Handle sizes (1,1). Preorder visits the entire left subtree before the right, so the left child is B and the right child is A: one tree. Reversing those children would give C,A,B and is not allowed.
(1) C (2) C
/ /
B B
/ \
A A
(3) C (4) C
\ \
B B
/ \
A A
(5) C
/ \
B A
6. Verify each tree by reading root-left-right. Each gives C,B,A. The exhaustive subtree-size split proves that no additional ordered binary-tree shape can qualify. In explicit node(left,right) notation, with - for no child, the five trees are C(B(A(-,-),-),-), C(B(-,A(-,-)),-), C(-,B(A(-,-),-)), C(-,B(-,A(-,-))), and C(B(-,-),A(-,-)).
Rewrite f(x,y,z)=xy′+yz′ using only one complementation and one or more AND/OR operations. Draw a circuit for that expression using a single NOT gate and AND/OR gates.
Shared context
Part (a) implements f(x,y,z) = xy′ + yz′ with one complement. Part (b) independently converts a drawn three-AND/two-OR circuit to exactly six two-input NAND gates.
Answer & solution
Answer: f = (x + y) · (yz)′ (no official key was published)
1. Start from the given f(x,y,z) = xy′ + yz′. Complementing y and z separately would require two NOT operations, so that direct sum-of-products implementation does not satisfy the restriction.
2. Search for a single complemented compound expression. De Morgan’s law gives (yz)′ = y′ + z′, so one NOT gate applied after AND(y,z) can generate the required complemented combination.
4. Show that xz′ is redundant rather than dropping it without justification. Split it by y: xz′ = xz′(y+y′) = xyz′ + xy′z′. The first term is already covered by yz′; the second is covered by xy′. Absorption therefore leaves precisely xy′ + yz′.
5. Implement the verified expression f = (x+y)(yz)′. Use t1 = OR(x,y), t2 = AND(y,z), t3 = NOT(t2), then f = AND(t1,t3):
x,y ---> OR --------- t1 ---\
AND ---> f
y,z ---> AND ---> NOT -- t3 -/
6. Count the gates: one OR, two AND gates, and exactly one NOT. The complemented quantity is yz, not either individual input. An exhaustive check of all eight input combinations independently confirms the identity.
Convert the given circuit directly, without first expressing its switching function, into an equivalent circuit containing exactly six two-input NAND gates. Textual description of the given diagram: three separate two-input AND gates receive six input wires (two per gate). The first and second AND outputs feed a two-input OR gate. That OR output and the third AND output feed a final two-input OR gate, which produces the circuit output. The input wires are unlabeled in the reproduction.
Shared context
Part (a) implements f(x,y,z) = xy′ + yz′ with one complement. Part (b) independently converts a drawn three-AND/two-OR circuit to exactly six two-input NAND gates.
Answer & solution
Answer: Six two-input NAND gates with netlist N1…N6 below (no official key was published)
1. Identify the source circuit by its connections. The top, middle, and bottom two-input AND gates feed a cascade of two OR gates: the first OR combines the top two branches, and the second combines that result with the bottom branch. Label the six external wires a,b,c,d,e,f from top to bottom. These are local wire labels, not extra assumptions about their values.
2. Transform the first AND–OR section by bubble-pushing. A NAND is an AND with a complemented output. Replace the top and middle AND gates with NAND gates N1 and N2. Replace the OR they feed with NAND N4, whose effective input complements cancel those two output complements. Thus N4 has the same output as that original OR.
3. Transform the final OR in the same way. Its bottom input is supplied in complemented form by replacing the bottom AND with NAND N3. Its other input must be the complement of N4’s output, which is produced by NAND N5 with both input pins tied to N4. NAND N6 then implements the final OR through De Morgan’s law.
4. Draw and connect the complete six-gate replacement:
5. Check the physical restrictions. Gates N1–N6 are all two-input NAND gates. Tying the two inputs of N5 together implements an inverter and still uses one allowed two-input NAND gate. There are exactly six gates, no hidden NOT gates and no three-input gates. This is a local circuit transformation, without first expressing the original switching function. A separate exhaustive simulation over the 64 external input assignments confirms equivalence.
The circuit takes three-bit inputs A=a₂a₁a₀ and B=b₂b₁b₀ and produces Z=z₃z₂z₁z₀. All registers load simultaneously on falling CLOCK edges; the clock period exceeds every circuit’s settling time. The diagram has R0 (6 bits) holding b₂,a₂,b₁,a₁,b₀,a₀. A full adder takes R0’s b₀,a₀ with carry-in 0. R1 (6 bits) holds the forwarded b₂,a₂,b₁,a₁ and this adder’s carry and sum. A second full adder takes R1’s b₁,a₁ and that stored carry. R2 (5 bits) holds the forwarded b₂,a₂, the second adder’s carry and sum, and the forwarded least-significant sum. A third, unregistered full adder takes R2’s b₂,a₂ and stored carry; its carry and sum are z₃,z₂, while R2’s stored sums directly provide z₁,z₀. Initially R0, R1, R2 are all zero. For clock numbers 1 through 8, A is [110,011,111,101,000,000,000,000] and B is [101,101,011,110,000,000,000,000]. Determine the sequence of eight four-bit output values Z.
Shared context
A and B are unsigned three-bit operands. All three registers R0, R1, R2 load on the same falling clock edge. The source circuit stages three full adders and delays higher input bits and lower result bits to keep each operand pair aligned. All registers initially contain zero.
Answer & solution
Answer: 0000, 0000, 1011, 1000, 1010, 1011, 0000, 0000 (no official key was published)
1. Read the timing rule before doing arithmetic. R0, R1, and R2 load simultaneously on every falling edge. A downstream register therefore samples the old contents of the register before it, not the new value arriving during that same edge. Read Z after the final full adder has settled.
2. Follow one input pair through the circuit. Pair t enters R0 at edge t. Its low-bit sum and carry enter R1 at edge t+1. Its middle-bit sum and carry enter R2 at edge t+2, after which the last full adder produces the high sum bit and final carry. The delayed low bits complete the four-bit output. Thus the input captured at edge 1 first appears as a complete sum after edge 3.
3. Compute the first four operand sums, preserving the carry bit:
Input pair A B Decimal sum Four-bit sum
1 110 101 6+5=11 1011
2 011 101 3+5=8 1000
3 111 011 7+3=10 1010
4 101 110 5+6=11 1011
5–8 000 000 0+0=0 0000
4. Check the first sum at bit level. For 110 + 101, bit 0 gives 0+1+0 = 1, so s0=1,c1=0. Bit 1 gives 1+0+0 = 1, so s1=1,c2=0. Bit 2 gives 1+1+0 = 2, so s2=0,c3=1. The result c3s2s1s0 is 1011.
5. Apply the two-edge delay and the all-zero initial register contents. The requested sequence is:
The initial two outputs come from the zero-filled pipeline. Input pairs 7 and 8 have not yet reached the output at edge 8. Register-by-register synchronous simulation verifies all eight reported outputs.
The circuit takes three-bit inputs A=a₂a₁a₀ and B=b₂b₁b₀ and produces Z=z₃z₂z₁z₀. All registers load simultaneously on falling CLOCK edges; the clock period exceeds every circuit’s settling time. The diagram has R0 (6 bits) holding b₂,a₂,b₁,a₁,b₀,a₀. A full adder takes R0’s b₀,a₀ with carry-in 0. R1 (6 bits) holds the forwarded b₂,a₂,b₁,a₁ and this adder’s carry and sum. A second full adder takes R1’s b₁,a₁ and that stored carry. R2 (5 bits) holds the forwarded b₂,a₂, the second adder’s carry and sum, and the forwarded least-significant sum. A third, unregistered full adder takes R2’s b₂,a₂ and stored carry; its carry and sum are z₃,z₂, while R2’s stored sums directly provide z₁,z₀. What operation does this circuit implement?
Shared context
A and B are unsigned three-bit operands. All three registers R0, R1, R2 load on the same falling clock edge. The source circuit stages three full adders and delays higher input bits and lower result bits to keep each operand pair aligned. All registers initially contain zero.
Answer & solution
Answer: Pipelined unsigned three-bit binary adder, producing a four-bit sum (no official key was published)
1. Identify each arithmetic stage from the source diagram. The first full adder takes a0, b0, and carry-in 0. It produces the least significant sum bit s0 and carry c1. R1 stores those values together with the delayed higher operand bits.
2. Follow the carry to the next stage. The second full adder takes a1, b1, and that same operand pair’s carry c1. It produces s1 and c2. R2 stores these along with the delayed a2,b2 and s0.
3. Finish the sum. The last full adder takes a2,b2,c2 and outputs s2 plus the carry c3. The circuit combines these with the delayed low bits as Z = c3s2s1s0. Consequently the four-bit unsigned result is exactly A+B; the leading carry is retained rather than discarded.
4. Explain why the registers matter. They delay the remaining operand bits and previously computed low sum bits along with the carry. This keeps all four output bits associated with one input pair while different pairs occupy different stages. Without those matching delays, bits from different pairs could be mixed.
5. Identify the implementation and performance. It is a pipelined unsigned three-bit binary adder, accepting a new pair each clock and producing one four-bit sum per clock after filling. A pair captured by R0 at edge t appears at Z after edge t+2 and combinational settling. It passes through three register loads, R0, R1, R2; there are two full clock intervals between its first capture and final output. This explicit convention avoids an ambiguous bare latency number.
A 32-bit floating-point format has fields, from most to least significant: sign (1 bit), fraction (24 bits), exponent (7 bits). Sign 0 means positive and 1 negative. The binary point precedes the fraction bits. The exponent is stored in excess-64 representation, and the exponentiation base is 16. Represent decimal −7.5 as a normalized number in this format. Derive each field and give the complete representation in hexadecimal.
Shared context
The custom 32-bit format stores sign, 24-bit fraction, then 7-bit excess-64 exponent, in that order. Its numeric value is (−1)^s(F/2^24)16^(E−64); no reserved exponent encodings are specified.
Answer & solution
Answer: Sign 1; fraction 0x780000; biased exponent 65; word 0xBC000041 (no official key was published)
1. Write the numeric interpretation of this particular format. For sign bit s, unsigned 24-bit fraction integer F, and unsigned stored exponent E, the value is (−1)s × (F/224) × 16E−64. The storage order is sign, fraction, exponent, unlike IEEE 754.
2. Normalize the magnitude in radix 16. Since 7.5/16 = 0.46875 and 0.46875 = 7/16 + 8/256, we have 7.5 = 0.78₁₆ × 16¹. The leading hexadecimal fraction digit 7 is nonzero, so this is normalized. Leading zeros within that hexadecimal digit’s four binary bits are allowed in radix-16 normalization.
3. Fill each field. The value is negative, so s=1. The six-hex-digit fraction is 780000, giving F=0x780000 and fraction bits 0111 1000 0000 0000 0000 0000. The actual exponent is 1; applying excess-64 gives E=65, whose seven-bit form is 1000001.
4. Concatenate the fields without moving the exponent to the front:
Equivalently, the word is (1 << 31) | (0x780000 << 7) | 65. The fraction is shifted by seven because the exponent occupies the low seven bits.
5. Decode the candidate to verify it: −(0x780000/224) × 1665−64 = −0.46875 × 16 = −7.5 exactly. No rounding is needed because the fraction has a finite binary and hexadecimal representation.
A 32-bit floating-point format has fields, from most to least significant: sign (1 bit), fraction (24 bits), exponent (7 bits). Sign 0 means positive and 1 negative. The binary point precedes the fraction bits. The exponent is stored in excess-64 representation, and the exponentiation base is 16. Find the largest representable value and express it as the nearest power of 10.
Shared context
The custom 32-bit format stores sign, 24-bit fraction, then 7-bit excess-64 exponent, in that order. Its numeric value is (−1)^s(F/2^24)16^(E−64); no reserved exponent encodings are specified.
Answer & solution
Answer: (1 − 2^−24)16^63 ≈ 7.23700515 × 10^75; nearest power 10^76 (no official key was published)
1. Choose the sign for the largest value. The largest representable number is positive, so the sign bit must be 0. A negative sign would reduce the value rather than maximize it.
2. Maximize the fraction. A 24-bit fraction with its binary point to the left has value F/224. All fraction bits equal to 1 give F=224−1 and fraction (224−1)/224 = 1−2−24. This is normalized and is strictly less than 1; replacing it by 1 would invent an unrepresentable fraction.
3. Maximize the exponent. The seven-bit stored field ranges from 0 to 127. Because the bias is 64, its largest actual exponent is 127−64=63. The problem specifies no reserved encodings, so none are excluded as infinity or NaN.
4. Combine the fields using radix 16, not radix 2: V_max = (1−2−24)1663 = (1−2−24)2252 ≈ 7.23700515 × 1075.
5. Convert to the requested nearest power of ten. log10(V_max) = log10(1−2−24) + 63log10(16) ≈ 75.85956. Rounding the exponent to the nearest integer gives 76, hence the nearest power is 1076. The exact maximum above distinguishes the representable value from this order-of-magnitude answer.
Find array elements that conflict in a direct-mapped cache
Cache Memory
Tap to enlarge
A C program declares float A[2048], with four bytes per element and A starting at address 0x00000000. It runs on a computer with an 8-Kbyte direct-mapped data cache and 16-byte cache blocks (lines). Which array elements conflict with A[0] in the cache? Briefly justify.
Shared context
float A[2048] begins at address 0; each element occupies 4 bytes. The direct-mapped data cache has 8 Kbytes = 8192 bytes and 16-byte lines. Part (b) scans from A[2047] to A[0], starting with an empty cache and no other accesses.
Answer & solution
Answer: None; A[1], A[2], A[3] share A[0]’s block but do not conflict (no official key was published)
1. Convert sizes using the standard binary Kbyte convention. The cache holds 8×1024=8192 bytes. Dividing by the 16-byte block size gives 512 direct-mapped cache lines. Each block holds 16/4=4 array elements.
2. Derive the mapping from an array index. Since A begins at address 0, A[i] starts at address 4i. Its memory-block number is floor(4i/16)=floor(i/4). The corresponding cache-line index is floor(i/4) mod 512; the tag distinguishes blocks with that same index.
3. Find all array elements with A[0]’s index. Its block is block 0 and its cache index is 0. An index of 0 requires block number 0,512,1024,… . Within the declared array, 0≤i≤2047, so floor(i/4) ranges only from 0 to 511. Only block 0 occurs, containing A[0], A[1], A[2], A[3].
4. Distinguish sharing from conflict. A[1], A[2], A[3] are in the same memory block as A[0], so they are fetched together and coexist. They do not compete for the line or evict A[0]. A conflict requires a different memory block, hence a different tag, mapping to that line.
5. The next genuinely conflicting block would start at byte address 8192, corresponding to A[2048], which is outside the declared array. Therefore no element within A[0…2047] conflicts with A[0]. Saying merely “A[1…3] have the same cache index” is true but does not answer the eviction/conflict question correctly.
A C program declares float A[2048], with four bytes per element and A starting at address 0x00000000. It runs on a computer with an 8-Kbyte direct-mapped data cache and 16-byte cache blocks (lines). Starting with an empty cache, access each array element once in reverse order, from the last element through the first. Ignore all other data and instruction accesses. How many data-cache misses occur? Briefly justify.
Shared context
float A[2048] begins at address 0; each element occupies 4 bytes. The direct-mapped data cache has 8 Kbytes = 8192 bytes and 16-byte lines. Part (b) scans from A[2047] to A[0], starting with an empty cache and no other accesses.
Answer & solution
Answer: 512 cache misses (no official key was published)
1. Count the blocks touched. The array holds 2048 four-byte elements, so its total size is 8192 bytes. With 16-byte lines, there are 8192/16 = 512 distinct array blocks, each containing four consecutive elements.
2. Trace the first reversed block. The first access, A[2047], misses because the cache is empty and loads the entire block A[2044…2047]. The next accesses A[2046], A[2045], A[2044] therefore hit. Crossing to A[2043] causes the next miss and loads the next group of four.
3. Generalize the pattern. In every group of four reversed accesses, the first is a miss and the other three are hits. No accesses outside the array intervene. The 512 array blocks have distinct cache indices, although even a smaller cache would still preserve this immediate three-hit pattern for a single uninterrupted sequential scan.
4. Multiply the counts: misses = 512×1 = 512, hits = 512×3 = 1536, total accesses = 512+1536 = 2048. All these misses are compulsory first references, not conflict misses.
5. Reverse traversal changes which element first brings in each block, but not the number of blocks touched. A direct-mapped simulation from A[2047] down to A[0] confirms the count of 512 misses.
Fill the three blanks in this recursive C template for Towers of Hanoi: void move(int n, char A, char B, char C) { if (____) { move(____); printf("Move disk %d from pole %c to pole %c\n", n, A, C); move(____); } } The task is to supply the condition and the arguments of both recursive calls.
Shared context
Complete all three blanks of a recursive C function move(n,A,B,C), whose printed central action moves disk n from pole A to pole C. B is the spare pole.
Answer & solution
Answer: Blanks: n > 0; n−1, A, C, B; n−1, B, A, C (no official key was published)
1. Infer the parameter roles from the printed central action. move(n,A,B,C) prints a move of disk n from A to C, so A is the source, C the destination, and B the spare pole. A recursive call must preserve this source/spare/destination order even when the pole names are permuted.
2. Fill the stopping condition. For zero disks there is nothing to move. Therefore execute the body only when n > 0. Using n > 1 would incorrectly skip the required single-disk move.
3. Clear the largest disk. Before disk n can move from A to C, the n−1 disks above it must move from A to B with C available as spare. In the function’s argument order this is move(n−1,A,C,B).
4. Move the largest disk, then restore the smaller tower above it. The printed action moves disk n from A to C. Next transfer the n−1 disks from B to C using A as spare, which is move(n−1,B,A,C).
5. The completed valid C function is:
void move(int n, char A, char B, char C)
{
if (n > 0) {
move(n - 1, A, C, B);
printf("Move disk %d from pole %c to pole %c\n", n, A, C);
move(n - 1, B, A, C);
}
}
Use the standard stdio declaration for printf in a complete program. The three blanks, in order, are n > 0; n−1,A,C,B; and n−1,B,A,C.
6. Check n=2 explicitly. The execution moves disk 1 A→B, disk 2 A→C, and disk 1 B→C. Each move is legal and the final tower is on C. For general n, assuming both smaller recursive transfers are legal establishes correctness by induction. The move count satisfies T(0)=0 and T(n)=2T(n−1)+1, hence T(n)=2n−1. Simulation verifies legality and final placement for n=1,…,8.
Complete a template computing all-pairs shortest-path lengths in a directed graph G. Its n×n adjacency matrix A has A[i,j]=1 for an edge i→j and 0 otherwise. Initialization loops over i=1..n and j=1..n and executes: if A[i,j]=0 then P[i,j]=____ else P[i,j]=____; The algorithm then has nested loops, in this exact order: for i=1..n, for j=1..n, for k=1..n, executing: P[____,____] = min{____,____}; Copy and complete the initialization line so that the algorithm is correct.
Shared context
For a directed unweighted graph, binary adjacency A[i,j] equals 1 for an edge i → j and 0 otherwise. Initialize a distance table P and run the printed loops in the order i outermost, then j, then k. Standard shortest-path distances permit an empty path of length 0.
Answer & solution
Answer: For i≠j: ∞ if A[i,j]=0, otherwise 1; for i=j: 0 (no official key was published)
1. Fix the graph interpretation. The adjacency entries are binary: A[i,j]=1 means a directed edge i→j of length 1, and A[i,j]=0 means that edge is absent.
2. Handle distinct vertices before any intermediate vertices are allowed. If i≠j and A[i,j]=1, the one-edge path has length 1, so initialize P[i,j]=1. If i≠j and A[i,j]=0, no direct path is available yet, so initialize P[i,j]=∞. Zero would incorrectly claim a free path between disconnected vertices.
3. Handle the diagonal separately. Standard shortest-path distance permits the empty path, so P[i,i]=0 whether or not A[i,i] contains a self-loop. A length-1 self-loop cannot beat that empty path.
4. Fill the original two blanks with expressions that incorporate these cases, without changing the printed outer condition:
if A[i,j] = 0 then P[i,j] = (0 if i = j else ∞)
else P[i,j] = (0 if i = j else 1);
Equivalently, initialize off-diagonal entries to ∞/1 and then explicitly set each P[i,i] to 0.
5. Check a small graph. If the only edge is 1→2, initialization gives rows [0,1] and [∞,0]. This correctly represents the direct path, lack of a reverse path, and both empty paths.
6. State the convention caveat. The abbreviated fills “∞,1” alone make a diagonal entry the length of a shortest nonempty closed walk, or ∞ if none exists, rather than the standard distance 0. That abbreviation suffices only if diagonal results are excluded or that other convention is intended. The conditional fill above is correct for every vertex pair under the standard convention and respects the template’s two blanks.
Complete the Floyd–Warshall update for the given loop order
Graph Algorithms
Tap to enlarge
Complete a template computing all-pairs shortest-path lengths in a directed graph G. Its n×n adjacency matrix A has A[i,j]=1 for an edge i→j and 0 otherwise. Initialization loops over i=1..n and j=1..n and executes: if A[i,j]=0 then P[i,j]=____ else P[i,j]=____; The algorithm then has nested loops, in this exact order: for i=1..n, for j=1..n, for k=1..n, executing: P[____,____] = min{____,____}; Copy and complete the line in the algorithm’s triple loop so that the algorithm is correct.
Shared context
For a directed unweighted graph, binary adjacency A[i,j] equals 1 for an edge i → j and 0 otherwise. Initialize a distance table P and run the printed loops in the order i outermost, then j, then k. Standard shortest-path distances permit an empty path of length 0.
Answer & solution
Answer: P[j,k] = min(P[j,k], P[j,i] + P[i,k]) (no official key was published)
1. Respect the printed loop order: i is outermost, j is next, and k is innermost. In Floyd–Warshall the outer loop must identify the newly allowed intermediate vertex. Therefore i is that intermediate, j is the source, and k the destination.
2. State the invariant. Before outer iteration i, P[j,k] is the shortest distance from j to k using only vertices 1,…,i−1 as internal vertices. Initialization supplies paths with no internal vertices: 0 on the diagonal, 1 for a direct edge, and ∞ otherwise.
3. Split paths into two exhaustive cases. A shortest path allowed after iteration i either avoids i internally, in which case its best length is the old P[j,k], or passes through i, in which case it can be split into a j→i portion and an i→k portion. Their best combined length is P[j,i]+P[i,k]. Nonnegative unit weights let us choose a shortest path without repeated positive-length cycles.
4. Take the better candidate and fill the line as:
P[j,k] = min(P[j,k], P[j,i] + P[i,k]);
For example, if the current j→k value is ∞ while P[j,i]=2 and P[i,k]=3, the update discovers a path of length 5. If P[j,k] were already 4, the minimum would retain 4.
5. Verify in-place and final correctness. During iteration i, the zero diagonal means an update through i does not lower the distances into or out of i; the in-place recurrence therefore preserves the invariant. After i=n, all vertices are allowed internally, so the table gives every shortest-path distance. Interpret ∞+x as ∞, or guard finite arithmetic against overflow.
6. Avoid a loop-order substitution error. The familiar form P[i,j]=min(P[i,j],P[i,k]+P[k,j]) assumes k is outermost. Under the source’s i,j,k loop order, using that form would generally be incorrect. Exhaustive comparison with BFS on every directed three-vertex graph, including self-loops, verifies the completed initialization and the stated j,k update.
Complete a template computing all-pairs shortest-path lengths in a directed graph G. Its n×n adjacency matrix A has A[i,j]=1 for an edge i→j and 0 otherwise. Initialization loops over i=1..n and j=1..n and executes: if A[i,j]=0 then P[i,j]=____ else P[i,j]=____; The algorithm then has nested loops, in this exact order: for i=1..n, for j=1..n, for k=1..n, executing: P[____,____] = min{____,____}; Complete the running-time expression O(____).
Shared context
For a directed unweighted graph, binary adjacency A[i,j] equals 1 for an edge i → j and 0 otherwise. Initialize a distance table P and run the printed loops in the order i outermost, then j, then k. Standard shortest-path distances permit an empty path of length 0.
Answer & solution
Answer: O(n³), more precisely Θ(n³) (no official key was published)
1. Count initialization work. There are n choices for the first index and n for the second, so initializing P visits n² entries. Each requires only a constant-time case selection and assignment, giving Θ(n²).
2. Count the algorithm’s updates. The source has three nested loops, over i, j, and k, each running from 1 to n. There is no data-dependent early termination. Thus the innermost statement executes n×n×n = n³ times.
3. Count work per update. Reading two candidate distances, adding, comparing with the old entry, and writing the minimum take constant time under the usual RAM model with constant-time distance arithmetic. Therefore the update phase costs Θ(n³).
4. Combine the phases. Θ(n²)+Θ(n³)=Θ(n³), since the cubic term dominates as n grows. The requested big-O blank is n³, so the answer is O(n³); the tighter bound is Θ(n³).
5. Keep time and space distinct. The distance table contains n² entries and uses Θ(n²) space. Its space requirement does not reduce the cubic number of updates, and an adjacency-matrix input does not make this particular triple-loop implementation linear in the number of edges.
Original13(a): For integer n≥2, count ordered expressions of n as a sum of two positive integers, not necessarily distinct. For n = 3, 1+2 and 2+1 are different expressions. Give only the answer without explanation.
Answer & solution
Answer: n−1 (no official key was published)
There are n−1 ordered pairs: choose the first summand from 1 through n−1, after which the second is n minus that choice. Equivalently, choose one of the n−1 gaps between n unit objects as a separator. The example counts 1+2 and 2+1 separately, so these are ordered compositions, not unordered partitions.
Original13(b): For integer n≥3, count ordered expressions of n as a sum of three positive integers, allowing repeats. For n=4 the three expressions are 1+1+2, 1+2+1, 2+1+1. Give only the answer without explanation.
Answer & solution
Answer: C(n−1,2) = (n−1)(n−2)/2 (no official key was published)
Place two separators in distinct gaps among n unit objects. There are n−1 gaps, and choosing two gives C(n−1,2)=(n−1)(n−2)/2 ordered positive triples. For n=4 these are (1,1,2), (1,2,1), and (2,1,1).
Original13(c): For n≥k≥1, count ordered expressions of n as a sum of k positive integers, allowing repeated summands. Give only the answer without explanation.
Answer & solution
Answer: C(n−1,k−1) (no official key was published)
For n≥k≥1, separate a row of n unit objects into k nonempty consecutive groups by choosing k−1 of its n−1 internal gaps. Group lengths give an ordered k-tuple of positive integers summing to n, and every such tuple yields exactly one separator choice. Therefore the count is C(n−1,k−1). This also gives one composition when n=k or k=1.
Prove undecidable the language of machines M that halt and output 1 on every input, by reducing the known halting problem {⟨M′,x⟩:M′ halts on x}. Construct M from M′,x. Original14(a): On input w, describe the first main step M performs.
Answer & solution
Answer: Ignore input w and simulate M′ on the hard-coded input x. (no official key was published)
Given a halting-problem instance ⟨M′,x⟩, effectively construct a machine M with M′ and x embedded in its finite description. On arbitrary input w, ignore w and simulate M′ on x. If that computation never halts, this simulation never proceeds to the next step. The construction itself does not need to decide whether M′ halts.
Reduction machine: output after the simulation halts
Decidability & Computability
Tap to enlarge
Prove undecidable the language of machines M that halt and output 1 on every input, by reducing the known halting problem {⟨M′,x⟩:M′ halts on x}. Construct M from M′,x. Original14(b): Describe its second step, depending on the first step’s outcome.
Answer & solution
Answer: If the simulation halts, output 1 and halt; otherwise continue simulating forever. (no official key was published)
After the simulation of M′ on x terminates, discard its result, output 1, and halt. The branch is triggered by any halting outcome of M′, not only acceptance or output 1. If M′ fails to halt, M never reaches this branch on any input w.
Prove undecidable the language of machines M that halt and output 1 on every input, by reducing the known halting problem {⟨M′,x⟩:M′ halts on x}. Construct M from M′,x. Original14(c): State the key equivalence relating M on arbitrary w to M′ on x.
Answer & solution
Answer: M′ halts on x iff M halts and outputs 1 on every input. (no official key was published)
If M′ halts on x, its simulation finishes regardless of the ignored input w, and M then halts with output 1 for every w. If M′ does not halt on x, M loops on every w, so its description is not in the target language. Thus ⟨M′,x⟩ belongs to HALT iff the computably constructed ⟨M⟩ belongs to {⟨N⟩: N halts and outputs 1 on every input}. A decider for the target language would decide HALT by constructing M and invoking that decider, which is impossible. Hence the target language is undecidable.
Placement schema COMPANY(cname,clocation), STUDENT(srollno,sname,sdegree), INTERVIEW(cname,srollno,idate), OFFER(cname,srollno,osalary). Keys: cname; srollno; (cname,srollno) for each remaining relation. cname and clocation are company name and location; srollno, sname and sdegree are student roll number, name and degree program. Interviews record company/student/date; offers record salary for successful interviews. Original15(a)(i): Using only relational algebra join, selection, projection, union and difference, list roll numbers and names of students interviewed at least once but receiving no offer.
Answer & solution
Answer: π_{srollno,sname}(STUDENT ⋈ (π_{srollno}(INTERVIEW) − π_{srollno}(OFFER))) (no official key was published)
Let I=π_{srollno}(INTERVIEW) and O=π_{srollno}(OFFER). I−O contains exactly the students with at least one interview and no offer at all. Join this one-column relation to STUDENT on srollno and project srollno,sname: π_{srollno,sname}(STUDENT ⋈ (π_{srollno}(INTERVIEW) − π_{srollno}(OFFER))). Only the permitted join, projection and difference operators are needed. Relational-algebra projection removes duplicates, so repeated interviews do not repeat students.
Placement schema COMPANY(cname,clocation), STUDENT(srollno,sname,sdegree), INTERVIEW(cname,srollno,idate), OFFER(cname,srollno,osalary). Keys: cname; srollno; (cname,srollno) for each remaining relation. cname and clocation are company name and location; srollno, sname and sdegree are student roll number, name and degree program. Interviews record company/student/date; offers record salary for successful interviews. Original15(a)(ii): Using only join, selection, projection, union and difference, list roll numbers and names of interviewed students receiving an offer from every company that interviewed them.
Answer & solution
Answer: π_{srollno,sname}(STUDENT ⋈ (π_{srollno}(INTERVIEW) − π_{srollno}(π_{cname,srollno}(INTERVIEW) − π_{cname,srollno}(OFFER)))) (no official key was published)
First form the interviewed company–student pairs I=π_{cname,srollno}(INTERVIEW) and offered pairs O=π_{cname,srollno}(OFFER). The difference I−O contains precisely the interviews not followed by an offer from that same company. Its student projection is the disqualified set. Therefore: π_{srollno,sname}(STUDENT ⋈ (π_{srollno}(INTERVIEW) − π_{srollno}(I−O))). Expanding the abbreviations gives the expression in the derived answer, using only join, projection and difference. Starting with students who appear in INTERVIEW excludes students with no interviews, rather than admitting them by vacuous truth. Receiving some offer is insufficient: every interviewed company must be covered.
Placement schema COMPANY(cname,clocation), STUDENT(srollno,sname,sdegree), INTERVIEW(cname,srollno,idate), OFFER(cname,srollno,osalary). Keys: cname; srollno; (cname,srollno) for each remaining relation. cname and clocation are company name and location; srollno, sname and sdegree are student roll number, name and degree program. Interviews record company/student/date; offers record salary for successful interviews. Original15(b): Write SQL listing each degree program with more than five students offered jobs, together with the program name and average offered salary of its students.
Answer & solution
Answer: SELECT S.sdegree, AVG(O.osalary) AS avg_offered_salary FROM STUDENT S JOIN OFFER O ON O.srollno=S.srollno GROUP BY S.sdegree HAVING COUNT(DISTINCT S.srollno)>5; (no official key was published)
A query under the usual interpretation of average offered salary, averaging the offer records, is: SELECT S.sdegree, AVG(O.osalary) AS avg_offered_salary FROM STUDENT AS S JOIN OFFER AS O ON O.srollno=S.srollno GROUP BY S.sdegree HAVING COUNT(DISTINCT S.srollno)>5; The join associates each offer with its student's degree. COUNT(DISTINCT S.srollno) implements more than five students, not more than five offers: the composite OFFER key permits several companies to offer jobs to one student. AVG(O.osalary) averages the offered salary values within the degree group. No JOIN to INTERVIEW is needed, because OFFER already identifies successful candidates.
Lossless decomposition through a common determinant
Normalization & Decomposition
Tap to enlarge
R(L,M,N,O,P) has M→O,NO→P,P→L,L→MN and is decomposed into R1(L,M,N,P),R2(M,O). Original16(a): Is the decomposition lossless? Explain.
Answer & solution
Answer: Yes, the decomposition is lossless. (no official key was published)
Step through it (2 steps)
The source dependencies are M→O, NO→P, P→L, and L→MN. The components are R1(L,M,N,P) and R2(M,O), with intersection {M}. Since M→O, their intersection functionally determines all of R2. The binary lossless-join criterion therefore holds: (R1∩R2)→R2 is implied by the dependencies. Consequently joining the two projections of any legal instance recreates the original relation without spurious tuples.
R(L,M,N,O,P) has M→O,NO→P,P→L,L→MN and is decomposed into R1(L,M,N,P),R2(M,O). Original16(b): Is it dependency-preserving? If not, list dependencies not preserved.
Answer & solution
Answer: No; NO→P is not preserved. (no official key was published)
Step through it (4 steps)
M→O is enforceable within R2, and P→L and L→MN within R1. The projection onto R1 also contains MN→P: M supplies O, then NO→P applies. Nevertheless NO→P cannot be recovered from the union of the projected dependency sets. In R1 no nontrivial dependency has determinant contained in {N}, since N+ under the original set is just {N}; in R2, O alone likewise determines nothing new. Thus the closure of {N,O} under the projected dependencies remains {N,O}, and does not contain P. Of the given dependencies, precisely NO→P is lost. A concrete locally valid join illustrates the loss. Let R1 contain (L1,M1,n,P1) and (L2,M2,n,P2), with distinct Li,Mi,Pi, and let R2 contain (M1,o),(M2,o). Each component satisfies all its projected dependencies. Their join has the same (N,O)=(n,o) with different P values, violating NO→P.
R(L,M,N,O,P) has M→O,NO→P,P→L,L→MN and is decomposed into R1(L,M,N,P),R2(M,O). Original16(c): Determine the highest normal form of each decomposed relation.
Answer & solution
Answer: Both R1 and R2 are in BCNF. (no official key was published)
Step through it (2 parts)
For R1(L,M,N,P), the candidate keys are {L}, {P}, and {M,N}. L gives M,N and then P using M→O and NO→P; P gives L and hence the rest; MN gives O and then P,L. Any determinant containing L or P is therefore a superkey. A determinant containing neither is a subset of {M,N}; neither M nor N alone determines an additional R1 attribute, whereas MN is a key. Hence every nontrivial projected dependency has a superkey determinant, so R1 is BCNF. In R2(M,O), M is the key and the only essential nontrivial dependency is M→O, so R2 is also BCNF. This does not imply dependency preservation; the lost NO→P constraint still requires checking across components.
Original17(a): Fill Constant or Variable in four search-time cells: X1 successful B-tree, X2 unsuccessful B-tree, X3 successful B+tree, X4 unsuccessful B+tree. Constant means independent of which key is sought in a fixed tree, not asymptotically O(1); Variable means depending on that key. Successful means the key exists; unsuccessful means it is absent.
Answer & solution
Answer: X1=Variable; X2=Constant; X3=Constant; X4=Constant. (no official key was published)
Interpret search time as the number of tree levels or disk pages visited in a fixed tree, with record retrieval in a B+ tree proceeding to its leaf. A successful B-tree search may stop at the root, an internal node, or a leaf, depending on where its key resides; X1 is Variable. An unsuccessful B-tree search reaches a leaf, and all leaves have equal depth, so X2 is Constant. B+ tree records are located at leaves, so both successful and unsuccessful record searches traverse the fixed-height root-to-leaf path; X3 and X4 are Constant. Here Constant means independent of which key is searched in that tree, not O(1) as the database grows.
R(A,B)={(1,2),(2,3),(2,4),(4,5),(6,7),(6,8),(9,10)}. View V is SELECT R1.A,R2.B FROM R R1,R R2 WHERE R1.B=R2.A. Original17(b)(i): Find the current contents of V.
Answer & solution
Answer: V={(1,3),(1,4),(2,5)}. (no official key was published)
The view combines a tuple (u,v) in the first copy of R with a tuple (v,w) in the second and returns (u,w), so it enumerates two-edge paths. For R={(1,2),(2,3),(2,4),(4,5),(6,7),(6,8),(9,10)}, the paths 1→2→3 and 1→2→4 yield (1,3),(1,4), while 2→4→5 yields (2,5). No other second component matches a first component. Thus V contains exactly those three tuples. They are distinct, so SQL bag semantics and set semantics give the same contents for this instance.
Incremental self-join view after two inserted tuples
SQL & Queries
Tap to enlarge
R(A,B)={(1,2),(2,3),(2,4),(4,5),(6,7),(6,8),(9,10)}. View V is SELECT R1.A,R2.B FROM R R1,R R2 WHERE R1.B=R2.A. Original17(b)(ii): Insert(2,11),(11,6) into R. Which additional tuples enter V?
Answer & solution
Answer: Additional tuples: {(1,11),(2,6),(11,7),(11,8)}. (no official key was published)
Let ΔR={(2,11),(11,6)}. A newly created length-two path must use at least one new edge, so inspect R⋈ΔR, ΔR⋈R, and ΔR⋈ΔR. The existing edge 1→2 followed by 2→11 adds (1,11). The new edge 11→6 followed by existing 6→7 or 6→8 adds (11,7),(11,8). The two new edges together form 2→11→6 and add (2,6). These four tuples are the additions; the original three remain. Longer paths such as 1→2→11→6 do not qualify, because this view joins exactly two copies of R rather than taking a transitive closure.
Original18(a): Draw and label the process-state transitions for an OS with states created,ready,running,blocked(sleep/wait),terminated and only non-preemptive scheduling.
Answer & solution
Answer: Created→Ready (admit); Ready→Running (dispatch); Running→Blocked (wait); Blocked→Ready (event completes); Running→Terminated (exit). (no official key was published)
Use these five labelled transitions: Created --admit--> Ready --dispatch--> Running --exit--> Terminated Running --I/O request or event wait--> Blocked Blocked --I/O or awaited event completes--> Ready The scheduler selects a ready process when the CPU becomes available. There is no timer/preemption edge from Running to Ready in the conventional non-preemptive diagram. Waking a blocked process makes it ready; it does not immediately displace the running process. A system explicitly supporting voluntary yield could add a Running→Ready edge labelled yield, but no such extra mechanism is required by the question.
Atomic TEST_AND_SET(int*x) performs A1:y=*x; A2:*x=1; A3:return y. Shared mutex initially 0. Entry/exit templates: void enter_cs(){while(blank);} void leave_cs(){blank;} Original18(b)(i): Fill the while condition in enter_cs(){while(blank);} and the statement in leave_cs(){blank;} using this instruction.
Answer & solution
Answer: enter_cs: while (TEST_AND_SET(&mutex)) { } ; leave_cs: mutex=0; (no official key was published)
Use the shared lock variable mutex, initially zero: void enter_cs(void) { while (TEST_AND_SET(&mutex)) { } } void leave_cs(void) { mutex = 0; } TEST_AND_SET atomically returns the old value and writes one. Exactly one contender observing the unlocked zero receives zero and leaves the loop; later contenders receive one and keep spinning. Releasing the lock restores zero for a future acquisition. This is pseudocode for the given atomic primitive and a shared lock, not a claim that an ordinary non-atomic C integer and a handwritten function implement modern concurrent-C synchronization. The source's hyphenated function names are rendered with underscores to make the names valid C identifiers.
Atomic TEST_AND_SET(int*x) performs A1:y=*x; A2:*x=1; A3:return y. Shared mutex initially 0. Entry/exit templates: void enter_cs(){while(blank);} void leave_cs(){blank;} Original18(b)(ii): For the resulting spinlock entry/exit solution, determine whether it is deadlock-free and starvation-free.
Answer & solution
Answer: Deadlock-free under the usual progress assumptions; not starvation-free. (no official key was published)
With atomic TEST_AND_SET, one contender acquires any free lock, and a holder that finishes its finite critical section releases the lock. Under the usual assumptions that a holder continues to receive execution time and eventually exits, the lock is deadlock-free: processes do not remain mutually blocked with no one able to proceed. It is not starvation-free, since a waiting process is not assigned a turn. Each time the lock is released another contender can acquire it first, so one process can lose indefinitely even while other processes keep making progress. As with any spinlock, a scheduler that prevents the holder from running can itself defeat progress; deadlock-freedom is not an unconditional scheduling guarantee.
Atomic TEST_AND_SET(int*x) performs A1:y=*x; A2:*x=1; A3:return y. Shared mutex initially 0. Entry/exit templates: void enter_cs(){while(blank);} void leave_cs(){blank;} Original18(b)(iii): If the three TEST_AND_SET steps were not atomic, give an interleaving violating mutual exclusion.
Answer & solution
Answer: Both processes can read mutex=0 before either sets it, so both enter. (no official key was published)
Initially mutex=0. Split TEST_AND_SET into the source steps A1: y=*x; A2: *x=1; A3: return y. Interleave two processes as follows: 1. P executes A1 and stores local yP=0. 2. Q executes A1 and stores local yQ=0. 3. P executes A2, writing mutex=1. 4. Q executes A2, also writing mutex=1. 5. P executes A3 and returns its saved zero; its while condition is false and it enters the critical section. 6. Q executes A3 and returns its saved zero; it also enters before P leaves. The final shared value one does not distinguish the two prior reads. Atomicity must cover the read and write as one indivisible operation.
Two-level address translation with equal index widths
Virtual Memory & Paging
Tap to enlarge
Virtual and physical addresses are 32 bits, byte addressed, page size 4 KB, two-level page tables with equal index widths, each entry 4 bytes. Original19(a): Draw how a virtual address translates to a physical address.
Answer & solution
Answer: Virtual address: 10-bit outer index | 10-bit inner index | 12-bit offset; physical address: 20-bit frame number | 12-bit offset. (no official key was published)
A 4 KiB page has 212 bytes, so the low 12 address bits are the unchanged page offset. The remaining 32−12=20 virtual-page bits split equally into two 10-bit indices. The translation is: VA[31:22] --index--> first-level table --second-level table base VA[21:12] --index into that table--> second-level entry --20-bit physical frame number PA = (physical frame number << 12) | VA[11:0]. More explicitly, the first entry is at first_table_base + 4·VA[31:22]; it identifies the second-level table. The second entry is at second_table_base + 4·VA[21:12]; it identifies the data page frame. Validity and protection flags are checked along the way; absent or disallowed mappings fault. The diagram describes a successful translation and does not require a TLB assumption.
Virtual and physical addresses are 32 bits, byte addressed, page size 4 KB, two-level page tables with equal index widths, each entry 4 bytes. Original19(b): How many page-table entries fit in one page?
Answer & solution
Answer: 1024 entries. (no official key was published)
Step through it (7 steps)
Each page contains 4 KiB=4096 bytes and each page-table entry occupies 4 bytes. Thus one page holds 4096/4=1024=210 entries, matching either 10-bit index. A first-level table and each populated second-level table can each occupy one page.
Virtual and physical addresses are 32 bits, byte addressed, page size 4 KB, two-level page tables with equal index widths, each entry 4 bytes. Original19(c): How many bits in each entry remain for protection/other information?
Answer & solution
Answer: 12 bits per page-table entry. (no official key was published)
Step through it (8 steps)
There are 232 addressable physical bytes and frames of 212 bytes, so a physical frame number needs 32−12=20 bits. Each page-table entry is 4 bytes=32 bits, leaving 32−20=12 bits for valid, protection, reference, dirty, or other information. The page offset is supplied by the virtual address and is not separately stored in each entry. First-level entries likewise point to page-aligned second-level tables.
Circular buffer size 100, indices first=last=0, semaphores b_full=0,b_empty=100. Producer repeats produce item; p1 blank; put into buf[first]; first=(first+1)%100; p2 blank. Consumer repeats c1 blank; take from buf[last]; last=(last+1)%100; c2 blank; consume item. Original20(a): Fill p1,p2,c1,c2 for one producer and one consumer.
Answer & solution
Answer: p1: wait(b_empty); p2: signal(b_full); c1: wait(b_full); c2: signal(b_empty). (no official key was published)
Complete the source placeholders with: p1: wait(b_empty); p2: signal(b_full); c1: wait(b_full); c2: signal(b_empty); The producer reserves an empty slot before writing buf[first] and advancing first, then announces a full slot. The consumer reserves a full slot before reading buf[last] and advancing last, then announces an empty slot. With b_empty initially BUFSIZE=100 and b_full initially zero, counting semaphores prevent overrun and underrun. Only one producer updates first and only one consumer updates last, so no additional mutex is needed for this single-producer/single-consumer algorithm under the usual atomic semaphore and memory-visibility assumptions. A semaphore count can exclude a reserved slot temporarily while its operation is in progress; b_empty+b_full need not equal BUFSIZE at every instruction boundary.
Mutex additions for multiple producers and consumers
Synchronization & Concurrency
Tap to enlarge
Circular buffer size 100, indices first=last=0, semaphores b_full=0,b_empty=100. Producer repeats produce item; p1 blank; put into buf[first]; first=(first+1)%100; p2 blank. Consumer repeats c1 blank; take from buf[last]; last=(last+1)%100; c2 blank; consume item. Original20(b): Introduce one additional semaphore and one statement at each location: immediately after p1, before p2, after c1, before c2 so the program supports multiple producers/consumers.
Answer & solution
Answer: Initialize semaphore mutex=1; after p1 and c1 insert wait(mutex); before p2 and c2 insert signal(mutex). (no official key was published)
Add a binary semaphore mutex initialized to one. Insert wait(mutex) immediately after p1 and immediately after c1, and signal(mutex) immediately before p2 and immediately before c2. The resulting operation order is: Producer: wait(b_empty); wait(mutex); write buf[first]; advance first; signal(mutex); signal(b_full). Consumer: wait(b_full); wait(mutex); read buf[last]; advance last; signal(mutex); signal(b_empty). This serializes updates to the shared buffer and indices across all producers and consumers. Slot availability is awaited before taking the mutex. Reversing that order can deadlock, for example a consumer holding the mutex while waiting for an item prevents a producer from inserting one. Producing and consuming the actual item stay outside the mutex-protected buffer operations.
Original21(a): Construct a four-state NFA for the language (a|b)*abb over {a,b}. Specify initial/final states and every transition.
Answer & solution
Answer: Start q0, accept q3: δ(q0,a)={q0,q1}, δ(q0,b)={q0}, δ(q1,b)={q2}, δ(q2,b)={q3}; all other transitions empty. (no official key was published)
Over alphabet {a,b}, use states q0,q1,q2,q3, with q0 initial and q3 the sole accepting state. q0 has loops on a and b and an additional a-transition to q1; q1 has a b-transition to q2; q2 has a b-transition to q3; q3 has no outgoing transitions. In notation: q0 --a--> q1 --b--> q2 --b--> q3 (accept), with a,b self-loops at q0. The loop consumes an arbitrary prefix from (a|b)*, and a nondeterministic branch chooses the a beginning the final abb. Acceptance requires the whole input to end at q3, so the last three letters must be abb. Conversely every string ending in abb has such an accepting path. No epsilon transitions or extra states are needed.
Original21(b): Construct a four-state DFA for the same language (a|b)*abb; specify all transitions and accepting state.
Answer & solution
Answer: Start q0, accept q3. On (a,b): q0→(q1,q0); q1→(q1,q2); q2→(q1,q3); q3→(q1,q0). (no official key was published)
Step through it (2 parts)
Use state qj to record the length j of the longest suffix of the input seen so far that is also a prefix of abb. The four represented suffixes are empty, a, ab, abb. Start at q0 and accept only q3. The transition table is: State | a | b q0 | q1 | q0 q1 | q1 | q2 q2 | q1 | q3 q3 | q1 | q0 For example, reading a after ab or abb leaves suffix a, while reading b after abb leaves no nonempty suffix that begins abb. This invariant proves that q3 is reached at end exactly for strings ending in abb. All transitions are defined and exactly four states are used.
Grammar E→E+E | E*E | id. Original22(a): Construct all parse trees for i+j*k, where i,j,k are identifiers.
Answer & solution
Answer: Two parse trees: +(i,*(j,k)) and *(+(i,j),k), with E→id at every identifier leaf. (no official key was published)
With productions E→E+E, E→E*E, E→id, the two full parse trees are:
Tree 1, root addition:
E
├── E
│ └── id(i)
├── +
└── E
├── E
│ └── id(j)
├── *
└── E
└── id(k)
Tree 2, root multiplication
E
├── E
│ ├── E
│ │ └── id(i)
│ ├── +
│ └── E
│ └── id(j)
├── *
└── E
└── id(k)
Here id(i), id(j), and id(k) denote the id tokens with those lexemes. Both yields are i + j * k. There are exactly two trees because the root split must be at one of the two operators, and each remaining two-identifier subtree has a unique possible split. Their grouping is i+(j*k) versus (i+j)*k.
Operator precedence in the ambiguous expression grammar
Parsing & Syntax Analysis
Tap to enlarge
Grammar E→E+E | E*E | id. Original22(b): What precedence, if any, does this grammar impose on * and +?
Answer & solution
Answer: No relative precedence is specified or enforced by this grammar. (no official key was published)
Both + and * are produced by the same nonterminal E, and the grammar allows both i+(j*k) and (i+j)*k for the same token string. It therefore does not enforce multiplication-before-addition or addition-before-multiplication. Saying merely that the operators have equal precedence is also incomplete: the grammar does not enforce associativity, so it does not define a unique parse even under that description. External parser precedence declarations could resolve conflicts, but they are not part of the supplied grammar.
Grammar E→E+E | E*E | id. Original22(c): Modify the grammar to obtain exactly one parse tree per string in the same language and a nonambiguous LALR(1) grammar.
Answer & solution
Answer: E→E+T | T; T→T*F | F; F→id. (no official key was published)
One replacement grammar is
E → E + T | T T → T * F | F F → id It accepts exactly the original token language id ((+|*) id)*, without introducing parentheses or changing which token strings are allowed. The E/T levels make * bind more tightly than +, and the left-recursive productions make repeated uses of either operator associate left. Thus i+j*k has only the i+(j*k) parse. This standard expression grammar is SLR(1), and hence LALR(1); separating the levels resolves the shift/reduce ambiguity. The original grammar specified no precedence, so multiplication-before-addition and left associativity are a legitimate choice of an unambiguous interpretation, not properties already forced by that grammar.