A random variable has E[X]=5. Must some outcome have X=5, X>5, X≥5, or none of these?
Your answer
Answer & solution
Answer: C (no official key was published)
Suppose every outcome had X<5. Then Y=5−X is positive everywhere. Since a positive random variable has positive expectation, E[Y]>0, contradicting E[Y]=5−E[X]=0. Hence some outcome has X≥5. Equality need not occur: equal probabilities on 4 and 6 have mean 5 but never value 5. Nor must a value exceed 5: the constant variable X=5 is a counterexample. Thus only C is forced, assuming the stated finite expectation.
How many binary relations exist on a set of n elements? Options: n,2^n,2^(n²),none.
Your answer
Answer & solution
Answer: C (no official key was published)
A binary relation is any subset of the Cartesian product S×S. There are n choices for each coordinate, hence n² ordered pairs. Each pair independently either belongs to the relation or does not. Multiplying the two choices over n² pairs gives 2n², C. No reflexivity, symmetry or function restriction is imposed; imposing one would change the count.
Count strings containing n zeros and k ones with no adjacent ones. The listed binomial choice A is C(n+1,k).
Your answer
Answer & solution
Answer: A (no official key was published)
First place the n zeros in their fixed order. They create n+1 gaps: before the first zero, between consecutive zeros, and after the last zero. A valid string uses at most one 1 in each gap, otherwise two ones would be adjacent. Choose exactly k of those gaps, giving C(n+1,k). Conversely every such choice creates one valid string, so this is a bijection rather than merely an upper bound. When k>n+1 the count is zero.
For the regular expression consisting of n concatenated factors (0+1), find the minimum finite-automaton states; choice C is n+2 and B is n+1.
Your answer
Answer & solution
Answer: C for a complete DFA (no official key was published)
The language contains exactly the binary strings of length n. Use states 0 through n to record how many symbols have been read and a dead state for lengths above n. State n alone accepts; both symbols advance the count, and the dead state loops. This constructs n+2 states. For i<j≤n, a suffix of length n−j accepts from j but not i, so all progress states are distinguishable. The dead state is distinguishable from each by an appropriate accepting suffix. A partial automaton or NFA could omit that state and use n+1, giving B. The source says finite automaton without explicitly saying complete deterministic; C uses that conventional interpretation, rather than a universal minimum across all automaton models.
Which pair of operations preserves context-free languages: intersection/complement, union/Kleene star, or the other listed pairs?
Your answer
Answer & solution
Answer: B (no official key was published)
For union, introduce a fresh start symbol with alternatives leading to the two original start symbols. For Kleene star, introduce S→S_old S|ε, producing any finite concatenation of words from the original language. Thus union and star preserve context-freeness. Intersection does not: {ai bi cj} intersected with {ai bj cj} gives {an bn cn}. Closure under complement together with union would imply intersection closure by De Morgan, so complement closure also fails. Hence B.
Compare languages accepted by final state and by empty stack: equal classes, one proper inclusion, or incomparable?
Your answer
Answer & solution
Answer: A for nondeterministic PDAs (no official key was published)
An empty-stack PDA can be turned into a final-state PDA by adding a protected bottom marker and moving to an accepting state when the original stack empties. Conversely, a final-state PDA can nondeterministically enter a stack-draining phase after reaching an accepting state; acceptance still requires consuming the whole input. These constructions preserve the recognized language and show equal classes, A. The statement is for unrestricted nondeterministic PDAs. Deterministic acceptance conventions have additional restrictions and cannot be substituted without qualification.
Which is not NOT x: x NAND x, x NOR x, x NAND 1, or x NOR 1?
Your answer
Answer & solution
Answer: D (no official key was published)
Compute each expression directly. x NAND x=¬(x·x)=¬x; x NOR x=¬(x+x)=¬x; x NAND 1=¬x. But x NOR 1=¬(x+1)=0 for both possible x values. At x=0 that differs from NOT x=1, so D is the non-inverter. Tying the inputs together and tying an input to a constant are different operations.
Rows AB and columns CD are Gray ordered 00,01,11,10. Rows are [0,0,1,0],[X,X,1,X],[0,1,1,0],[0,1,1,0]. Find the expression; B is D(C+A).
Your answer
Answer & solution
Answer: B (no official key was published)
Step through it (13 steps)
The entire CD=11 column consists of ones, giving implicant CD. The block spanning AB=11,10 and CD=01,11 gives AD. Their union is CD+AD=D(C+A). Check that every specified one is covered and neither group contains a specified zero; don’t-cares may take either value. Both terms are needed: AB=00,CD=11 requires CD, while AB=10,CD=01 requires AD. Therefore the displayed expression B implements all constrained cells.
Match thread, virtual address space, file system and signal to CPU, memory, disk and interrupt respectively; option C gives 3,2,4,1.
Your answer
Answer & solution
Answer: C (no official key was published)
A thread is an execution context scheduled on a CPU. A virtual address space is the process-facing abstraction of memory. A file system organizes persistent disk storage into named files and directories. A signal is a software notification analogous to an interrupt in its asynchronous transfer of control. Thus the mapping is thread→3, virtual address space→2, file system→4, signal→1, giving C. This matches abstractions rather than asserting that signals and hardware interrupts are identical.
Which is likely to provide best throughput: farthest cylinder next, nearest cylinder next, FCFS, or elevator?
Your answer
Answer & solution
Answer: B under the usual seek-dominated comparison (no official key was published)
Nearest-cylinder-next, or SSTF, chooses the pending request needing the least immediate head movement. Shorter seeks usually reduce service time and allow more requests per unit time, motivating B. FCFS ignores position; farthest-next deliberately increases movement. Elevator scheduling trades some local seek economy for orderly service and better fairness. The question says likely, not universally optimal: arrivals, rotational latency and starvation can change observed performance, so this is a conventional workload judgment rather than a theorem for every request sequence.
System calls are usually invoked by software interrupt, polling, indirect jump, or privileged instruction.
Your answer
Answer & solution
Answer: A (no official key was published)
A user program must request a controlled transition to kernel code. A software trap or software interrupt supplies that entry point, saves the required return state and switches privilege as the architecture specifies. Thus A is the traditional description. An ordinary indirect jump does not itself authorize a privilege change, and polling is a waiting strategy rather than a syscall entry mechanism. Modern processors may use dedicated syscall instructions; the user-callable trap must not be confused with an instruction executable only after privilege has already been obtained.
Does stable sorting mean O(n log n) time, preservation of the order of equal keys, divide-and-conquer, or O(n) space?
Your answer
Answer & solution
Answer: B (no official key was published)
Label two records with equal key as (k,first) and (k,second), in that input order. A stable sort guarantees that first still precedes second afterward. That property matters when one field has already been sorted and a later stable pass sorts another field. Runtime, extra space and algorithmic paradigm are separate properties: a stable insertion sort may take quadratic time, while some fast sorts are unstable. Hence the definition is B.
Partition n array values so negatives precede positives. What is the minimum number of arbitrary exchanges in the worst case: n−1,n,n+1,or none?
Your answer
Answer & solution
Answer: D: floor(n/2) (no official key was published)
Suppose there are k negative values. Their final region is the first k positions. Let t positives currently lie in that region; exactly t negatives then lie outside it. Pair and swap each misplaced positive with a misplaced negative, requiring t exchanges. Every exchange fixes at most one misplaced negative in the target region, proving optimality. Since t≤min(k,n−k), the worst case over k is floor(n/2), attained by placing balanced sign groups in the wrong halves. Thus none of the listed formulas A–C is the general answer. This uses arbitrary swaps, not adjacent swaps.
Sort 20,47,15,8,9,4,40,30,12,17 by straight two-way merging. What is the order after the second pass?
Your answer
Answer & solution
Answer: B: 8,15,20,47,4,9,30,40,12,17 (no official key was published)
Step through it (10 steps)
Pass one merges singleton runs into pairs: [20,47], [8,15], [4,9], [30,40], [12,17]. Pass two merges adjacent pairs into four-element sorted runs. The first two yield [8,15,20,47]; the next two yield [4,9,30,40]. The final pair has no partner and remains [12,17]. Concatenating these runs gives B. The whole array is not yet sorted; later passes merge the length-four runs and the remaining tail.
The graph has edges 12,13,23,24,35,36,56,57. How many articulation vertices: 0,1,2,3?
Your answer
Answer & solution
Answer: D: 3 (no official key was published)
Removing vertex 2 isolates leaf 4. Removing vertex 3 separates the triangle on 1,2 from the triangle on 5,6. Removing vertex 5 isolates leaf 7. Therefore 2,3,5 are articulation points. Removing either leaf does not disconnect the remaining graph, and removing 1 or 6 leaves the corresponding triangle connected through its other edge. No other vertex qualifies, so the count is three, D. The edge list is a self-contained transcription of the linked diagram.
For n a power of two, how many multiplications are minimally needed to compute a^n? Options log2 n, sqrt(n), n−1,n.
Your answer
Answer & solution
Answer: A (no official key was published)
Write n=2k. Repeated squaring computes a²,a⁴,…,a2^k, using exactly k multiplications. To prove minimality in the ordinary multiplication-only straight-line model, observe that one multiplication can at most double the largest exponent already available. Starting with exponent 1, after t multiplications every computed exponent is at most 2t. Reaching n therefore requires t≥log2 n=k. Construction and lower bound coincide, giving A; n=1 needs zero multiplications.
Which parser recognizes the broadest grammar class: LL(1), canonical LR, SLR, or LALR?
Your answer
Answer & solution
Answer: B (no official key was published)
Canonical LR(1) retains a full lookahead context in its states. SLR instead uses FOLLOW sets for reductions, and LALR merges states sharing LR(0) cores; both simplifications can create conflicts absent from the canonical construction. LL(1) is also a more restrictive deterministic grammar class. Consequently canonical LR is the most powerful among the choices, B. Power here concerns which grammars can be handled without conflicts, not implementation speed or table size.
Relations R,S have m,n tuples. What are the maximum and minimum possible sizes of their join?
Your answer
Answer & solution
Answer: B: mn and 0 (no official key was published)
A join selects qualifying pairs from R×S, which contains mn pairs. Therefore it cannot exceed mn. This upper bound occurs when every pair satisfies the join predicate. The minimum zero occurs when no pair satisfies it. Hence B gives the general possible extremes. This reasoning assumes an ordinary inner join with a condition that can permit or reject pairs. A fixed natural join on disjoint schemas is always the Cartesian product, so its minimum would not be zero for positive m,n; the question is the usual unrestricted join-bound comparison.
Translate {t | t∈r and t[A]=10 and t[B]=20}. Options combine the two selections by OR/union, intersection, or difference.
Your answer
Answer & solution
Answer: C (no official key was published)
The tuple must satisfy both tests simultaneously. Selection on A=10 retains the first qualifying subset, and selection on B=20 retains the second. Their intersection contains exactly tuples passing both, so σ(A=10)(r)∩σ(B=20)(r) is equivalent, C. Union or a disjunctive predicate would admit a tuple satisfying only one test. Difference would keep the first test while rejecting the second, which reverses the required conjunction.
Find the eight Booth signed digits for decimal −57, most significant first; option B is 0,−1,0,0,+1,0,0,−1.
Your answer
Answer & solution
Answer: B (no official key was published)
The eight-bit two’s-complement representation of −57 is 11000111, obtained from 57=00111001 by inversion and adding one. Append b[−1]=0 and use signed digit d[i]=b[i−1]−b[i]. From low to high the digits are −1,0,0,+1,0,0,−1,0. Reversing them gives 0,−1,0,0,+1,0,0,−1, option B. The weighted check is −26+23−20=−64+8−1=−57. The negative sign in the question is essential.
For multiplying two n-bit numbers using an array multiplier, is maximum output delay O(n²),O(n),O(log n),or O(1)?
Your answer
Answer & solution
Answer: B (no official key was published)
The array contains quadratically many partial-product cells, but delay measures the longest dependent path rather than the total number of cells. In a regular array multiplier, carry/sum information traverses only a linear number of cell stages along a path to the final output. With bounded gate delay per stage, the critical delay is O(n), B. A logarithmic tree multiplier is a different organization; counting all n² cells as if they operated serially incorrectly gives A.
Main memory has 2cm blocks and cache has 2c blocks, with two blocks per set. Which set receives block k: k mod m,c,2c,or 2cm?
Your answer
Answer & solution
Answer: B (no official key was published)
The number of cache sets is capacity divided by associativity: (2c)/2=c. Consecutive main-memory blocks are distributed cyclically over these c sets, so the set index is k mod c. The remaining quotient supplies tag information, while either way within that indexed set may hold the block. Thus B. The paper display products 2cm and 2c, not exponents; reading the latter as 2c would change the set-count formula incorrectly.
Newton–Raphson starts at x0. Does it converge always, only for polynomials, only if f(x0)<0, or none?
Your answer
Answer & solution
Answer: D (no official key was published)
Newton iteration is x_next=x−f(x)/f′(x), so zero derivatives or a poor initial point can prevent convergence. For f(x)=x³−2x+2 and x0=0, the iteration cycles 0→1→0, disproving always. Nonpolynomial smooth functions can converge near a simple root, disproving the polynomial restriction. For f(x)=x−1 with x0=2, f(x0)>0 yet one step reaches the root, disproving the sign restriction. Therefore D. Standard local convergence hypotheses concern smoothness, a simple root and sufficient initial proximity.
R(A,B,C,D,E,F) has C→F,E→A,EC→D,A→B. Choose a key from CD,EC,AE,AC.
Your answer
Answer & solution
Answer: B: EC (no official key was published)
Step through it (2 steps)
Start the closure of EC with E,C. E→A adds A; A→B adds B; C→F adds F; and EC→D adds D. Thus (EC)+ contains every attribute, so EC is a superkey. Neither E nor C occurs on a right-hand side, so neither can be obtained from other attributes; every key must contain both. Therefore EC is also minimal, a candidate key, and B is correct. Each other listed pair is missing E or C.
Which comparison is correct: disk versus RAM exclusivity, faster B+-tree range queries, primary versus secondary exclusivity, or height independent of record count?
Your answer
Answer & solution
Answer: B (no official key was published)
B+-trees store the data entries at the leaf level and typically link those leaves in key order. After locating a range’s first entry, scanning successive leaves retrieves the remainder efficiently without repeated searches through internal nodes. This is the conventional range-query advantage in B. Both structures may be disk resident and can support different index roles, so A and C are false dichotomies. Height still increases with record count at a fixed fanout, making D false. The comparison assumes the standard linked-leaf B+-tree layout.
P(E1)=1/2,P(E2)=1/3,P(E1∩E2)=1/5. Evaluate union=2/3, independence, nonindependence, and P(E1|E2)=4/5.
Select all that apply
Answer & solution
Answer: C (no official key was published)
Inclusion–exclusion gives P(E1∪E2)=1/2+1/3−1/5=19/30, not 2/3. Independence would require intersection (1/2)(1/3)=1/6, unequal to 1/5; hence B is false and C true. The conditional probability is (1/5)/(1/3)=3/5, not 4/5. Therefore only C is correct. Conditional probabilities divide by the conditioning event, not by the union.
Two distinct girls divide 10 roses,15 sunflowers and 14 daffodils. Count allocations among 1638,2100,2640,none.
Select all that apply
Answer & solution
Answer: C (no official key was published)
The first girl may receive any number of roses from 0 through 10, giving 11 choices; the second receives the remainder. Independently there are 16 sunflower choices and 15 daffodil choices. By the product rule there are 11·16·15=2640 allocations, C. Flowers of the same type are treated as indistinguishable, and empty shares of a type are allowed. Counting subsets of individually labelled flowers would solve a different problem. Under the latter wording the count is 11·16·16=2816, giving D instead. The the paper-derived C is not claimed as an official answer.
R is reflexive,antisymmetric,transitive on L, and every pair has a least upper bound and greatest lower bound. Must L be a poset,Boolean algebra,lattice,or none?
Select all that apply
Answer & solution
Answer: A,C (no official key was published)
The first three axioms are exactly those of a partial order, so L is a poset: A. Existence of a join and meet for every pair upgrades that poset to a lattice: C. Boolean algebra requires additional structure, including boundedness, complements and distributivity; none follows merely from the given pairwise bounds. A three-element chain is a lattice but its middle element has no Boolean complement. Therefore B is not forced, and D is false.
L1 is context-free and L2 regular. Which claims are false in general: A L1−L2 is not context-free; B L1∩L2 is context-free; C complement L1 is context-free; D complement L2 is regular?
Select all that apply
Answer & solution
Answer: A,C (no official key was published)
Regular languages are closed under complement, and intersecting a CFL with a regular language preserves context-freeness using a PDA–DFA product. Thus L1−L2=L1∩complement(L2) is context-free, so A is false; B and D are true. CFLs are not closed under complement: otherwise their union closure plus De Morgan would imply intersection closure, contradicted by the standard an bn cn construction. Hence C is also false as a universal assertion. Some particular L1 do have context-free complements, so the conclusion is about closure, not every instance.
Which constructs should be excluded to make the language’s halting function programmable: choices include arbitrary goto(v),recursive calls(vii),and repeat loops(viii), together in B? Remaining constructs are assignment,bounded for,if,forward goto,and nonrecursive calls.
Select all that apply
Answer & solution
Answer: B under the bounded-loop model (no official key was published)
Exclude arbitrary backward jumps, unrestricted recursion and unbounded repeat loops. The remaining for loops have fixed finite bounds whose control variable cannot be changed in the body; forward jumps cannot create cycles; and a finite acyclic nonrecursive call structure terminates. Structural induction on these constructs therefore proves every valid program halts. Its halting predicate is simply the constant true function, expressible in the language. This establishes the intended sufficient restriction B. The argument assumes finite evaluated bounds and ordinary bounded-for semantics, not changing loop limits or hidden nonterminating primitives.
Schedule: r1(A),r2(B),w1(A),r2(A),w2(A),w2(B),r1(B),w1(B). Is it serializable and/or possible under two-phase locking?
Select all that apply
Answer & solution
Answer: D: neither (no official key was published)
Step through it (10 steps)
The A conflicts put transaction 1 before transaction 2: w1(A) precedes r2(A) and w2(A). The B conflicts put transaction 2 before transaction 1: w2(B) precedes r1(B) and w1(B). Hence the precedence graph has a directed cycle. It is not conflict serializable; even view equivalence fails because T2 reads A from T1 while T1 reads B from T2, requiring opposite serial orders. Two-phase locking guarantees conflict serializability, so it cannot produce this completed schedule. Thus D.
R(S,T,U,V) has S→T,T→U,U→V,V→S and is decomposed into R1,R2. Determine whether the components satisfy 2NF and 3NF.
Select all that apply
Answer & solution
Answer: D: both (no official key was published)
By following the dependency cycle, each single attribute determines all four. Consequently, in any projected component, every individual attribute determines all attributes of that component and is a key. Every nontrivial projected FD therefore has a superkey determinant, so each component is in BCNF, hence also 3NF and 2NF. Thus D. This normal-form argument does not depend on whether the components intersect. The reproductions differ on that intersection symbol; normal form alone does not establish lossless decomposition.
The circuit has u=NAND(A,Y),v=NAND(B,u),Y=AND(C,v). Given steady Y=1, select ABC from 001,011,101,111.
Select all that apply
Answer & solution
Answer: A,C,D (no official key was published)
Substitute the required Y=1 into the first gate: u=¬A. The second gives v=¬(B·¬A)=¬B+A. For the output AND to be one, C=1 and v=1 are required. Thus either A=1 or B=0, with C=1. The allowed listed triples are 001,101,111, namely A,C,D; 011 gives v=0 and fails. This is a fixed-point calculation, not a claim about which state an arbitrary initial circuit will reach. NAND bubbles were checked in the clearer alternate diagram.
Choose universal component sets: A XOR and NOT; B 2:1 multiplexers; C AND and XOR; D gates AB+C.
Select all that apply
Answer & solution
Answer: B,C if constants 0 and 1 are available (no official key was published)
A produces only affine Boolean functions, so it cannot express AND and is incomplete. For B, a mux with data inputs 1,0 implements NOT of its select; a mux with data 0,y and select x implements xy. NOT and AND are universal. For C, x XOR 1=¬x, again providing NOT plus AND. D is monotone, so compositions cannot implement inversion. Hence B,C under the usual available-constant convention. Without constant 1, B and C preserve zero and cannot produce NOT; the source does not explicitly state the constant-input convention, so this dependence is retained.
Which hardware feature is essential in the standard native protected-OS model: address translation,DMA,two privilege modes,demand paging?
Select all that apply
Answer & solution
Answer: C under the protected native-execution model (no official key was published)
User code must be prevented from directly changing privileged OS state, while kernel code must be allowed to do so. Distinct privileged and unprivileged execution modes provide this boundary, motivating C. DMA is an optimization over programmed transfers; demand paging is optional; and full address translation is not the only conceivable protection mechanism. The literal word cannot is broader than the textbook model: trusted programs or an interpreter can implement multiuser services without native privilege modes. Thus the result concerns untrusted applications executing natively with hardware-enforced protection.
Select advantages: A faster average accesses,B protected address spaces,C linker addresses independent of physical loading,D programs larger than RAM.
Select all that apply
Answer & solution
Answer: B,C,D (no official key was published)
Translation associates each process’s virtual addresses with controlled physical mappings, enabling separate protected spaces: B. Link-time virtual addresses need not equal final physical frame addresses, enabling C. Keeping only a working set resident while backing other pages on storage permits an address space larger than RAM: D. Translation and page faults add overhead rather than intrinsically speeding memory access, so A is not a general advantage. Protection permissions and backing-store support are the conventional virtual-memory system assumptions.
Which is typically NOT performed when switching A to B: save/restore registers,change translation tables,swap A’s entire memory image to disk,invalidate TLB?
Select all that apply
Answer & solution
Answer: C (no official key was published)
A context switch preserves A’s architectural state and restores B’s registers. It also selects B’s address-translation context. In a conventional untagged TLB, old translations must be invalidated to avoid interpreting B’s addresses through A’s mappings. None of this requires writing all of A’s memory to disk: both processes can remain resident. Therefore C is the operation not normally required. Tagged TLBs may avoid full invalidation, but that architectural optimization is distinct from whole-process swapping and does not turn every switch into a disk transfer.
Global x is set to 0.25. show prints x. small has local x=0.125 and calls show. Main calls show,then small, using dynamic scope.
Select all that apply
Answer & solution
Answer: C: 0.25,0.125 (no official key was published)
Dynamic lookup searches active calling environments. In the first show call, no nearer local x is active, so the global value 0.25 is printed. In the second call, small is the active caller and its local x=0.125 is the nearest binding, so show prints 0.125. Thus C. Under lexical scope, show’s definition outside small would instead resolve both calls to the global binding; the explicit dynamic-scoping premise is therefore essential.
Count tokens in legacy FORTRAN DO 10 I = 1.25. Options 3,4,5,none; the number contains a decimal point, not a comma.
Select all that apply
Answer & solution
Answer: A: 3 (no official key was published)
In the classic fixed-form FORTRAN lexical convention, embedded blanks are insignificant outside literals. Thus DO 10 I becomes the identifier DO10I when the remainder is an assignment rather than a valid DO-loop header. The decimal point in 1.25 means this is not the loop form DO 10 I=1,25. Its tokens are identifier DO10I, assignment equals, and real literal 1.25: three, A.
A grammar is both left and right recursive for a nonterminal. Must it be ambiguous,unambiguous,or is more information required?
Select all that apply
Answer & solution
Answer: C literally; usefulness assumptions matter (no official key was published)
Both recursion directions can certainly occur in an ambiguous grammar: S→Sa|aS|a derives aa using either recursive rule. But the premise alone does not say that the recursive nonterminal is reachable and productive. For example S→c together with A→Aa|aA|b has both recursion directions at A, while the start language has just one parse tree for c. Thus the literal premise does not force ambiguity, giving C. The example deliberately exposes the omitted usefulness condition; it does not assert that an arbitrary useful doubly recursive nonterminal is harmless. The usual ambiguity claim needs a more precise grammar hypothesis.
Add two 16-bit numbers without an external carry-in. Choose the half/full-adder counts; B gives one half-adder and 15 full-adders.
Select all that apply
Answer & solution
Answer: B (no official key was published)
The least-significant position adds only two operand bits, so a half-adder produces its sum and carry. Each of the remaining fifteen positions must add two operand bits plus the carry from the preceding position, requiring a full-adder. The total is therefore one half-adder and fifteen full-adders, B. Using half-adders alone would not handle three inputs at higher positions without extra combination logic. If an external carry-in were required at the first position, sixteen full-adders would be the natural implementation instead.
Which schemes have two zeros: sign-magnitude,ones complement,twos complement,none?
Select all that apply
Answer & solution
Answer: A,B (no official key was published)
In sign-magnitude, magnitude bits all zero represent zero with either sign bit, producing +0 and −0. In ones complement, complementing the all-zero positive representation yields the all-one negative-zero pattern. In twos complement, negation complements then adds one, returning zero to the all-zero pattern after overflow is discarded; the all-one pattern represents −1 instead. Thus exactly A and B have two zero representations.
RAID configurations provide fault tolerance,high speed,high data density,or none. Select applicable goals.
Select all that apply
Answer & solution
Answer: A,B (no official key was published)
Mirroring or parity can preserve recoverability after a disk failure, providing fault tolerance. Striping distributes transfers across disks and can increase throughput, providing high speed. These are system-level properties, not an increase in the physical bit density of an individual disk, so C is not a RAID benefit. The applicable goals are A,B. Different RAID levels trade these goals differently: RAID0 emphasizes striping without redundancy, while mirrored/parity levels supply failure protection; the answer does not claim every level supplies both equally.
Order hardwired control,horizontal microprogramming,vertical microprogramming from fastest to slowest.
Select all that apply
Answer & solution
Answer: B (no official key was published)
Hardwired control generates signals through dedicated logic without fetching a microinstruction for each control step. Horizontal microcode exposes many control fields directly, reducing decoding and allowing parallel control actions. Vertical microcode is more densely encoded and needs additional decoding, often with less control parallelism. Thus the traditional comparable-design order is hardwired, horizontal, vertical, option B. This is an architectural rule of thumb, not a universal measured ordering across unrelated implementations or clock technologies.
Merge file lengths 10,20,15,5,25 with pairwise merging; cost is records moved. Choose165,90,75,65.
Select all that apply
Answer & solution
Answer: A: 165 (no official key was published)
Always merge the two shortest remaining files, as in the optimal merge/Huffman construction. Merge5+10=15, costing 15; then 15+15=30, costing 30; then 20+25=45, costing 45; finally 30+45=75, costing 75. Total cost is 15+30+45+75=165. The greedy choice is optimal because two smallest weights can occupy deepest sibling leaves of an optimal merge tree, after which contracting them leaves the same problem on fewer files. Counting only 75 ignores repeated moves through intermediate merges.
M:T(n)=T(n−1)+n; N:T(n)=T(n/2)+n; O:T(n)=T(n/2)+n log n; P:T(n)=T(n−1)+log n. Match to U O(n),V O(n log n),W O(n²),X O(log² n).
Select all that apply
Answer & solution
Answer: B: M-W,N-U,O-V,P-V (no official key was published)
For M, summing 1+2+…+n gives Θ(n²). For N, the work is n+n/2+n/4+…=Θ(n). For O, the first term already gives n log n and the geometric weighted tail is O(n log n), hence Θ(n log n). For P, summing log k for k=2…n gives log(n!)=Θ(n log n): the upper bound is n log n and the last n/2 terms each exceed log(n/2). Thus M-W,N-U,O-V,P-V, option B. The listed big-O labels are interpreted as tight intended growth classes; loose upper bounds would not define a unique matching.
Relative to CISC, does RISC typically have fewer instructions,fewer addressing modes,more registers,and easier hardwired control?
Select all that apply
Answer & solution
Answer: A,B,C,D (no official key was published)
A smaller, more regular instruction repertoire and fewer addressing forms simplify instruction decoding. A load/store style relies heavily on register operands, encouraging a larger register file. Regular simple instruction behavior also makes hardwired control easier to design than for many complex multi-step instructions. These support all four listed typical characteristics. They are historical design tendencies, as the word typically indicates, not strict necessary conditions that classify every modern hybrid processor.
With only immediate and direct addressing, which cannot be implemented: pointers,arrays,records,recursive procedures with locals?
Select all that apply
Answer & solution
Answer: No unconditional impossibility; A,B,D under a restricted direct-code model (no official key was published)
A direct instruction names a fixed address; it cannot in one ordinary memory operation follow a runtime pointer or index. Records with fixed field offsets can use fixed addresses, while pointers, variable array indices and runtime stack frames naturally need computed-address access. This motivates A,B,D only under a model excluding software emulation and code modification. Literally, however, a finite address space permits a dispatch chain: compare the desired address with each legal address and execute the matching direct load/store. Such an interpreter can implement all these features, albeit inefficiently; self-modifying code supplies another possible route if allowed. Therefore the given addressing-mode restriction alone does not prove impossibility, and no unsupported official choice is assigned.
Trial(a,b,c) returns b if a≥b and c<b; otherwise calls Trial(a,c,b) if a≥b, or Trial(b,a,c). Does it find maximum,minimum,median,or none?
Select all that apply
Answer & solution
Answer: C on distinct values; not total for arbitrary integers (no official key was published)
For distinct values, a return requires c<b≤a, so b is the median. If a<b, swapping the first two puts the larger first. If a≥b but c≥b, swapping b and c either puts the middle value second or is followed by a first-pair swap; direct enumeration of the six strict orderings confirms termination at the median. Ties expose a defect: Trial(2,1,1) repeatedly calls itself because c<b is false while swapping equal arguments changes nothing. Trial(1,1,1) likewise never returns. Thus C describes the intended distinct-input algorithm, but no unconditional median function is established by the stated unrestricted int signature.
Which is correct: queries automatically remove duplicates; queries require indexes; column names may repeat within the same relation; none?
Select all that apply
Answer & solution
Answer: D under the base-table reading (no official key was published)
Ordinary SELECT uses bag semantics; DISTINCT is needed when duplicate elimination is desired, so A is false. Indexes improve access paths but table scans execute queries without them, so B is false. A base table schema requires distinct column names within that table, so C is false in the stated relation-schema sense. Hence D. Different tables may share names and qualified references disambiguate them; some query result displays may also contain repeated labels, which is not the same as a valid base relation definition.
For a relation R on a set X, Mr. X claims symmetry and transitivity imply reflexivity. His proof starts with xRy, obtains yRx by symmetry, and then xRx by transitivity. Briefly identify the flaw. (This final instruction appears in GFG but is omitted from GateForum.)
Shared context
For a relation R on a set X, Mr. X claims symmetry and transitivity imply reflexivity. His proof starts with xRy, obtains yRx by symmetry, and then xRx by transitivity. Briefly identify the flaw.
Answer & solution
Answer: The proof assumes every x has some related y; symmetry and transitivity do not guarantee this. (no official key was published)
1. Reflexivity requires xRx for every x in the specified underlying set X. The proof must therefore start with an arbitrary x, not with an arbitrarily available related pair.
2. Its deductions from xRy are valid: symmetry gives yRx, and transitivity then gives xRx. What is unjustified is the premise that, for each x, there exists any y with xRy.
3. Thus the argument proves only: if x occurs as the first coordinate of some pair in R, then xRx. Elements outside that domain may have no related pairs at all.
4. For example, on X={0,1}, R={(0,0)} satisfies symmetry and transitivity but does not contain (1,1). Replacing the missing premise with an assumption that every x relates to some y would make the proposed proof valid.
Give a relation R that is symmetric and transitive but not reflexive. Specify its underlying set.
Shared context
Give a relation R that is symmetric and transitive but not reflexive. Specify its underlying set.
Answer & solution
Answer: On X={0,1}, take R={(0,0)}. (no official key was published)
Choose X={0,1} and R={(0,0)}. Symmetry holds because the reverse of its only pair is the same pair. For transitivity, if xRy and yRz hold, both pairs must be (0,0), so x=z=0 and the required pair xRz=(0,0) is in R. However, reflexivity on X would require both (0,0) and (1,1); the latter is absent.
The universe matters: this same relation would be reflexive on {0}. Alternatively, the empty relation on any nonempty set works, since symmetry and transitivity are vacuously true while at least one required diagonal pair is missing.
Let G be a finite group, H a subgroup, and aH={ah:h∈H} for a∈G. Prove |aH|=|H|.
Shared context
Let G be a finite group, H a subgroup, and aH={ah:h∈H} for a∈G. Prove |aH|=|H|.
Answer & solution
Answer: Left multiplication h↦ah is a bijection H→aH. (no official key was published)
Define φ:H→aH by φ(h)=ah. It is surjective by the definition of aH: every element there is ah for some h in H. It is injective because ah₁=ah₂ implies h₁=h₂ after multiplying on the left by a⁻¹. Thus φ is a bijection, proving equal cardinalities. Its inverse is x↦a⁻¹x, which sends each x=ah back to h∈H. Commutativity is unnecessary; the side on which cancellation occurs must remain consistent.
Let G be a finite group, H a subgroup, and aH={ah:h∈H} for a∈G. Prove aH=bH or aH∩bH=∅ for all a,b∈G.
Shared context
Let G be a finite group, H a subgroup, and aH={ah:h∈H} for a∈G. Prove aH=bH or aH∩bH=∅ for all a,b∈G.
Answer & solution
Answer: A shared element forces equality of the two left cosets. (no official key was published)
If the intersection is empty there is nothing to prove. Otherwise choose x=ah₁=bh₂ with h₁,h₂∈H. Rearrangement gives b⁻¹a=h₂h₁⁻¹∈H, using subgroup closure and inverses.
For any ah∈aH, write ah=b(h₂h₁⁻¹h). The parenthesized product belongs to H, so ah∈bH; hence aH⊆bH. Likewise a⁻¹b=h₁h₂⁻¹∈H gives bH⊆aH. Therefore aH=bH.
This proof does not assume the cosets themselves are subgroups, which need not be true. The subgroup properties are used only for products of the h-elements.
Let G be a finite group, H a subgroup, and aH={ah:h∈H} for a∈G. Use equal coset sizes and the equal-or-disjoint property to show |H| divides |G|.
Shared context
Let G be a finite group, H a subgroup, and aH={ah:h∈H} for a∈G. Use equal coset sizes and the equal-or-disjoint property to show |H| divides |G|.
Answer & solution
Answer: |G|=[G:H]|H|, so |H| divides |G|. (no official key was published)
Every g∈G belongs to gH because the identity e lies in H and g=ge. Thus all left cosets cover G. By the previous part, distinct left cosets do not overlap; they form a partition. Finiteness of G means there are a finite number r of distinct cosets. Each has |H| elements by the multiplication bijection. Counting the disjoint union yields |G|=r|H|. Since r is an integer, |H| divides |G|. The number r is called the index [G:H]; no normality assumption is needed.
G is the undirected graph on {A,B,C,D,E,F} with edges {AB,AD,AE,AF,BC,BD,CF,DE,DF,EF}. Edge crossings without a labeled vertex are not vertices. A cut is any edge set whose removal disconnects G; a min-cut has minimum cardinality. Is {AB,EF,BD,AE,AD} a cut?
Shared context
G is the undirected graph on {A,B,C,D,E,F} with edges {AB,AD,AE,AF,BC,BD,CF,DE,DF,EF}. Edge crossings without a labeled vertex are not vertices. A cut is any edge set whose removal disconnects G; a min-cut has minimum cardinality. Is {AB,EF,BD,AE,AD} a cut?
Answer & solution
Answer: No; the remaining graph is connected. (no official key was published)
After deleting the proposed five edges, the remaining edges are AF, BC, CF, DE, and DF. They form a connected spanning tree: B–C–F–D–E is a path and A attaches to F. In particular, starting at F reaches A and C directly, B through C, D directly, and E through D. Therefore no vertex is separated, and the proposed set is not a cut. Removing many edges does not by itself guarantee disconnection; one must check connectivity of the surviving graph.
G is the undirected graph on {A,B,C,D,E,F} with edges {AB,AD,AE,AF,BC,BD,CF,DE,DF,EF}. Edge crossings without a labeled vertex are not vertices. A cut is any edge set whose removal disconnects G; a min-cut has minimum cardinality. Is {BD,CF,AB} a cut?
Shared context
G is the undirected graph on {A,B,C,D,E,F} with edges {AB,AD,AE,AF,BC,BD,CF,DE,DF,EF}. Edge crossings without a labeled vertex are not vertices. A cut is any edge set whose removal disconnects G; a min-cut has minimum cardinality. Is {BD,CF,AB} a cut?
Answer & solution
Answer: Yes; it separates {B,C} from {A,D,E,F}. (no official key was published)
The only edges crossing between {B,C} and the remaining vertices are BA, BD, and CF. All three are removed. The edge BC survives, leaving B and C connected to one another but with no path to the other four vertices. The induced remaining subgraph on {A,D,E,F} is connected, for example by AD, DE, and EF. Consequently the deletion produces exactly two components and is a cut. Its size is three, although it is not a minimum cut.
G is the undirected graph on {A,B,C,D,E,F} with edges {AB,AD,AE,AF,BC,BD,CF,DE,DF,EF}. Edge crossings without a labeled vertex are not vertices. A cut is any edge set whose removal disconnects G; a min-cut has minimum cardinality. Find the min-cut cardinality.
Shared context
G is the undirected graph on {A,B,C,D,E,F} with edges {AB,AD,AE,AF,BC,BD,CF,DE,DF,EF}. Edge crossings without a labeled vertex are not vertices. A cut is any edge set whose removal disconnects G; a min-cut has minimum cardinality. Find the min-cut cardinality.
Answer & solution
Answer: 2, witnessed by removing BC and CF to isolate C. (no official key was published)
An upper bound is immediate: C has degree two, so deleting BC and CF isolates C. Hence the minimum cut has size at most two.
To exclude a one-edge cut, show that no edge is a bridge. The cycle A–B–C–F–A contains AB, BC, CF, AF. The triangle A–B–D–A contains BD and AD. The triangle A–D–E–A contains DE and AE. Finally the triangle D–E–F–D contains EF and DF. Together these cycles cover every edge of G.
An edge on a cycle cannot be a bridge because the rest of that cycle provides an alternate path between its endpoints after deletion. The graph is connected initially, so a zero-edge cut is impossible. Therefore its minimum cut cardinality is exactly two.
Let G be a connected undirected graph with n≥2 vertices and min-cut cardinality k. Prove G has at least nk/2 edges.
Shared context
Let G be a connected undirected graph with n≥2 vertices and min-cut cardinality k. Prove G has at least nk/2 edges.
Answer & solution
Answer: 2|E|=Σᵥdeg(v)≥nk, so |E|≥nk/2. (no official key was published)
For each vertex v, delete all edges incident to v. This isolates v from the other n−1 vertices, so those deg(v) edges form a cut. Since k is the minimum possible cut size, deg(v)≥k for every v.
Sum these n inequalities to obtain Σᵥdeg(v)≥nk. By the handshake lemma, every undirected edge contributes one to each endpoint degree, and therefore Σᵥdeg(v)=2|E|. Dividing by two gives |E|≥nk/2. If nk is odd, the integer edge count is in fact at least ⌈nk/2⌉. The proof explains why the minimum cut bounds every degree rather than merely the average degree.
Similar questions1 more → · asked again: GATE 1994, Q19(b)
Regular union does not determine a summand
Closure Properties & Language Hierarchy
Tap to enlarge
Given that language A is regular and A∪B is regular, must B be regular? Justify.
Shared context
Given that language A is regular and A∪B is regular, must B be regular? Justify.
Answer & solution
Answer: No: take A={0,1}* and B={0ⁿ1ⁿ:n≥0}. (no official key was published)
Let the alphabet be {0,1}. Choose A={0,1}*, a regular language, and B={0ⁿ1ⁿ:n≥0}, which is not regular. Because B⊆A, the union A∪B equals A and is regular.
For completeness, B is nonregular by the pumping lemma: for pumping length p, any allowed pumped substring in 0ᵖ1ᵖ lies among the initial p zeros, and pumping it down changes the number of zeros without changing the p ones. The resulting word is not in B.
Closure under difference only proves (A∪B)\A=B\A is regular. It gives no control over the possibly nonregular part B∩A. This is precisely why reversing union closure fails.
Given finite automata M₁ and M₂, outline an algorithm to decide L(M₁)⊊L(M₂). The prose explicitly says strict subset even though a reproduced symbol permits equality.
Shared context
Given finite automata M₁ and M₂, outline an algorithm to decide L(M₁)⊊L(M₂). The prose explicitly says strict subset even though a printed symbol permits equality.
Answer & solution
Answer: Require L(M₁)\L(M₂)=∅ and L(M₂)\L(M₁)≠∅. (no official key was published)
1. Put the automata over the same alphabet Σ, taking the union of their alphabets if needed. Determinize any NFAs and complete both resulting DFAs with sink states for missing transitions. This makes complementing acceptance correct.
2. Explore the product states (q₁,q₂) from the initial pair, with δ((q₁,q₂),a)=(δ₁(q₁,a),δ₂(q₂,a)). A reachable pair with q₁ accepting and q₂ rejecting witnesses a word in L(M₁)\L(M₂). If such a pair exists, answer NO.
3. Also look for a reachable pair with q₂ accepting and q₁ rejecting. If none exists, the languages are equal, so strict inclusion is false. If one exists while the first kind does not, answer YES.
4. Breadth-first or depth-first search suffices because a finite automaton language is nonempty exactly when an accepting state is reachable. On complete DFAs the search takes O(|Σ||Q₁||Q₂|) time; determinization can add exponential cost for NFA input. Both tests are necessary: ordinary inclusion alone incorrectly accepts equal languages.
Prove L={xcx:x∈{0,1}*} is not context-free, where c is a terminal different from 0 and 1.
Shared context
Prove L={xcx:x∈{0,1}*} is not context-free, where c is a terminal different from 0 and 1.
Answer & solution
Answer: A context-free pumping-lemma argument on 0ᵖ1ᵖc0ᵖ1ᵖ yields a contradiction. (no official key was published)
Suppose L were context-free and let p be its pumping length. Choose w=0ᵖ1ᵖc0ᵖ1ᵖ∈L. For any pumping decomposition w=uvxyz, the lemma requires |vxy|≤p, |vy|>0, and uvⁱxyⁱz∈L for every i≥0. We show pumping down (i=0) always fails.
If v or y contains c, removing v and y removes the unique separator. The result cannot be in L.
Otherwise c is not pumped. If vxy lies entirely on one side of c, pumping down shortens only that copy. The two sides have unequal lengths, so cannot be equal.
The remaining case is that vxy spans c, with c inside the unpumped substring x. Because |vxy|≤p, everything it can reach to the left of c is in the first block of ones, and everything to the right is in the second block of zeros: it cannot reach the first zeros or the final ones, each separated by a whole length-p block. Thus v=1ᵃ and y=0ᵇ, allowing a or b to be zero, but a+b>0. Pumping down leaves 0ᵖ1p−ac0p−b1ᵖ. Equality of the two copies would force both a=0 (compare ones) and b=0 (compare zeros), contrary to |vy|>0.
Every allowable decomposition fails the lemma, so L is not context-free. The argument relies on a genuine copy xc x, not the context-free reversed-copy language xc xᴿ.
An n×n matrix A has every row and column in ascending order. Draw a decision tree finding its first, second, and third smallest entries using the minimum number of comparisons. Assume n≥2; count repeated values as separate entries.
Shared context
An n×n matrix A has every row and column in ascending order. Draw a decision tree finding its first, second, and third smallest entries using the minimum number of comparisons. Assume n≥2; count repeated values as separate entries.
Answer & solution
Answer: Two comparisons suffice and are necessary in the worst case. (no official key was published)
The first entry is always A₁₁. Set b=A₁₂ and c=A₂₁. Every remaining entry is at least b or c, so the second is min(b,c).
If b≤c, the only candidates for third are c and d=A₁₃. Other entries in the first row are at least d; entries outside the first row are at least c (including A₂₂). If c<b, the analogous candidates are b and e=A₃₁. When n=2, the missing d or e can be treated as +∞, so the third is simply the other one of b,c and just one comparison suffices for that special size.
For n≥3 the full decision tree is:
compare b ≤ c?
/ yes \ no
compare d ≤ c? compare e ≤ b?
/ yes \ no / yes \ no
(A₁₁,b,d) (A₁₁,b,c) (A₁₁,c,e) (A₁₁,c,b)
Each root-to-leaf path has two comparisons. The leaves give the first three entries in order. Ties can follow the ≤ branch: tied entries have equal values, so either identity order is valid.
Optimality for n≥3: all four strict order possibilities displayed at the leaves can occur in a row-and-column-sorted matrix. A single binary comparison has only two outcomes and cannot distinguish four possible ordered triples of positions; two comparisons are necessary in the worst case. For n=2 there are only the two orders of b,c and one comparison is both sufficient and necessary. For n=1 a third entry does not exist, so the task presupposes at least n=2.
Similar questions1 more → · asked again: GATE 1998, Q23
Synthesized attributes for binary fractions
Semantic Analysis & Type Checking
Tap to enlarge
Assign synthesized attributes to evaluate a binary numeral, exemplified by 101.101=5.625. The reproduced grammar is damaged: GateForum prints “S → LL\L; L → LB\B; B → 0\1”, with no radix point; GFG has conventional alternative bars but an unclear/missing radix-point glyph. Conditional intended grammar used below: S→L.L | L; L→LB | B; B→0 | 1. Write semantic rules for every production.
Shared context
Assign synthesized attributes to evaluate a binary numeral, exemplified by 101.101=5.625. Conditional intended grammar used below: S→L.L | L; L→LB | B; B→0 | 1. Write semantic rules for every production.
Answer & solution
Answer: For S→L₁.L₂, use S.val=L₁.val+L₂.val/2^(L₂.len); synthesize L.val and L.len. (no official key was published)
a radix-point production is required to parse the supplied fractional example. The following is an explicitly stated reconstruction consistent with that example, not a claim that an official original was verified. If the production is literally S→LL with no point terminal, the grammar does not parse 101.101 at all and is ambiguous about splitting an unmarked bit string.
Use synthesized attributes L.val (the bit string interpreted as an unsigned integer) and L.len (its number of bits). Let B.val be the numeric value of one bit. Distinguish repeated L occurrences by subscripts:
S → L₁ . L₂ : S.val := L₁.val + L₂.val / 2^(L₂.len)
S → L : S.val := L.val
L → L₁ B : L.val := 2*L₁.val + B.val; L.len := L₁.len + 1
L → B : L.val := B.val; L.len := 1
B → 0 : B.val := 0
B → 1 : B.val := 1
Appending a bit shifts the existing integer one binary place left, hence multiplication by two. The fractional substring represents its integer value divided by 2 raised to its length; this also handles leading zeros correctly. All right-hand sides depend only on child attributes, so the definition is S-attributed.
For 101, successive (val,len) pairs are (1,1),(2,2),(5,3). Both L occurrences in 101.101 therefore have (5,3), and S.val=5+5/8=5.625. For 0.001, the fractional attributes (1,3) give 1/8 rather than 1/2, showing why the length attribute is essential.
Assume a total, correct procedure HALTS(f,x) reports whether f(x) terminates. Define FUNNY(f)=IF HALTS(f,f) THEN NOT(f(f)) ELSE TRUE. Show FUNNY terminates for every f.
Shared context
Assume a total, correct procedure HALTS(f,x) reports whether f(x) terminates. Define FUNNY(f)=IF HALTS(f,f) THEN NOT(f(f)) ELSE TRUE. Show FUNNY terminates for every f.
Answer & solution
Answer: Under the hypothetical HALTS assumption, both selected branches terminate. (no official key was published)
Interpret f as a program that can be supplied its own description as input; for the NOT expression restrict attention to programs returning Boolean values when they halt. This restricted class already suffices for the impossibility proof.
HALTS(f,f) terminates by the assumed totality of the decision procedure. If it returns FALSE, FUNNY immediately returns TRUE without running the nonterminating f(f). If it returns TRUE, its correctness guarantees that f(f) terminates. Evaluating that result and applying Boolean NOT therefore also terminates.
Thus for every such input program f, FUNNY(f) terminates and returns a Boolean. This is a conclusion conditional on the assumed existence of HALTS, not an independently implementable algorithm. Short-circuit branch selection is essential: the unselected branch must not evaluate f(f).
Assume a total, correct procedure HALTS(f,x) reports whether f(x) terminates. Define FUNNY(f)=IF HALTS(f,f) THEN NOT(f(f)) ELSE TRUE. Use termination of FUNNY to prove by contradiction that no such total correct HALTS exists.
Shared context
Assume a total, correct procedure HALTS(f,x) reports whether f(x) terminates. Define FUNNY(f)=IF HALTS(f,f) THEN NOT(f(f)) ELSE TRUE. Use termination of FUNNY to prove by contradiction that no such total correct HALTS exists.
Answer & solution
Answer: FUNNY(FUNNY) would return the negation of its own Boolean result. (no official key was published)
Assume HALTS exists as a computable, always-terminating correct decision procedure. Then the definition constructs a computable FUNNY, and part (a) shows that FUNNY terminates on every program description, including its own. Consequently HALTS(FUNNY,FUNNY) must return TRUE.
Let b be the Boolean returned by FUNNY(FUNNY). Following its definition and the TRUE answer, the same call must return NOT(FUNNY(FUNNY)), namely NOT b. This implies b=NOT b. Neither Boolean value satisfies this equation: TRUE would have to be FALSE and FALSE would have to be TRUE.
There is also an operational view: the TRUE branch invokes the identical FUNNY(FUNNY) call again before it can negate the result, producing unending recursion, contradicting the termination guaranteed by part (a). Either explanation refutes the initial assumption. Therefore no algorithm decides halting for arbitrary programs and inputs. Assuming a function can accept its own encoded description is standard for general-purpose programs; restricting output to Booleans does not avoid the contradiction.
Given the algorithm below, with procedure A taking O(1) time and B(n) taking O(1/n) time, derive its time complexity in O-notation. GFG retains the O symbols lost in GateForum.
what(n): if n = 1: call A else: what(n-1) call B(n)
Assume n is a positive integer.
Shared context
Given the algorithm below, with procedure A taking O(1) time and B(n) taking O(1/n) time, derive its time complexity in O-notation.
what(n): if n = 1: call A else: what(n-1) call B(n)
Assume n is a positive integer.
Answer & solution
Answer: Procedure-cost-only model: O(log n). With ordinary constant recursion/control overhead: Θ(n). (no official key was published)
In the idealized accounting suggested by the question, count only costs of A and B. Let their costs be a and b(k), with a=O(1) and b(k)=O(1/k). The recurrence is T(1)=a and T(n)=T(n−1)+b(n). Expanding gives T(n)=a+Σ(k=2..n)b(k)≤C₀+C₁Σ(k=2..n)1/k for suitable constants, absorbing finitely many small inputs into C₀.
The harmonic sum is bounded above by 1+ln n, by comparison with the integral of 1/x. Thus T(n)=O(log n). If the supplied procedure costs are actually Θ(1) and Θ(1/n), the lower integral bound gives Θ(log n), but upper bounds alone do not prove this tight classification.
Cost-model qualification: a real RAM implementation must perform a test, decrement, recursive call and return at each of n recursion levels. These contribute Θ(1) per level, giving T_RAM(n)=T_RAM(n−1)+Θ(1)+O(1/n)=Θ(n), with Θ(n) stack depth. Moreover a nonzero discrete instruction cost cannot asymptotically decrease as 1/n. Therefore O(log n) is the intended abstract procedure-cost result, not an unconditional full implementation running-time claim.
Write a constant-time algorithm to insert data D just before a node whose address p is given in a singly linked list. State any limitation of the method.
Shared context
Write a constant-time algorithm to insert data D just before a node whose address p is given in a singly linked list. State any limitation of the method.
Answer & solution
Answer: Copy p’s old payload into a new successor, then store D at p; this inserts the value in sequence but changes node identity. (no official key was published)
With only p and no predecessor, one cannot in general redirect the predecessor’s next pointer in constant time while preserving the identity and payload of the existing node p. The standard answer implements insertion in the logical sequence by moving p’s old payload one node forward:
insert_before_value(p, D):
require p != NULL
q := allocate_node() // assumed O(1); handle allocation failure
q.data := p.data
q.next := p.next
p.data := D
p.next := q
return p // address now containing the inserted value
Before: ... → p:[old] → successor
After: ... → p:[D] → q:[old] → successor
The prefix still points to p, so no predecessor lookup is needed. The old data and suffix order are preserved. The method also works when p is the head or the tail. If an external tail pointer is maintained and p was the tail, update tail:=q.
The number of pointer and fixed-size data operations is constant. This assumes payload copying and allocation are constant-time. It does not preserve the old element’s address: external references to p now observe D. If “before the node p” literally requires the same p to remain the old node, the requested operation is impossible from p alone in a general singly linked list; supply its predecessor, an incoming-link pointer, or search from the head in O(n).
In a nonempty binary tree, a full node has exactly two children. Prove by induction on height that the number of leaves equals the number of full nodes plus one.
Shared context
In a nonempty binary tree, a full node has exactly two children. Prove by induction on height that the number of leaves equals the number of full nodes plus one.
Answer & solution
Answer: For every nonempty binary tree, L=F+1, including trees with one-child nodes. (no official key was published)
Use strong induction on the height h, taking a leaf to have height zero. Let L(T) and F(T) count leaves and full nodes in T.
Base h=0: T is a single leaf, so L=1 and F=0, giving L=F+1.
Induction hypothesis: the identity holds for every nonempty binary tree of height less than h. Consider a tree T of height h>0. Its root has one or two children.
If it has one child, the unique child subtree T₁ has smaller height. The root is neither full nor a leaf, so L(T)=L(T₁) and F(T)=F(T₁). By induction L(T)=F(T₁)+1=F(T)+1.
If it has two children with subtrees T₁,T₂, both have smaller height. Here L(T)=L(T₁)+L(T₂) and F(T)=1+F(T₁)+F(T₂), because the root itself is full. Substituting the two induction hypotheses gives L(T)=F(T₁)+1+F(T₂)+1=F(T)+1.
These cases exhaust all roots, proving the claim. The qualification “nonempty” matters: an empty tree has zero leaves and zero full nodes, so the formula would not hold there. It is unnecessary to assume every internal node is full.
Insert the specified sequence into an initially empty min-heap and draw the final heap and its state after deleting the root. Source discrepancy: GateForum p11 gives 7,6,5,4,3,2,1; GFG p7 visibly gives 7,6,5,4,2,3,1. Both are solved separately below; no official original is available to adjudicate.
Shared context
Insert the specified sequence into an initially empty min-heap and draw the final heap and its state after deleting the root. Both are solved separately below; no official original is available to adjudicate.
Answer & solution
Answer: [1,4,2,7,5,6,3] → [2,4,3,7,5,6] (no official key was published)
A binary min-heap has complete-tree shape and each parent no larger than either child. Store it in level order. On insertion append at the next free position and swap upward while smaller than its parent. Do not sort the whole array: a heap is only partially ordered.
Delete the root by moving the final element 3 into its position and removing that final slot. This gives [3,4,2,7,5,6]. Swap 3 with its smaller child 2, giving [2,4,3,7,5,6]. Now 3≤6, so downward repair stops. The final tree is:
2
/ \
4 3
/ \ /
7 5 6
The paper instead orders the last three insertions as 2,3,1. Its successive arrays are: [7] [6, 7] [5, 7, 6] [4, 5, 6, 7] [2, 4, 6, 7, 5] [2, 4, 3, 7, 5, 6] [1, 4, 2, 7, 5, 6, 3]
Its root-deletion result therefore also coincides. Preserving both source sequences is still important: agreement of the final answer does not establish that the printed questions were identical.
Five instructions pass in order through F, D, E, W. Their respective cycle requirements are I1=(1,2,1,1), I2=(1,2,2,1), I3=(2,1,3,2), I4=(1,3,2,1), I5=(1,2,1,2). Find the completion time.
Answer & solution
Answer: 15 clock cycles (no official key was published)
Step through it (7 steps)
Assume one instruction can occupy each stage at a time, in-order processing and no unmentioned data hazards. A completed instruction may wait for the next stage. A feasible schedule, using inclusive cycle ranges, is:
Instruction F D E W
I1 1 2–3 4 5
I2 2 4–5 6–7 8
I3 4–5 6 8–10 11–12
I4 6 8–10 11–12 13
I5 8 11–12 13 14–15
Waiting is not additional useful stage work: I2 stays at F through cycle 3; I3 stays at D during cycle 7; I4 stays at F during cycle 7; I5 stays at F through cycle 10. Thus the schedule is also feasible with ordinary backpressure rather than unbounded interstage queues. For a lower bound, even with unrestricted waiting buffers the earliest completion recurrence is C(i,j)=max(C(i−1,j),C(i,j−1))+duration(i,j), with zero boundary values. Its rows are (1,3,4,5), (2,5,7,8), (4,6,10,12), (5,9,12,13), (6,11,13,15). No legal schedule can finish before cycle 15, and the displayed schedule attains it. Summing all stage times would incorrectly remove pipeline overlap.
Answer: Counterexample p=false, q=true. (no official key was published)
An implication is false precisely when its antecedent is true and consequent false. Set p=false and q=true. Then ¬p ∨ q=true ∨ true=true, but q ⇒ p=true ⇒ false=false. The whole formula is therefore false. One counterexample suffices to refute a tautology; it need not be false on every valuation. Indeed the formula simplifies to p ∨ ¬q: ¬(¬p ∨ q) ∨ (¬q ∨ p)=(p ∧ ¬q) ∨ ¬q ∨ p=p ∨ ¬q. Its values for (p,q)=(F,F),(F,T),(T,F),(T,T) are T,F,T,T.
If A is a tautology and B is any propositional formula, prove A ∨ B is a tautology.
Answer & solution
Answer: A ∨ B is true under every valuation. (no official key was published)
Take an arbitrary valuation v of every propositional variable occurring in A or B. Because A is a tautology, v(A)=true regardless of that valuation. A disjunction is true if either operand is true, so v(A ∨ B)=true ∨ v(B)=true. Since v was arbitrary, the result holds for all valuations, which is exactly the definition of a tautology. No assumption about satisfiability of B is needed: B may be a tautology, contradiction, or contingent formula.
For this program, determine printed a under call by value: procedure P(x,y,z); begin y := y+1; z := x+x end; begin a := 2; b := 3; P(a+b,a,a); print(a) end. The initialization a:=2 is supplied by GFG; GateForum omits it.
Answer & solution
Answer: 2 (no official key was published)
At entry the actual expression a+b is evaluated to 5. Call by value creates three independent local cells x=5, y=2 and z=2. The first assignment changes only local y from 2 to 3. The second computes local z=x+x=10. Neither assignment writes caller a; the local cells disappear when P returns. Hence caller a remains 2 and print(a) outputs 2. The two occurrences of actual a do not create aliases in call by value.
Determine printed a under call by reference for: procedure P(x,y,z); begin y := y+1; z := x+x end; begin a := 2; b := 3; P(a+b,a,a); print(a) end. Use GFG’s visible a:=2 initialization, absent in GateForum, and discuss passing the expression a+b by reference.
Answer & solution
Answer: 10 under expression-temporary convention; strict variable-reference semantics reject the call. (no official key was published)
There is a language-semantic qualification: an ordinary assignable reference parameter cannot bind to the non-variable expression a+b. In a strict Pascal-style var-parameter language this call is invalid, so no output is defined. The customary exercise convention evaluates a+b once into an anonymous temporary t=5 and binds x to t, while both y and z refer directly to caller a. Then y:=y+1 changes a from 2 to 3. Next z:=x+x reads t twice, obtains 10, and writes a=10. Thus the intended trace under that convention prints 10. It does not print 12: reevaluating a+b after a changes would be call-by-name behavior, not a reference to the original temporary. The convention and the secondary initialization must both be stated rather than silently assumed.
Determine printed a under call by copy-restore for: procedure P(x,y,z); begin y := y+1; z := x+x end; begin a := 2; b := 3; P(a+b,a,a); print(a) end. GFG supplies a:=2, which is missing in GateForum. No copy-back order is specified.
Answer & solution
Answer: 10 if y restores before z; 3 if z restores before y; no unique output without a convention. (no official key was published)
Copy-in gives independent local values x=5, y=2, z=2. The body ends with x=5, y=3, z=10. Both y and z have the same copy-back destination, caller a, so restoration order matters. Restoring y then z sets a first to 3 and then to 10, printing 10. Restoring z then y sets a first to 10 and finally to 3, printing 3. Thus the given program has no uniquely determined copy-restore result unless the language specifies the order. A left-to-right formal-parameter restoration convention yields 10. As in reference passing, the non-variable actual a+b requires an expression temporary or a rule permitting input-only expressions; strict copy-in/copy-out parameters requiring assignable actuals reject the call. Under the temporary convention restoring unchanged x does not affect a. This is aliasing at copy-back, not aliasing between the local parameter cells.
In a Pascal skeleton, program sort declares a,x and the sibling procedures readarray, exchange, qsort. qsort declares k,v and a nested function partition, which declares i,j. The active call sequence is sort → qsort(1,9) → qsort(1,3) → partition(1,3) → exchange(1,3). Draw the runtime stack with access links after each activation.
Answer & solution
Answer: Both qsort frames and exchange link statically to sort; partition links to qsort(1,3). (no official key was published)
Access (static) links follow lexical nesting, whereas control (dynamic) links follow the caller. Label frames S=sort, Q1=qsort(1,9), Q2=qsort(1,3), P=partition(1,3), E=exchange(1,3). Each line below is a complete snapshot written bottom → top; the parenthesized target is the access link:
The final stack, top first, is: E : static→S; dynamic→P P : static→Q2; dynamic→Q2 Q2: static→S; dynamic→Q1 Q1: static→S; dynamic→S S : static→outer/null; dynamic→outer/null
Recursive Q2 is not lexically declared inside Q1, so its static link must not point to Q1. Partition accesses its enclosing qsort variables such as v through Q2, then global a through Q2→S. Exchange was declared directly inside sort, so its a and x references use E→S, even though partition called it. readarray is not active and has no frame in these snapshots. Return addresses and saved registers may also occupy frames but do not change the links.
For the assembly below with initial (R1,R2,R3)=(5,0,0), find R1 and R3 on reaching Z: X: CMP R1,0 JZ Z MOV R2,R1 SHR R1 SHL R1 CMP R2,R1 JZ Y INC R3 Y: SHR R1 JMP X Z: ... CMP sets comparison flags; JZ jumps on equality; MOV copies its second operand into its first; SHR/SHL shift by one bit.
Answer & solution
Answer: R1=0, R3=2 (no official key was published)
The SHR followed by SHL clears the least significant bit. Comparing the result against saved R2 detects whether that bit was 1. If so, increment R3. The SHR at Y then advances to the next bit. With nonnegative logical shifts the trace is:
Entry R1 | R2 after MOV | after SHR,SHL | R3 after test | R1 after Y
5 (101) | 5 | 4 (100) | 1 | 2
2 (010) | 2 | 2 (010) | 1 | 1
1 (001) | 1 | 0 (000) | 2 | 0
At the next X, R1=0 makes JZ Z branch before another iteration. Hence final R1=0 and R3=2. R2 happens to remain 1, though it is not requested. The two right shifts in the body do not skip two input bits because the intervening left shift restores the higher-bit positions.
For the same assembly with initial (R1,R2,R3)=(n,0,0), determine R3 on reaching Z: X: CMP R1,0 JZ Z MOV R2,R1 SHR R1 SHL R1 CMP R2,R1 JZ Y INC R3 Y: SHR R1 JMP X Z: ... CMP sets comparison flags; JZ jumps on equality; MOV copies its second operand into its first; SHR/SHL shift by one bit.
Answer & solution
Answer: R3=popcount(n), the number of 1 bits in n. (no official key was published)
For nonnegative integer n (or an unsigned fixed-width register with logical SHR), write current R1=2k+b, where b∈{0,1}. SHR then SHL yields 2k, so CMP detects inequality exactly when b=1; R3 therefore increases by b. The SHR at Y sets R1=k. After t iterations, R1=floor(n/2t) and R3 equals the number of ones in the t low-order bits removed from n. This invariant holds initially and is preserved by the decomposition 2k+b. Termination occurs when R1=0, after all significant bits have been examined, so R3 is the binary population count of n. For n=0 the initial branch exits immediately and R3=0. For negative signed inputs the outcome requires a specified word width and right-shift convention; arithmetic SHR is not covered by this nonnegative-integer proof.
Design 2048 eight-bit locations at 1000h–17FFh for an 8085, using four 1K×4 chips. Each has active-low /CS, /RD, /WR; address A0–A9; data D0–D3. /CS=1 makes data high impedance. GFG explicitly says eight-bit locations; GateForum loses the 8 in the prose.
Answer & solution
Answer: Two 1K×8 banks: 1000h–13FFh and 1400h–17FFh; decode A15…A11=00010 and select bank by A10. (no official key was published)
A 1K×4 chip has 1024 locations of four bits. Put two chips in parallel to make each 1K×8 bank, then use two banks for 2K×8. Name them L0,H0 and L1,H1. Wire all four address inputs to CPU A0–A9. In each bank L’s chip D0–D3 connect to CPU D0–D3, and H’s chip D0–D3 connect to CPU D4–D7. Both chips in a bank share selection and read/write controls.
1000h = 0001 0000 0000 0000 17FFh = 0001 0111 1111 1111 Thus A15…A11=00010 is fixed; A10 selects one of two banks; A9…A0 address a byte within the bank. Let M=NOT(IO/M), true on memory cycles, and S=M·¬A15·¬A14·¬A13·A12·¬A11. Then /CS0=NOT(S·¬A10), to L0 and H0 /CS1=NOT(S· A10), to L1 and H1. Bank 0 responds to 1000h–13FFh and bank 1 to 1400h–17FFh, with no other addresses selected. Connect CPU /RD and /WR to each chip’s /RD and /WR; memory qualification in /CS suppresses I/O-cycle responses.
8085 AD0–AD7 ──┬── bidirectional data bus D0–D7 ── both banks
└── ALE-controlled latch ── A0–A7 ── all chips
8085 A8,A9 ─────────────────────────────── A8,A9 ── all chips
A15…A10, IO/M ── decoder ── /CS0,/CS1
/RD,/WR ───────────────────────────────────────── all chips
The latch is essential because the 8085 multiplexes low address and data pins. The upper chip in each bank maps its local D0 to CPU D4, not CPU D0. Only one bank is enabled per address; deselected banks stay high impedance and cannot fight the data bus.
A byte-addressed segmented-paging system has 2^16 bytes in each of its virtual and physical address spaces, divided into 8 equal virtual segments. The hardware segment table points to each segment’s page table in main memory. Each page-table entry is 2 bytes. GateForum visibly prints 2^16; GFG loses exponent formatting and appears as 216. Find the smallest power-of-two page size for which one segment’s page table occupies at most one page.
Answer & solution
Answer: 128 bytes (no official key was published)
The eight segments need 3 segment-number bits, leaving 13 bits of segment offset. Each segment therefore contains 216/8=213=8192 bytes. If page size is P=2p bytes, the segment contains 8192/P pages and needs that many page-table entries. At 2 bytes each, its table occupies 16384/P bytes. The one-page requirement is 16384/P≤P, or P²≥16384=214. Thus p≥7 and the smallest allowed power of two is P=128. Verification: 8192/128=64 entries occupy 128 bytes exactly. The preceding power of two, 64 bytes, would need 128 entries or 256 bytes, exceeding one page. The hardware segment table does not add to the per-segment page-table storage being bounded.
A byte-addressed segmented-paging system has 2^16 bytes in each of its virtual and physical address spaces, divided into 8 equal virtual segments. The hardware segment table points to each segment’s page table in main memory. Each page-table entry is 2 bytes. GateForum visibly prints 2^16; GFG loses exponent formatting and appears as 216. With 512-byte pages, a direct-mapped TLB holds 16 virtual-page translations. How many tag bits per entry are needed?
Answer & solution
Answer: 3 tag bits (no official key was published)
A 512-byte page has 9 offset bits. Therefore the full 16-bit virtual address has 7 virtual-page-number bits. A 16-entry direct-mapped TLB uses 4 of those bits as its index, leaving 7−4=3 tag bits. In this segmented layout the address can be drawn as [segment:3 | page within segment:4 | byte offset:9]. Indexing by the low 4 virtual-page bits chooses the page number within a segment; the stored 3-bit segment tag distinguishes the eight segments that map to that same TLB slot. Page offset bits neither select a translation nor belong in its tag. This is the tag for the single address space described; unmentioned address-space identifiers or additional implementation status are not included.
A byte-addressed segmented-paging system has 2^16 bytes in each of its virtual and physical address spaces, divided into 8 equal virtual segments. The hardware segment table points to each segment’s page table in main memory. Each page-table entry is 2 bytes. GateForum visibly prints 2^16; GFG loses exponent formatting and appears as 216. With 512-byte pages, each entry has 1 valid bit, 3 protection bits and 1 dirty bit. How many bits remain for aging information?
Answer & solution
Answer: 4 aging bits (no official key was published)
There are 216/29=27 physical page frames, so a page-table entry needs 7 bits for the physical frame number. The offset is supplied by the original virtual address and is not stored in the entry. Each entry is 2 bytes=16 bits. The stated non-address metadata occupies 1+3+1=5 bits. Thus the aging budget is 16−7−5=4 bits. A valid field allocation is [frame number:7 | valid:1 | protection:3 | dirty:1 | aging:4], totaling 16. Subtracting a full 16-bit physical byte address would be wrong because a page frame is aligned and its low 9 offset bits need not be recorded. This answer assumes no additional unspecified fields consume the remaining capacity.
TSET register,flag atomically copies flag into register and sets flag=1. Give entry and exit pseudocode for a critical region.
Answer & solution
Answer: Spin until TSET returns 0; release by setting flag to 0. (no official key was published)
Initialize a shared flag to 0 before any competing process starts. Each process uses its own register r.
shared flag := 0
entry:
repeat
TSET r, flag
until r = 0
critical_region()
exit:
flag := 0
TSET must run on every retry; reading a stale r in a spin loop would never acquire the lock. When flag=0, exactly one atomic TSET can observe that 0 and simultaneously change flag to 1. That process enters; all later tests obtain 1 and continue waiting. Only the owner clears the flag on exit. This establishes mutual exclusion, assuming atomic release stores and the abstract sequentially consistent memory model of the question. Real machines additionally require appropriate acquire/release memory ordering. The scheme busy-waits and does not by itself guarantee bounded waiting or freedom from starvation.
A one-slot producer-consumer buffer uses count=0 initially. Tests and assignments of count are individually atomic. Producer repeats: produce item; if count=1 then sleep; put item in buffer; count:=1; wakeup(Consumer). Consumer repeats: if count=0 then sleep; remove item; count:=0; wakeup(Producer); consume item. Show an execution where both processes sleep.
Answer & solution
Answer: A wakeup between the consumer’s test and sleep is lost; producer later sleeps on the full buffer. (no official key was published)
Assume ordinary sleep/wakeup semantics: waking a process not currently asleep does not save a future wakeup token. The following interleaving is legal even though each test and assignment is atomic. 1. Consumer tests count=0 and gets true, but is preempted just before executing sleep. 2. Producer produces an item, tests count=1 (false), places the item, then atomically sets count=1. 3. Producer calls wakeup(Consumer). Consumer is not sleeping yet, so the notification is lost. 4. Consumer resumes at the pending sleep instruction and goes to sleep, without rechecking count. The buffer is full and count remains 1. 5. Producer begins its next iteration and produces another item. Its count=1 test is true, so it sleeps waiting for space. Now both processes are asleep. Only the sleeping consumer could remove the buffered item and wake the producer; only the sleeping producer could issue another consumer wakeup. Individual atomicity of test and assignment does not make the combined test-and-sleep sequence atomic. A semaphore that retains notifications, or correctly synchronized condition-variable wait with a predicate loop, prevents this lost-wakeup window.
In a B-tree, every non-root internal node has between m and 2m−1 children inclusive. The root is at level 0; all leaves are at level h≥1. Derive minimum and maximum numbers of records in the leaf nodes.
Answer & solution
Answer: Under standard B-tree key occupancy: minimum 2m^(h−1)(m−1); maximum (2m−1)^h(2m−2). (no official key was published)
State the usual B-tree assumptions explicitly: m≥2, an internal node with c children has c−1 records, the non-leaf root has 2 through 2m−1 children, and non-root leaves carry between m−1 and 2m−2 records. The printed child bound alone does not independently specify leaf capacity; these are the conventional B-tree occupancy rules, not B+ tree rules or the alternative maximum-2m convention. For the minimum, choose two root children and m children at every internal level below the root. The number of leaves is then Lmin=2mh−1: for h=1 there are two leaves; each further level multiplies their count by m. Filling each leaf with m−1 records gives Rmin=2mh−1(m−1). For the maximum, root and all other internal nodes have 2m−1 children, so Lmax=(2m−1)h. Filling every leaf with 2m−2 records gives Rmax=(2m−1)h(2m−2). Both bounds are attained by uniformly minimally or maximally occupied levels. These counts exclude records in internal nodes. For example m=2,h=1 gives 2 to 6 leaf records (2 leaves×1 up to 3 leaves×2), not the 3 to 8 total records including the root. If only the literal internal-child bound is permitted without standard leaf-occupancy rules, leaf record counts are underdetermined; only the leaf-node bounds follow with the usual root rule.
EMP(Employee-no, Dept-no, Employee-name, Salary), DEPT(Dept-no, Dept-name, Location). Return employee names whose department is located at Calcutta and salary exceeds Rs.50,000.
Answer & solution
Answer: Join EMP to DEPT and filter Location=Calcutta and Salary>50000. (no official key was published)
Use the common department identifier to join each employee to their department, then apply both predicates:
SELECT e."Employee-name"
FROM EMP AS e
JOIN DEPT AS d ON d."Dept-no" = e."Dept-no"
WHERE d.Location = 'Calcutta'
AND e.Salary > 50000;
The double quotes are standard SQL identifier quoting, required here because the printed attribute names contain hyphens. A database schema using Employee_name and Dept_no may use those unquoted names instead. The inequality is strict: salary exactly 50000 does not qualify. The department join is essential because Location belongs to DEPT, not EMP. This returns one row per matching employee under the usual department-key assumption; two employees sharing a name may produce duplicate name values. Add DISTINCT only if the intended output is a set of distinct names rather than names per employee. SQL NULL salaries do not pass the comparison.
EMP(Employee-no, Dept-no, Employee-name, Salary), DEPT(Dept-no, Dept-name, Location). For each department number, count employees whose salary exceeds Rs.1,00,000.
Answer & solution
Answer: LEFT JOIN all departments to qualifying employees and count the matching employee department values, including zeros. (no official key was published)
To interpret “for each department” literally, start from DEPT so that departments with zero qualifying employees are retained:
SELECT d."Dept-no", COUNT(e."Dept-no") AS high_salary_count
FROM DEPT AS d
LEFT JOIN EMP AS e
ON e."Dept-no" = d."Dept-no"
AND e.Salary > 100000
GROUP BY d."Dept-no";
The salary condition belongs in ON: placing it in WHERE would discard the null-extended rows and remove zero-count departments. COUNT(e."Dept-no") counts only actual matches, since a matched equality implies a non-null employee department value; COUNT(*) would incorrectly count the null-extended row as one. Salaries equal to 100000 do not qualify. This assumes the conventional unique department number in DEPT. If the expected interpretation asks only for department numbers represented by qualifying employees, the shorter traditional query is: SELECT "Dept-no", COUNT(*) AS high_salary_count FROM EMP WHERE Salary > 100000 GROUP BY "Dept-no"; That version omits zero-count departments. It is a different coverage choice, so the all-department query is preferable for the literal wording. Attribute names are quoted to preserve the printed hyphens.