skip to content

Discrete Mathematics

Logic, proofs, counting, relations, graph structure and modular arithmetic — the language used to argue a program is correct. Interviewers probe it when you must justify a bound, not just code one.

part ofComputer science fundamentalsoverview, primer and where to startread it →
on this pageshow

explore

questions

122 · 6 sections

A filter allows a request when authenticated AND (hasRole OR isServiceCall); what is the equivalent reject condition with the negation pushed inward?

level: juniorimportance: must knowfreq 68%
basics
~20 s

Reject when NOT authenticated OR (NOT hasRole AND NOT isServiceCall). De Morgan's laws flip each connective as the negation moves inward: the outer AND becomes OR, the inner OR becomes AND, and every atom is negated.

open as a page

A spec says every queued job is eventually acknowledged: what refutes that claim, and what do passing runs establish?

level: juniorimportance: must knowfreq 62%
basics
~20 s

One queued job that is never acknowledged refutes the claim completely; a single counterexample is a full disproof. Passing runs only fail to find one. They establish the claim only if they exhaust a finite domain.

open as a page

An alert rule says 'if the retry budget is exhausted, the request fails' - which restatement of it is guaranteed to hold?

level: juniorimportance: must knowfreq 72%
basics
~10 s

Only the contrapositive: 'if the request succeeded, the retry budget was not exhausted'. The converse and the inverse are different claims that can be false while the original rule still holds.

open as a page

How does 'every request has some handler' differ from 'some handler serves every request', and which implies the other?

level: middleimportance: must knowfreq 58%
basics
~20 s

Quantifier order decides whether the handler may vary per request. 'Some handler serves every request' fixes one handler for all of them and is the stronger claim: it implies 'every request has some handler', while the reverse fails.

open as a page

Why does the rule 'if the retry budget is exhausted, the request fails' count as true for a request that never retried?

level: middleimportance: must knowfreq 55%
basics
~20 s

Material implication is false on exactly one row: antecedent true, consequent false. A request that never exhausted its budget cannot produce that row, so the rule holds vacuously - and a vacuous truth is evidence of nothing.

open as a page

A service truncates each key's digest to 32 bits as a fingerprint; why are collisions eventually unavoidable?

level: juniorimportance: must knowfreq 70%
basics
~20 s

A 32-bit fingerprint has only 2^32 possible values, so any 2^32 + 1 distinct keys must contain two that share one. That is the pigeonhole principle; a better function cannot avoid it, only a wider field delays it.

open as a page

To attack by contradiction the claim that an allocator never hands one block to two callers, what do you assume?

level: middleimportance: must knowfreq 62%
basics
~20 s

Assume the claim fails: that some run exists in which one block is held by two callers at once. That single assumed run is a concrete object you can trace until it forces something impossible.

open as a page

Why prove the contrapositive of 'if a block is on the free list, no live pointer refers to it'?

level: middleimportance: must knowfreq 58%
basics
~20 s

The contrapositive — if a live pointer refers to a block, that block is not on the free list — states the same claim, but starts from a fact you can trace: a pointer, and the call that produced it.

open as a page

When a reviewer calls an induction proof circular, what does the inductive hypothesis actually let you assume?

level: middleimportance: must knowfreq 62%
basics
~20 s

Only smaller cases, never the case being proved. The step establishes an implication - if the claim holds at k, it holds at k+1 - and the base case supplies the first true instance, so nothing is assumed about the target.

open as a page

Why does proving that every integer above 1 factors into primes require strong induction?

level: middleimportance: must knowfreq 52%
basics
~20 s

Because a composite splits as n = a times b, where a and b can be far smaller than n - 1. A previous-value hypothesis says nothing about them; the strong form assumes the claim for every value below n, which does cover both factors.

open as a page

In a document tag filter, which set operation returns documents tagged either label, and which returns documents tagged both?

level: juniorimportance: must knowfreq 72%
basics
~20 s

Union gives 'either' — every document carrying at least one of the labels. Intersection gives 'both' — only documents carrying every selected label. As a user ticks more labels a union can only stay the same or grow; an intersection can only stay the same or shrink.

open as a page

A merge pipeline buckets rows by a grouping key: what must that key's equality and its hash satisfy for lookups to stay correct?

level: middleimportance: must knowfreq 72%
basics
~20 s

Equality must be an equivalence relation — reflexive, symmetric, transitive — and must stay stable while the key is stored. Equal keys must produce equal hashes; unequal keys are allowed to collide, and a collision never means equality.

open as a page

A merge pipeline groups customer rows by a 'same person' rule: which three properties must that rule satisfy for the groups to be well defined?

level: middleimportance: must knowfreq 64%
basics
~20 s

Reflexivity, symmetry and transitivity. A rule with all three is an equivalence relation, and only then does it cut the rows into disjoint groups where every row lands in exactly one group, whichever row you start from.

open as a page

A migration remaps every old record identifier to a new one: what does injectivity of that mapping guarantee, and what breaks without it?

level: middleimportance: must knowfreq 66%
basics
~20 s

Injective means no two distinct old identifiers are sent to the same new identifier. Lose it and two separate records land on one row in the target: one write overwrites the other, references converge, and no rollback can tell them apart.

open as a page

When does a remapping from old record identifiers to new ones have an inverse that translates any new identifier back?

level: middleimportance: must knowfreq 54%
basics
~20 s

Injectivity alone gives an inverse only on the identifiers the remap actually produced. To translate back any identifier the new store holds, the remap must also be surjective onto that set — together, a bijection onto it.

