The reasoning toolkit the rest of computer science quietly assumes: logic, proof, sets and relations, counting, recurrences and the number theory behind cryptography.
A proposition is a declarative statement with a definite truth value. Connectives build compound propositions, and a truth table settles any question about them mechanically.
| Connective | Symbol | Read as | True when |
|---|---|---|---|
| Negation | not p | p is false | |
| Conjunction | p and q | both are true | |
| Disjunction | p or q | at least one is true | |
| Exclusive or | p xor q | exactly one is true | |
| Implication | if p then q | always, except when p is true and q is false | |
| Biconditional | p if and only if q | both have the same truth value |
| Form | Statement | Equivalent to the original? |
|---|---|---|
| Original | - | |
| Converse | No | |
| Inverse | No (it is the converse's contrapositive) | |
| Contrapositive | Yes - always |
"If it rains, the ground is wet" does not mean "if the ground is wet, it rained" (converse). It does mean "if the ground is not wet, it did not rain" (contrapositive).
| Law | Form |
|---|---|
| De Morgan | and |
| Distributive | |
| Implication | |
| Contrapositive | |
| Absorption | |
| Double negation |
Propositional logic cannot express "every student passed" - it has no way to talk about individuals. Predicate logic adds predicates and quantifiers over a domain.
| Rule of inference | Form | Name |
|---|---|---|
| From and , infer | Affirm the premise | Modus ponens |
| From and , infer | Deny the conclusion | Modus tollens |
| From and , infer | Chain | Hypothetical syllogism |
| From and , infer | Eliminate | Disjunctive syllogism |
| Technique | To prove | Method | Use when |
|---|---|---|---|
| Direct | Assume p, derive q | The implication is straightforward | |
| Contraposition | Assume , derive | The negation is easier to work with | |
| Contradiction | Any statement s | Assume , derive an absurdity | Proving something does not exist |
| Induction | for all | Base case, then | The claim is indexed by a natural number |
| Strong induction | for all n | Assume , prove | The step needs more than the previous case |
| Counterexample | Exhibit one x with | Disproving a universal claim |
| Property | Definition | Example |
|---|---|---|
| Reflexive | , | "is equal to", "divides" |
| Symmetric | "is a sibling of" | |
| Antisymmetric | and both in R | "", "is a subset of" |
| Transitive | and in R | "", "is an ancestor of" |
| Function type | Condition | Consequence |
|---|---|---|
| Injective (one-to-one) | Distinct inputs give distinct outputs | |
| Surjective (onto) | Every element of the codomain is hit | |
| Bijective | Both | ; an inverse exists |
| Rule | Formula | Use |
|---|---|---|
| Product rule | Independent sequential choices | |
| Sum rule | Mutually exclusive alternatives | |
| Permutation | Arrange r of n - order matters | |
| Combination | Choose r of n - order does not matter | |
| With repetition (arrange) | r positions, n choices each | |
| With repetition (choose) | r items from n types, repeats allowed | |
| Circular permutation | Seat n people around a table |
A recurrence defines a term from earlier terms. Solving it means finding a closed form - which for algorithm analysis is exactly the running time.
Substitution (iteration)
Characteristic equation
Master theorem
| Recurrence | Closed form | Arises in |
|---|---|---|
| Linear search | ||
| Bubble sort, insertion sort worst case | ||
| Binary search | ||
| Mergesort | ||
| Towers of Hanoi |
int gcd(int a, int b) { // iterative
while (b) { int t = b; b = a % b; a = t; }
return a;
}
int gcd_rec(int a, int b) { // recursive - the definition itself
return b == 0 ? a : gcd_rec(b, a % b);
}
// gcd(48, 18) -> gcd(18, 12) -> gcd(12, 6) -> gcd(6, 0) = 610 questions on Discrete Mathematics · misses join your review queue, on this device only