open as a page

In the expansion of (1 + x)^n, why does the coefficient of x^k count the k-member reviewer sets drawn from n engineers?

level: middleimportance: must knowfreq 58%
basics
~20 s

Expanding (1 + x)^n means one (1 + x) factor per engineer, and each factor contributes either 1 (stay off the review) or x (join it). A product becomes x^k exactly when k engineers contributed x, so its coefficient counts k-member sets.

open as a page

On an n-engineer roster, why does summing the number of possible reviewer sets of every size 0 through n give exactly 2^n?

level: middleimportance: must knowfreq 50%
basics
~20 s

Both totals count one collection: every reviewer set the roster can produce. Grouping that collection by size and adding the groups gives the sum of binomial coefficients; building a set by deciding in or out per engineer gives 2^n. One collection, two tallies, so they are equal.

open as a page

A nightly job must count records matching none of k taint filters - why must the correction terms alternate in sign?

level: middleimportance: must knowfreq 66%
basics
~20 s

Subtracting each filter's matches over-corrects records caught by several filters, so pairwise overlaps are added back, triples removed again, and so on. The alternating signs make every record matching at least one filter cancel to exactly zero.

open as a page

Using inclusion-exclusion, how do you count the IDs from 1 to 1000 divisible by none of 2, 3 and 5?

level: middleimportance: must knowfreq 50%
basics
~10 s

Subtract from 1000 the multiples of 2, 3 and 5, add back the multiples of 6, 10 and 15, then subtract the multiples of 30. That is 1000 - 734 = 266 surviving IDs.

open as a page

In a length-n maintenance schedule where no two maintenance slots may be adjacent, why does the count satisfy f(n)=f(n-1)+f(n-2)?

level: middleimportance: must knowfreq 60%
basics
~10 s

Split on the last slot. Idle leaves any valid (n-1)-schedule; maintenance forces the previous slot idle, leaving any valid (n-2)-schedule. The two cases are disjoint and exhaustive, so their counts add.

open as a page

In a replication mesh where each link joins two machines, why does the sum of machines' link counts equal twice the link count?

level: juniorimportance: must knowfreq 70%
basics
~20 s

Every link has two ends, and each end raises exactly one machine's link count by one. Totalling link counts therefore counts every link twice. This is the handshake lemma: the degree sum equals 2E, so it is always even.

open as a page

What does the chromatic number of a conflict graph tell a scheduler that joins clashing jobs by an edge?

level: middleimportance: must knowfreq 65%
basics
~20 s

The chromatic number is the fewest colours that label every vertex so no edge has one colour at both ends. On a conflict graph it is the minimum number of time slots any valid schedule can use.

open as a page

In a fibre backbone graph, what makes a site a cut vertex and a span a bridge?

level: middleimportance: must knowfreq 64%
basics
~20 s

A cut vertex is a site whose removal, together with its spans, leaves the network in more pieces than before; a bridge is a span whose removal alone does that. Both name single points of failure.

open as a page

In a fibre network, when can one closed route use every span exactly once?

level: middleimportance: must knowfreq 58%
basics
~20 s

Exactly when every span lies in one connected piece and every site has even degree. Each visit to a site uses one span in and one out, so an odd degree makes a closed route over every span impossible.

open as a page

A wiring plan gives each of seven machines exactly three replication links - why can no such mesh exist?

level: middleimportance: must knowfreq 54%
basics
~20 s

The degrees would sum to 7 x 3 = 21, which is odd, but every graph's degree sum equals twice its edge count and so must be even. The plan is impossible for any wiring, not just awkward ones.

open as a page

Given ac congruent to bc modulo n, when may you cancel c and conclude that a is congruent to b modulo n?

level: middleimportance: must knowfreq 48%
basics
~20 s

Only when c and n share no common factor, that is when their greatest common divisor is 1. Otherwise the honest conclusion is a congruent to b modulo n divided by that greatest common divisor, which is weaker.

open as a page

Bucketing keys by remainder modulo n collapses integers into residue classes: what exactly does that collapse preserve?

level: middleimportance: must knowfreq 62%
basics
~10 s

Addition, subtraction and multiplication survive: the class of a sum or product depends only on the input classes, never on which representatives you picked. Order, cancellation and the exponent position do not survive.

open as a page

A multiplicative inverse of a modulo n does not always exist - for which a does it exist, and why?

level: middleimportance: must knowfreq 62%
basics
~20 s

A value a has a multiplicative inverse modulo n exactly when gcd(a, n) = 1. If they share a factor g > 1, every product a*x reduced modulo n is a multiple of g, and 1 never is.

open as a page

How does the extended Euclidean algorithm turn gcd(a, n) = 1 into an actual inverse of a modulo n?

level: middleimportance: must knowfreq 55%
basics
~20 s

It returns integers x and y with ax + ny = gcd(a, n), by carrying those two coefficients alongside the remainders. When the gcd is 1, reducing modulo n drops the n*y term, so x is the inverse of a.

open as a page

Euler's theorem shrinks a huge exponent: when computing g^k mod n, what licenses replacing k with k mod phi(n)?

level: seniorimportance: must knowfreq 58%
basics
~20 s

Euler's theorem gives g^phi(n) congruent to 1 mod n whenever gcd(g, n) = 1, so the powers of g cycle with a period dividing phi(n) and only k mod phi(n) matters. Without that coprimality the reduction is simply invalid.

open as a page