Induction and Recursion

Learn to prove statements about every whole number with mathematical induction and strong induction, and see why the well-ordering principle makes these proofs valid. Define sequences, strings, trees and expressions recursively, and prove their properties with structural induction. Then model processes and algorithms as state machines, use invariants to show what can and cannot happen, and prove that recursive and iterative algorithms stop with the right answer.

IntermediateLesson 4 of 10 in Discrete Mathematics Course

What you will learn

  1. Use the principle of mathematical induction to prove that a statement holds for every integer from a starting value on, write complete induction proofs, and find the gaps in flawed ones.
    • Understand how an induction proof works
      State the principle of mathematical induction, explain why it is valid, and lay out a proof with a base case, an inductive hypothesis and an inductive step.
    • Prove sums, divisibility and inequalities by induction
      Apply induction to the classic kinds of claims: summation formulas, divisibility statements and inequalities, including claims that start after n=1.
    • Find the flaws in induction proofs and strengthen the claim
      Recognize the typical gaps in faulty induction arguments, check a proof systematically, and prove a stronger statement when the original claim cannot carry the inductive step.
  2. Prove statements in which a case depends on several smaller cases, and use the well-ordering principle to argue from a smallest counterexample.
    • Prove statements with strong induction
      State strong induction, decide when it is the right tool, and choose the base cases the inductive step needs.
    • Argue from a smallest counterexample with well-ordering
      State the well-ordering principle, use it to prove statements by contradiction from a least counterexample, and explain how it underlies induction and termination.
  3. Write recursive definitions that determine every value or element, compute with them, and define functions on recursively built structures such as strings and trees.
    • Define sequences and functions recursively
      Give a recursive definition of a sequence or function, compute its terms, check that the definition determines every value, and prove a guessed formula by induction.
    • Define sets, strings and trees recursively
      Build sets and structures from a basis and construction rules, define functions such as length, reversal, size and height on them, and recognize ambiguous definitions.
  4. Prove that every element of a recursively defined set has a property by checking the basis elements and every construction rule.
    • Apply structural induction to sets and strings
      Set up a structural induction proof with a case for each basis element and each rule, explain why it is valid, and use it for sets of numbers and strings.
    • Apply structural induction to trees and expressions
      Prove counting facts and inequalities about full binary trees and fully parenthesized expressions, and prove that functions defined on them behave as claimed.
  5. Describe a step-by-step process as a state machine, prove what is true in every reachable state, and prove that a process stops.
    • Describe a process as a state machine
      Identify the states, start state and transitions of a process, trace its executions, and decide which states are reachable in small examples.
    • Prove properties with preserved invariants
      Use the invariant principle to show that a property holds in every reachable state, prove that some states can never be reached, and strengthen a property that is not preserved.
    • Prove that a process terminates
      Use a strictly decreasing natural-number quantity to prove termination, separate partial correctness from termination, and handle processes that need a lexicographic measure.
  6. Specify what an algorithm must do and prove that recursive and iterative algorithms always stop with a correct answer.
    • Prove recursive algorithms correct
      Prove by induction on the size of the input that a recursive algorithm meets its specification, and check that every recursive call is valid and smaller.
    • Prove iterative algorithms correct with loop invariants
      State pre- and postconditions, find a loop invariant, and prove that a loop is correct by checking initialization, maintenance, exit and termination.

Induction and Recursion study guide

6 chapters

1

Prove statements with mathematical induction

Induction turns an infinite family of claims into a starting check and a general forward step. You will write that structure carefully, then use it for sums, divisibility, and inequalities. The algebra changes with the claim, but the logical duties stay the same. You will also examine broken proofs and learn how a stronger statement can supply information that a step is missing.

1.1 Build an induction proof

A claim about every natural number has infinitely many cases. Induction proves them through a starting case and a rule that carries truth forward. Here the natural numbers are ℕ={0,1,2,…}; the claim itself tells you whether to start at 0, 1, or another integer.

State exactly what changes

A predicate P(n) becomes a statement when you choose a value of n. For example, let P(n) mean “1+2+⋯+n=n(n+1)/2.” The intended claim is P(n) for every integer n≥1. The variable is part of the statement: the last term of the sum and both occurrences on the right change together.

Induction principle: If P(b) is true and P(k)⇒P(k+1) for every integer k≥b, then P(n) is true for every integer n≥b.

Think of dominoes in a row. The first must fall, and each must knock over the next. A missing first fall leaves the row standing; a gap stops the chain. For any chosen n, only n−b forward steps are needed to reach it. The well-ordering principle gives a rigorous justification of this argument.

Prove the sum formula

Base case. At n=1 the sum is 1, and 1(1+1)/2=1. Both sides agree.

Inductive hypothesis. Let k≥1 be arbitrary and assume

1+2+⋯+k=k(k+1)2.

Inductive step. The next sum contains the old sum and one new term. Split them before using the hypothesis:

1+2+⋯+k+(k+1)=k(k+1)2+(k+1).

The replacement of the old sum is the exact place the hypothesis enters. Put both terms over a common denominator and factor:

k(k+1)+2(k+1)2=(k+1)(k+2)2.

This is the proposed formula at n=k+1. Therefore, by induction, the formula holds for every integer n≥1. It gives 1+⋯+100=5050 without adding the hundred terms separately.

Keep assumption and conclusion separate

In the step you prove an implication. You temporarily assume the one statement P(k) and derive P(k+1). Because k was arbitrary, this establishes every forward link. Assuming “P(n) holds for all n” would already assume the entire conclusion.

Write the target P(k+1) on scratch paper to see where the algebra must end. In the finished proof, begin with a known expression for one side and transform it using justified equalities. Starting by declaring the target equation true risks using what you are trying to prove. Working backward is valid only when you justify the reverse implications.

An equivalent indexing convention proves P(k−1)⇒P(k) for k≥b+1. The hypothesis has moved one index, and so has the step's range. A claim beginning at 5 still needs P(5) as its base; checking P(6) would leave the first case uncovered.

Key Takeaways

  • State the predicate and its starting integer.
  • Check the base case directly.
  • Assume the claim at one arbitrary allowed integer and prove the next case.
  • Identify where the hypothesis is used; conclude for the full stated range.

1.2 Carry sums, divisibility, and bounds forward

The form of a claim suggests the useful first move. A longer sum contains a shorter sum; a larger power contains the previous power. For an inequality, the hypothesis supplies a bound that must still be compared with the next target.

Split off the new term

Summation notation abbreviates repeated addition: ∑i=1nai=a1+⋯+an. In the next case,

∑i=1k+1ai=∑i=1kai+ak+1.

For ∑i=0n2i=2n+1−1, the base case is n=0: both sides are 1. Assuming the formula through k gives

∑i=0k+12i=(2k+1−1)+2k+1=2k+2−1.

The new term is 2k+1, not 2k+2. The latter is part of the answer after combining terms.

For the square sum ∑i=1ni2=n(n+1)(2n+1)/6, the base case is 1=1⋅2⋅3/6. In the step, factor out the common k+1:

k(k+1)(2k+1)6+(k+1)2=(k+1)(2k2+7k+6)6.

Since 2k2+7k+6=(k+2)(2k+3), this is exactly the formula for k+1.

Expose an integer multiple

For integers d,t, divisibility d∣t means t=dm for some integer m. To prove 6∣7n−1 for n≥0, check 70−1=0=6⋅0. Assume 7k−1=6m. Then

7k+1−1=7(7k−1)+6=6(7m+1).

The coefficient 7m+1 is an integer, which proves divisibility. Multiplying the old expression by 7 also multiplies its constant term; the extra 6 repairs that difference.

Polynomial claims use the same strategy. For 3∣n3+2n, the base at 0 is immediate, and

(k+1)3+2(k+1)=(k3+2k)+3(k2+k+1).

The hypothesis handles the first term, and the displayed factor 3 handles the second.

Justify the extra inequality

Consider 2n>n2 for n≥5. At 5, 32>25. If 2k>k2, multiplying by 2 gives 2k+1>2k2. To finish, show 2k2≥(k+1)2:

2k2−(k+1)2=(k−1)2−2≥2(k≥3).

Thus 2k+1>2k2≥(k+1)2. The chain remains strict because its first comparison is strict. The step works from 3, but the claim fails at 2, 3, and 4; the valid consecutive range begins at 5.

Products work similarly. For n!>2n when n≥4, check 4!=24>16. Then

(k+1)!=(k+1)k!>(k+1)2k≥2⋅2k=2k+1.

The first bound uses the hypothesis and a positive multiplier. The second uses k+1≥2. Record both reasons so the algebra and the range can be checked separately.

Key Takeaways

  • For a sum, separate the last term before substituting the hypothesis.
  • For divisibility, rewrite the next expression as known multiples of the divisor.
  • A divisibility proof must leave an integer coefficient.
  • For an inequality, justify the comparison between the bound and the next target.
  • Choose a true base case even when the algebraic step works earlier.

1.3 Repair a broken induction argument

An induction proof is only as sound as its first case and its weakest forward link. Numerical checks can suggest a claim, but a proof needs a step that works throughout the claimed range. When a sound attempt stalls, the statement itself may need more information.

Locate the missing link

The expression n2+n+41 is prime for integers from 0 through 39. At 40, however, it equals 1681=412. Even a long run of successful tests leaves later cases open. Use tests to find a pattern or catch an error, then prove the general claim.

A valid implication can begin with a false premise. If you assume k=k+1, adding 1 gives k+1=k+2. This supplies a forward step for the false claim “n=n+1,” but no true base case starts it.

The reverse failure is a true base with an invalid first step. A familiar false argument says every set of balls has one color. For k+1 balls, remove the first ball and then the last. Each remaining group has k balls, so the argument uses the hypothesis to give each group a single color. It then uses their overlap to match the colors. When k+1=2, the groups each contain one ball and have no common ball. The step from 1 to 2 fails.

Check the quantifiers and direction

Proving P(3)⇒P(4) establishes one link. The general step needs an arbitrary integer k in its stated range. Proving P(k+1)⇒P(k) moves backward and cannot propagate the base to larger values. Assuming all cases at once is circular.

Check the algebra as carefully as the logic. An equality chain must use equal expressions; an inequality chain must preserve direction and justify multiplication signs. If the proof silently divides by an expression, verify that expression is nonzero.

Strengthen the statement to make room

Let Sn=∑i=1n1/i2. We want Sn<2. Assuming only Sk<2 gives Sk+1<2+1/(k+1)2, which is above the desired bound. The old bound leaves no stated allowance for the new positive term.

Prove the stronger claim

Sn≤2−1n(n≥1).

The stronger bound includes a gap below 2. At n=1, S1=1=2−1. If Sk≤2−1/k, then

Sk+1≤2−1k+1(k+1)2.

For k≥1,

1(k+1)2<1k(k+1)=1k−1k+1.

Substitution gives Sk+1<2−1/(k+1), which establishes the required weak inequality too. Finally, 2−1/n<2 for every positive integer n, so the original claim follows.

Strengthening the hypothesis means proving a more informative claim, with its own base and step. It never means simply assuming an unproved extra fact. Here the extra information is a quantitative gap that the next term cannot consume.

Before accepting a proof, check its predicate, starting case, arbitrary index, hypothesis range, use of the hypothesis, each transformation, and final conclusion. For a stalled proof, write down exactly what the next case needs; that often reveals the useful stronger statement.

Key Takeaways

  • Successful tests suggest a pattern; a general argument establishes it.
  • A true base and a valid step are both essential.
  • Test the smallest index at which the proposed step must work.
  • A stronger claim can carry information the next case needs.
  • Prove the stronger claim and show that it implies the original one.
  • Check the direction and range of every use of the hypothesis.
2

Use strong induction and the well-ordering principle

A proof may need several earlier cases, or a smaller case whose size depends on a factorization or split. Strong induction makes those dependencies explicit. Well-ordering approaches the same logic through a least possible failure. These methods also explain why a process cannot descend forever through the natural numbers, a fact that will later support termination proofs.

2.1 Use all earlier cases when the proof needs them

Some objects break into pieces of several sizes. A composite integer need not contain its immediate predecessor as a factor, and a split bar need not have equal pieces. Strong induction makes every earlier case available when proving the next one.

State the full hypothesis range

Strong induction proves P(n) for all integers n≥b by proving the needed initial cases and then deriving P(k+1) from all statements P(j) with b≤j≤k. A proof may use just some of those statements, but each use must stay in that interval.

For example, every integer n≥2 is prime or a product of primes. The base, 2, is prime. Assume the result for all integers from 2 through k. If k+1 is prime, it already has the required form. Otherwise write k+1=ab with 2≤a≤b≤k. Each factor has a prime factorization by the hypothesis, so multiplying them gives one for k+1. This proves existence of a factorization; uniqueness is a separate claim.

Follow a split into two smaller objects

Suppose a rectangular bar has n squares. Each break splits one piece into two along a groove. To separate it into single squares always takes n−1 breaks.

For one square, zero breaks are needed. Assume the claim for every size from 1 through k. The first break of a bar with k+1 squares makes pieces with a and k+1−a squares, both between 1 and k. Their remaining breaks total

(a−1)+(k+1−a−1)=k−1.

Including the first break gives k, as required. This works however uneven the split is. A 12-square bar takes 11 breaks.

Supply enough starting cases

Every integer amount of at least 12 cents can be formed from 4-cent and 5-cent stamps. Check the block

12=4+4+4,13=4+4+5, 14=4+5+5,15=5+5+5.

For k≥15, assume all amounts from 12 through k can be formed. The amount k+1−4=k−3 lies in that range. Form it using the hypothesis and add one 4-cent stamp. This gives k+1. Checking only 12 and 13 would leave 14 and 15 without a proof. The amount 11 is impossible: zero, one, or two 5-cent stamps leave 11, 6, or 1 cents, none divisible by 4.

The number of initial cases comes from the proof's dependencies. A step that uses both P(k−1) and P(k) needs two consecutive established cases before it starts. A sequence may be defined from two earlier terms while a particular property still has a one-base-case proof; inspect the property proof, not just the definition.

Compare the two induction forms

Strong induction gives a broader hypothesis, not a larger collection of provable claims. Define Q(n) to mean “every P(j) from b through n is true.” Ordinary induction on Q reproduces the strong-induction argument: the whole established block supplies the next case. Choose the form that makes the dependency easiest to see.

Key Takeaways

  • Strong induction makes every earlier case in the stated range available.
  • Check that each smaller piece stays above the starting value.
  • Choose base cases by examining how far back the step reaches.
  • Ordinary and strong induction have the same proving power.

2.2 Use the least possible failure

A contradiction proof can exploit the smallest place a claim might fail. Its strength comes from knowing that every earlier allowed case succeeds. The well-ordering principle guarantees that this smallest failure exists when any failure exists.

Know which sets have least elements

The well-ordering principle says that every nonempty set of nonnegative integers has a least element.

It also applies to a nonempty set of integers bounded below: shifting by an integer lower bound turns it into a set of nonnegative integers. The set of all negative integers has no least element. Positive rational numbers have none either, since x/2 is a smaller positive rational whenever x is one.

To prove P(n) for every n≥b, suppose the set of failures is nonempty and let m be its least element. Then P(j) holds whenever b≤j<m. Find a contradiction using that entire interval. Any smaller candidate must still lie in the allowed domain.

Find a prime divisor

Suppose an integer at least 2 has no prime divisor, and choose the least such integer m. It cannot be prime, because a prime divides itself. Thus m=ab for integers with 2≤a<m. Minimality says a has a prime divisor p. Since p∣a and a∣m, we get p∣m, a contradiction. So every integer at least 2 has a prime divisor.

Descend to a smaller denominator

Suppose 2=a/b for positive integers a,b, and choose a representation with the least denominator b. From a2=2b2, the numerator a is even; write a=2c. Substituting gives b2=2c2, so b=2d is even too.

Now 2=c/d, where d=b/2 is a positive integer smaller than b. This contradicts the chosen minimum. The contradiction rules out the assumed rational representation.

Make the remainder minimal

For any integer a and positive integer d, consider all nonnegative values a−dq with integer q. This set is nonempty: choosing q=−∣a∣ gives a nonnegative value. Let its least value be r. If r≥d, then r−d=a−d(q+1) is another nonnegative value of the same form and is smaller. Therefore 0≤r<d, and a=dq+r. For example, −17=5(−4)+3.

Connect minimality with induction

Assume a true base P(b) and a valid forward step, but suppose there is a least failure m. It is not b. Hence m−1≥b and P(m−1) is true, so the step forces P(m), contradicting failure.

Conversely, suppose a nonempty subset A of ℕ had no least element. Use induction to show that no natural number belongs to A. Zero cannot belong, since it would be least. If none of 0 through k belongs, then k+1 cannot belong either, since it would be least. This says A is empty, a contradiction. Together with the block-hypothesis argument for strong induction, these proofs establish the equivalence of all three principles.

Well-ordering also explains termination: an infinite strictly decreasing sequence of natural numbers would have a least value and then an even smaller next value.

Key Takeaways

  • A nonempty set of natural numbers has a least element.
  • A least-counterexample proof assumes failure and exploits all earlier allowed successes.
  • A smaller candidate must remain in the set under discussion.
  • Induction, strong induction, and well-ordering are equivalent.
  • A strictly decreasing natural-number sequence must end.
3

Define sequences, functions and sets recursively

Recursion builds a value or object from simpler ones. Initial values start a sequence; basis objects start a set of strings, trees, or expressions. You will compute examples, prove a guessed formula, and check whether the rules determine a unique result. The construction rules will also become the cases of structural proofs, so make their inputs and index ranges explicit.

3.1 Define values from earlier values

A recursive definition specifies initial values and explains how to obtain each later value from earlier ones. It describes how values are built. A closed formula instead gives the value directly from its index; induction can prove that a guessed formula matches the recursive definition.

Match the rule to its starting values

The basis gives initial values, and the recursive step gives the remaining ones. Factorial has basis 0!=1 and rule (n+1)!=(n+1)n! for n≥0. This gives 1!=1, 2!=2, and eventually 5!=120. Powers use a0=1 and an+1=a⋅an. A running sum starts with the empty sum, 0, and adds the next term.

The Fibonacci sequence needs two starting values:

f0=0,f1=1,fn=fn−1+fn−2(n≥2).

Its first terms are 0,1,1,2,3,5,8,13,21,34,55. Both earlier terms are needed to compute a later one. Some books begin with f1=f2=1, so identify the indexing convention before comparing formulas.

Guess a formula, then prove it

Let a0=1 and an=3an−1+2 for n≥1. Computing gives 1,5,17,53,161. Adding 1 gives 2,6,18,54,162, suggesting

an=2⋅3n−1.

At zero the formula gives 1. If it holds at k, then

ak+1=3ak+2=3(2⋅3k−1)+2=2⋅3k+1−1.

The recursion supplies the first equality and the inductive hypothesis supplies the second. The terms suggested the formula; the base and step establish it for every index.

Choose induction for the property

To prove fn<2n, check f0=0<1 and f1=1<2. For k≥1, the two earlier bounds give

fk+1=fk+fk−1<2k+2k−1<2k+1.

This proof uses two consecutive cases. By contrast, the sum identity f0+⋯+fn=fn+2−1 needs one base case. At zero it reads 0=f2−1. In the step, substitute the sum formula through k and add fk+1:

(fk+2−1)+fk+1=fk+3−1.

The Fibonacci rule completes the step without needing a second instance of the sum identity.

Check existence and consistency

A function is well defined when every allowed input receives exactly one value. For h(0)=0 and h(n)=h(n−2)+1 from n=1, computing h(1) calls for the undefined h(−1). Supply h(1)=0 and restrict the rule to n≥2 to cover both parity chains.

Conflicting clauses also fail: f(0)=0 and f(n)=f(n−1)+1 force f(2)=2, so an added clause f(2)=5 contradicts them. A later-index expression need not fail: g(n)=g(n+1)−1 rearranges to g(n+1)=g(n)+1. With g(0)=c it determines g(n)=c+n. Inspect the actual dependencies and equations before deciding whether a definition works.

Key Takeaways

  • A recursive definition needs initial values and a rule with a valid index range.
  • Each input must receive exactly one value.
  • A pattern guessed from terms still needs proof.
  • The property proof determines which earlier hypotheses and base cases are needed.

3.2 Build strings, sets, and trees by rules

Recursion can describe objects as well as numbers. Begin with simple objects, then specify every permitted way to build a larger one. Functions such as length, height, and evaluation can follow those same construction rules.

Include the exclusion rule

A recursive set definition has a basis, construction rules, and an exclusion rule: only objects obtained by finitely many applications of the rules belong. If 3∈S and x,y∈S implies x+y∈S, we build 3,6,9,12,…. The set is exactly the positive multiples of 3. One direction requires building every positive multiple; the other requires showing that no construction escapes that class.

Append one symbol at a time

An alphabet Σ is a finite set of symbols. The set Σ∗ of finite strings starts with the empty string λ. If w is a string and x∈Σ, then wx is a string. Over {0,1} this builds λ,0,1,00,01,10,11,…. Another common name for the empty string is ε.

Define functions by matching that construction:

  • Length: ℓ(λ)=0 and ℓ(wx)=ℓ(w)+1.
  • Concatenation: uλ=u and u(wx)=(uw)x.
  • Reversal: λR=λ and (wx)R=xwR.

For example, (abc)R=c(ab)R=cba. The last symbol moves to the front, while the shorter prefix is reversed recursively.

Balanced-parenthesis strings have three rules: the empty string is balanced; wrapping a balanced string u gives the balanced string “(u)”; joining balanced strings u,v gives “uv.” Thus “()()” joins two wrapped empty strings, and “(()())” wraps that result. “)(” cannot be built.

Join two full binary trees

A single vertex is a full binary tree. Given two such trees T1,T2, add a new root with their roots as its left and right children. Every vertex therefore has zero or two children. The children may have different heights.

A single vertex has size 1 and height 0. For a joined tree,

n(T)=1+n(T1)+n(T2), h(T)=1+max⁡(h(T1),h(T2)).

The extra 1 counts the new root or the extra edge level. A root with two leaves has size 3 and height 1. Some conventions give a single vertex height 1; here height counts edges on a longest root-to-leaf path.

Give expressions an unambiguous structure

Every variable or numeral is an expression. From expressions E,F, build (E+F), (E−F), or (E⋅F). Evaluate by first evaluating the two parts and then applying the operator. For ((x+3)⋅y) with x=2,y=5, the value is 25.

A function defined by construction must give the same answer whenever an object has multiple constructions. Full parenthesization fixes binary expression structure. Without grouping or precedence, “2+3⋅4” could be built as (2+3)⋅4 or 2+(3⋅4), giving 20 or 14. Ordinary arithmetic supplies precedence and chooses 14; a recursive grammar must specify its own resolution.

Key Takeaways

  • Only finite constructions from the basis belong to the recursively defined set.
  • Define a function by giving its value for every construction rule.
  • The empty string has length 0.
  • A full binary tree has zero or two children at every vertex.
  • Tree height here counts edges, so a single vertex has height 0.
  • Grouping or consistent alternative constructions make recursive evaluation well defined.
4

Prove properties of recursive structures with structural induction

Structural induction uses a recursive definition as its proof plan. A basis object supplies a base case, and each way of building an object supplies a preservation case. You will use this pattern for divisibility, strings, full binary trees, and expressions. Counting formulas and transformations then follow from properties of the immediate parts, even when those parts have different sizes.

4.1 Prove properties by following the construction

Structural induction follows how an object is built. Instead of asking only for a statement at the next integer, prove that every construction rule carries the property from its input objects to its output. The recursive definition tells you the cases to write.

Turn the definition into a proof plan

Prove the property for every basis object. Then, for each construction rule, assume the property for all objects used by that rule and prove it for the new object. These assumptions are the structural inductive hypotheses.

The exclusion rule makes this enough: each object has a finite construction, so repeated uses of the preservation steps reach it. This can be formalized as induction on construction length. Ordinary induction is the special case of building natural numbers from 0 using the successor rule.

For S defined by basis 3 and the rule x,y∈S⇒x+y∈S, prove every element is divisible by 3. The basis is 3=3⋅1. For the construction, assume x=3a and y=3b for integers a,b. Then x+y=3(a+b). Thus every member is a positive multiple of 3, and 10∉S.

To prove the reverse inclusion, ordinary induction builds 3n for every n≥1. The base is 3; if 3k has been built, add the basis element 3 to build 3(k+1). The two arguments together identify the set exactly.

Check both parenthesis rules

Let L(w) count left parentheses and R(w) count right parentheses. Prove equality for every balanced string.

  1. Empty string: both counts are 0.
  2. Wrapping: the string “(u)” adds one to each count. If L(u)=R(u), the new counts are equal.
  3. Joining: in uv the counts add. The hypotheses for u and v give L(u)+L(v)=R(u)+R(v).

Leaving out joining would leave an entire construction rule unproved. The hypothesis applies to the shorter input strings, not to the new string being constructed.

Equal totals rule out “((),” which has two left parentheses and one right parenthesis. But equal totals alone also hold for “)(.” A balanced string must satisfy the prefix condition: reading from the left, every initial segment has at least as many left as right parentheses. Equal totals together with that prefix condition characterize balanced strings.

Prove that lengths add

Fix any string u and use structural induction on v to prove ℓ(uv)=ℓ(u)+ℓ(v). At v=λ, concatenation gives uλ=u and the right side adds 0.

For the step, write v=wx with one final symbol x. Assume the length formula for w. Then

ℓ(u(wx))=ℓ((uw)x)=ℓ(uw)+1 =ℓ(u)+ℓ(w)+1=ℓ(u)+ℓ(wx).

The first line follows the recursive concatenation and length rules. The hypothesis replaces only ℓ(uw). Fixing u lets the induction focus on exactly the argument that gets shorter.

A construction proves membership. A property shared by all constructions can rule membership out. Keep these directions separate when using a structural proof to describe a set.

Key Takeaways

  • Use one basis case per starting object and one preservation case per rule.
  • Assume the property for the parts used in the construction.
  • Balanced parentheses need correct prefixes as well as equal totals.
  • A construction shows membership; a proved necessary property can exclude membership.
  • Choose the recursive argument that actually gets smaller.

4.2 Count and transform recursive trees

A full binary tree is either a single vertex or a new root joined to two full binary trees. Structural induction handles exactly these cases. The two subtrees can differ in size and height, so use separate hypotheses for each.

Count leaves and internal vertices

Let L(T) be the number of leaves and I(T) the number of internal vertices. We prove L(T)=I(T)+1. A single vertex has one leaf and no internal vertices, so the basis holds.

For a tree built from T1,T2, assume L(T1)=I(T1)+1 and L(T2)=I(T2)+1. The new root is internal, and the leaves come from the two subtrees:

L(T)=L(T1)+L(T2)=I(T1)+I(T2)+2.

Since I(T)=1+I(T1)+I(T2), this equals I(T)+1. Adding leaves and internal vertices gives n(T)=2I(T)+1, so every full binary tree has an odd number of vertices. A tree with every leaf at depth 2 has four leaves, three internal vertices, and seven vertices in total.

Bound the size from the height

Prove n(T)≤2h(T)+1−1. The single-vertex case is 1≤21−1. For the step, let m=max⁡(h(T1),h(T2)). The two inductive bounds imply

n(T)≤1+(2h(T1)+1−1)+(2h(T2)+1−1).

Each subtree height is at most m, so

n(T)≤2⋅2m+1−1=2h(T)+1−1.

The final equality uses h(T)=m+1. Equality need not hold: a root with one leaf child and one child having two leaves has height 2 and five vertices, below the upper bound 7. Assuming equal subtree heights would miss this valid shape.

Mirror twice

Define mir⁡(T)=T for a single vertex. For a joined tree, its mirror has mir⁡(T2) on the left and mir⁡(T1) on the right. Each level swaps its children.

To prove mir⁡(mir⁡(T))=T, the basis is immediate. In the step, the outer mirror swaps the children back. Its left subtree is mir⁡(mir⁡(T1))=T1 by one hypothesis; its right subtree is T2 by the other. The original ordered tree is restored.

Transfer the proof to expressions

A fully parenthesized binary expression has the same structure: atoms are leaves and binary operators are internal vertices. Thus it has one more atom than operators. Each binary construction also adds exactly one pair of parentheses, so the number of pairs equals the number of operators. In ((x+3)⋅y), there are three atoms, two operators, and two pairs of parentheses.

These statements concern full binary trees. A root with a single child has one leaf and one internal vertex, so the leaf formula fails for that different class. Strong induction on vertex count can reproduce the structural proof, since both subtrees have fewer vertices; following the construction makes the needed cases more visible.

Key Takeaways

  • For a full binary tree, leaves equal internal vertices plus 1.
  • The total number of vertices is odd: n=2I+1.
  • With single-vertex height 0, n≤2h+1−1.
  • Use separate hypotheses for the two subtrees, including unequal-height cases.
  • Mirroring twice restores the original ordered tree.
  • Binary expressions have one more atom than operators and one pair of parentheses per operator.
5

Model processes as state machines and reason with invariants

A process can be modeled through states and allowed transitions. One execution shows what can happen along a path; an invariant can describe every reachable state. You will build models, prove unreachable targets, and find measures that force executions to end. Keeping preservation and progress separate makes it possible to reason about machines with choices as well as deterministic algorithms.

5.1 Describe a process one state at a time

A state machine describes a process through snapshots and allowed moves. It separates the information the process needs from the details of how it is implemented. Once the model is explicit, you can ask which snapshots are possible and whether a run can continue forever.

Specify the machine

A state machine consists of a set of states, a start state, and a transition relation. Write q→r when one allowed step changes state q into state r. A state records all information needed to determine future moves and evaluate the property of interest.

For an algorithm, a state may include its variables and its current location in the instructions. If two snapshots have identical recorded values but different possible next actions, the model may need to record where execution is paused. Choose a transition size consistently, such as one whole loop pass.

An execution starts at the start state and follows allowed transitions. A state is reachable if some execution visits it, including the start state itself after zero steps. A state in the state set need not be reachable.

A machine is deterministic if each state has at most one successor. It is nondeterministic if some state permits a choice. A state with no outgoing transition is final. Deterministic describes choice, not whether the process ends: the counter 0→1→2→⋯ is deterministic and runs forever.

Model a diagonal robot

Let states be pairs (x,y) of integers, with start (0,0). A move changes each coordinate by either 1 or −1. Thus each state has four successors. The first moves reach

(1,1), (1,−1), (−1,1), (−1,−1).

The pair (1,0) is a state of the model, but whether it is reachable requires an argument about every possible path. Listing a few paths can establish reachability for visited states; ruling a state out requires more.

Model water jugs precisely

For a 3-liter jug and a 5-liter jug, use state (a,b) for the amounts in the small and large jug. Start at (0,0). A step fills either jug, empties either jug, or pours until the source is empty or the destination is full. Treat operations that leave the amounts unchanged as omitted moves in this model.

When pouring from the small jug to the large one, the amount transferred is

t=min⁡(a,5−b),

so the new state is (a−t,b+t). The minimum enforces both the available water and the receiving capacity. The reverse pour uses t=min⁡(b,3−a).

One execution is

(0,0)→(0,5)→(3,2)→(0,2)→(2,0)→(2,5)→(3,4).

It measures 4 liters in the large jug. Every arrow must match a full operation: you cannot stop a pour at an arbitrary unmarked level.

Read a model before proving a claim

State bounds, start conditions, and all move types are part of the problem. For a small finite machine, explore successors systematically, recording newly discovered states until none remain. For an infinite machine or a large branching one, a preserved property can settle a reachability question without listing all executions.

Key Takeaways

  • A state is a snapshot; a transition is one allowed move.
  • An execution begins at the start state and follows transitions.
  • Reachability requires at least one finite path from the start.
  • A deterministic machine can have an infinite execution.

5.2 Prove a property survives every move

An execution can have many steps and many choices. An invariant proof handles them together by checking one arbitrary allowed move. It is induction on the number of steps, with the start state as the base case.

Separate preservation from initialization

A predicate P is preserved when P(q) and q→r always imply P(r). If it also holds at the start, the invariant principle gives P in every reachable state. State both checks: a preserved property that is initially false cannot describe all reachable states.

Preservation must be proved from an arbitrary state satisfying P, checking every transition type. It is stronger than observing that a property holds in the runs tried so far. To prove a target unreachable, find an initialized preserved property that the target violates.

Use parity for the robot

For the diagonal robot starting at (0,0), let P(x,y) mean that x+y is even. Initially the sum is 0. Each move changes it by −2, 0, or 2, because both coordinates change by 1 or −1. Evenness is preserved.

Every reachable state therefore has an even coordinate sum. The target (1,0) has sum 1, so it is unreachable. The property “the sum is odd” is also preserved by the moves, but fails at the start. Preservation alone would not justify using it.

Check each jug operation

With 3-liter and 9-liter jugs, start with both empty. Use the invariant that each amount is a multiple of 3 liters.

  • Fill: the filled amount is 3 or 9, a multiple of 3.
  • Empty: the emptied amount is 0, also a multiple of 3.
  • Pour: from state (a,b), a transfer amount is min⁡(a,9−b) or min⁡(b,3−a). Under the hypothesis both arguments of either minimum are multiples of 3, so the transferred amount is too. Adding and subtracting it preserves the property.

Neither jug can hold 4 liters in any reachable state. The eight reachable pairs are exactly those with a∈{0,3} and b∈{0,3,6,9}. The divisibility invariant alone rules out 4; listing the eight states also requires checking paths to them and capacity restrictions.

Strengthen a true but unpreserved claim

Consider states in ℕ, start 0, and transition x→x+2. Every reachable state avoids 3. Yet the predicate x≠3 is not preserved on the whole state set: 1→3 breaks it.

Use the stronger property “x is even.” It holds initially and survives adding 2. Since 3 is odd, this property implies the desired claim. A stronger invariant supplies information that makes the preservation step possible, just as a stronger inductive hypothesis can repair a stalled induction.

An invariant need not keep a quantity constant. “The sum is even” allows the sum to change. What remains true is the predicate; a constant quantity is one useful special case.

Key Takeaways

  • Prove both initialization and preservation.
  • Check every transition type from an arbitrary state satisfying the predicate.
  • A target violating a proved invariant is unreachable.
  • A predicate can hold on reachable states without being preserved on all states.
  • A stronger invariant can make preservation provable.

5.3 Find a measure that must run out

An invariant explains what stays true while a process runs. A termination argument explains why it cannot keep running. The useful quantity often measures work left, but it must decrease on every allowed step and stay in a domain where endless descent is impossible.

Use a natural-number measure

A derived variable assigns a value to each state, such as v(a,b)=a+b. It is strictly decreasing if every transition q→r satisfies v(r)<v(q). Weak decrease allows equality.

If a natural-number-valued measure strictly decreases on every transition, every execution is finite. From start state q0, there are at most v(q0) transitions.

Each strict decrease between integers is at least 1. After more than the initial value in steps, the measure would be negative. Equivalently, well-ordering rules out an infinite descending sequence of natural numbers.

Prove subtractive gcd terminates

Start with positive integers a,b. While they differ, subtract the smaller from the larger. Positivity is preserved: subtracting a smaller positive integer from a larger one leaves a positive integer.

If a>b, the sum changes from a+b to (a−b)+b=a, dropping by b>0. The other case drops it by a>0. Thus a+b is a strictly decreasing natural-number measure.

For example,

(84,36)→(48,36)→(12,36)→(12,24)→(12,12).

The sums are 120,84,48,36,24. The process stops at equality. To identify the result, use the separate invariant gcd⁡(a,b)=gcd⁡(84,36). Subtracting one input from the other preserves common divisors. At equality, gcd⁡(a,a)=a, so the final value is 12.

The invariant gives partial correctness: if the process stops, its answer is right. The decreasing measure supplies termination. Both together give total correctness.

Check the domain and strictness

An integer value can decrease forever if it is unbounded below: 0,−1,−2,…. A positive real value can also decrease forever: 1,1/2,1/4,…. Being positive and decreasing is therefore insufficient without a suitable domain. A weakly decreasing natural number also allows an endless constant run, including a self-loop.

Use a pair when one coordinate can grow

Consider natural-number states (r,b). A move either changes them to (r−1,b+k) for any chosen natural number k when r≥1, or to (r,b−1) when b≥1.

Every move decreases the pair in lexicographic order: compare the first coordinate first, and compare the second only when the first is unchanged. In an infinite run, r could decrease only finitely often. After its last decrease, every remaining move would strictly decrease the natural number b, which is impossible. Hence every run is finite.

There is no uniform finite bound on run length from (1,0): the first move can choose any finite k and produce (0,k), followed by k decrements. Each particular run ends, while the collection of run lengths is unbounded. Termination and a fixed step bound are different claims for this machine.

Key Takeaways

  • A natural-number measure must decrease strictly on every transition.
  • Show the measure remains a nonnegative integer.
  • Partial correctness plus termination gives total correctness.
  • A lexicographic pair may decrease even when its second coordinate grows.
  • All runs can be finite while their lengths have no common finite bound.
6

Prove algorithms correct with induction and invariants

Correctness begins with a precise promise about allowed inputs and required outputs. For recursion, prove smaller calls correct and check how their results are combined. For loops, describe the partial result with an invariant and use the exit condition to reach the postcondition. In either form, a decreasing measure supplies termination, so the proof establishes both a correct answer and a finite run.

6.1 Prove recursive calls return the right result

A recursive algorithm delegates work to smaller inputs. Its proof follows those calls: prove the direct returns correct, assume correctness on smaller allowed inputs, and verify how the current call combines their results. The input conditions and the size measure are part of the proof.

Specify the promise and the goal

A precondition states which inputs are allowed. A postcondition states what the returned result must satisfy. For a recursive factorial algorithm, the precondition is an integer n≥0 and the postcondition is “the returned value equals n!.”

Use a nonnegative integer size measure. Each recursive call must preserve the precondition and strictly reduce that measure. Strong induction then makes the results of every smaller call available. Ordinary induction can suffice when a proof depends only on the preceding size.

Prove factorial correct

The algorithm returns 1 at zero and otherwise returns n⋅fact⁡(n−1). At zero the return is 1=0!. If fact⁡(k)=k!, then

fact⁡(k+1)=(k+1)fact⁡(k)=(k+1)!.

For positive input, subtracting 1 gives a smaller nonnegative integer, so the calls reach zero. A negative input violates the precondition and produces an endless descent through negative integers.

Prove Euclid's recursive step

For nonnegative integers a,b not both zero, return a when b=0. Otherwise call the algorithm on (b,a mod b). Let r=a−qb be the remainder, so 0≤r<b.

Any common divisor of a,b divides r. Conversely, a common divisor of b,r divides a=qb+r. Thus gcd⁡(a,b)=gcd⁡(b,r). The new first input is positive, so the pair is still allowed, and its second input is smaller. Induction on that second input proves correctness and termination.

For instance,

(252,198)→(198,54)→(54,36)→(36,18)→(18,0).

The returned value is 18.

Handle calls at several smaller sizes

For powers, return 1 at n=0. For positive even n, recursively compute h=power⁡(a,n/2) and return h2. For odd n, return apower⁡(a,n−1). Strong induction on n supplies correctness of either smaller call:

h2=(an/2)2=an,a⋅an−1=an.

Handle zero before the even branch; otherwise zero would call itself. The base a can be fixed while the induction follows the exponent. For 313, the exponent calls are 13,12,6,3,2,1,0 and the result is 1594323.

Merge sort uses strong induction on list length. Lists of length 0 or 1 return unchanged. For n≥2, both halves have smaller lengths, so their recursive results are sorted rearrangements of their inputs. A correct merge combines them into a sorted rearrangement of the original list. The specification needs both sortedness and preservation of elements: an empty output is sorted but generally loses the input.

At each call, check smaller size, valid input, and correct combination. Assuming correctness on the current input would bypass the induction instead of proving it.

Key Takeaways

  • State preconditions and postconditions before the proof.
  • Match proof bases to the algorithm’s direct returns.
  • Check that every recursive call has a smaller measure and an allowed input.
  • Use the inductive hypothesis for recursive calls, then verify the combination.
  • For sorting, prove both sorted order and preservation of all input elements.

6.2 Prove a loop with an invariant and an exit condition

A loop may perform an unknown number of passes. Its invariant describes what the variables mean at the boundary between passes. The proof must connect that meaning to initialization, each update, and the result when the loop condition becomes false.

Organize four checks

For precondition p, program S, and postcondition q, the notation {p} S {q} expresses partial correctness: an allowed run that terminates satisfies the postcondition. Some books write p{S}q. Total correctness also guarantees termination.

A loop proof checks:

  1. Initialization: the invariant holds before the first pass.
  2. Maintenance: the invariant and true loop condition imply the invariant after the body.
  3. Exit: the invariant and false loop condition imply the postcondition.
  4. Termination: a suitable measure decreases on every pass.
Track the factorial already computed

For an integer n≥1, use this loop:

f := 1
i := 1
while i < n:
    i := i + 1
    f := f * i

At loop boundaries use f=i! and 1≤i≤n. Initialization gives f=1=1!. For maintenance, call the old index j. The first assignment makes i=j+1; the second makes f=j!(j+1)=(j+1)!. Since the guard gave j<n, the new index is still at most n.

At exit, i≥n from the false guard and i≤n from the invariant give i=n. Hence f=n!. The natural number n−i decreases by 1 per pass, proving termination. For n=5 the boundary pairs (i,f) are (1,1),(2,2),(3,6),(4,24),(5,120). The assignment order matters: multiplying before incrementing would use the old factor.

Preserve a product during exponentiation

To compute ab for integer b≥0, start with x=a,y=b,z=1. While y>0, use the odd branch z:=zx followed by y:=y−1, or the even branch x:=x2 followed by y:=y/2. The invariant is

zxy=ab,y∈ℕ.

It holds initially. In the odd branch, the new product is (zx)xy−1=zxy. In the even branch it is z(x2)y/2=zxy. These equations use the old values on their right sides. At exit y=0, so the invariant yields z=ab. During every pass, the positive integer y strictly decreases, so the loop ends.

Find an invariant from a partial result

For a list sum, the final claim “all entries have been added” suggests tracking a prefix: s=A[1]+⋯+A[i] with 0≤i≤n. Initialization at i=0,s=0 uses an empty sum. A pass extends the prefix by one entry; at exit the bounds and guard establish i=n.

A true but weak statement such as s≥0 may say too little to identify the output. Also keep the invariant distinct from the guard: the guard becomes false at exit, while the invariant remains available. A loop invariant is an inductive claim about the number of completed passes, even when its formula is written using other variables.

Key Takeaways

  • Use initialization, maintenance, exit, and termination as separate checks.
  • At exit, combine the invariant with the negated loop condition.
  • Respect the order of assignments and distinguish old from new values.
  • Choose an invariant that identifies the partial result.
  • Use a decreasing measure to add termination to partial correctness.
  • Loop invariants and recursive correctness proofs both use induction.

Induction and Recursion examples

6 Walkthroughs

1

From a first case to every case

16 steps
Build an induction proof, adapt its step, and repair an argument that needs a stronger claim.
  1. 1
    IntroductionProve a whole family

    Checking ten cases of a formula leaves infinitely many unchecked. Induction replaces that unfinished list with two obligations: establish the first case and prove that any established case carries the next one.

    We will build a sum proof, adapt the step to divisibility, and diagnose why a seemingly useful bound can be too weak to continue.

  2. 2
    AnalogyStart the chain and connect the links

    Picture a row of dominoes. Two facts matter: the first falls, and each falling domino knocks over the next. Induction has the same structure: a base case and a forward implication.

    Any chosen position is finitely far from the first. You do not check every position separately; you establish the rule that reaches it. A missing first fall or a broken link leaves the argument incomplete.

  3. 3
    ExampleChoose the statement and its base

    Let P(n) say that the first n odd positive integers sum to n2:

    1+3+⋯+(2n−1)=n2(n≥1).

    At n=1, the sum and the square both equal 1. This checks the base. Notice that the claim starts at 1; our convention that natural numbers include 0 does not change the theorem’s chosen range.

  4. 4
    ExplanationAssume one arbitrary case

    Let k≥1 be an arbitrary integer. Assume

    1+3+⋯+(2k−1)=k2.

    This is the inductive hypothesis. We are proving an implication, so assuming its premise is legitimate. Our target is the next sum, ending at 2(k+1)−1=2k+1. Both the last summand and the square on the right must change to the new index.

  5. 5
    ExampleUse the old sum inside the new one

    Separate the new last term from the earlier sum:

    1+3+⋯+(2k−1)+(2k+1)=k2+2k+1.

    The hypothesis replaces exactly the earlier sum. Factoring gives

    k2+2k+1=(k+1)2.

    That is P(k+1). The base is true and the implication works for arbitrary k≥1, so induction establishes the formula for every positive integer.

  6. 6
    ChallengeShift the starting point

    A claim starts at n=6. A proposed proof checks P(7) and proves P(k)⇒P(k+1) for every k≥6. What case is still missing?

    ---reveal---

    The proof has not established P(6). Starting at 7 and moving forward reaches only cases from 7 on. Check P(6) directly; the given forward step can then cover 7 and every later integer.

  7. 7
    ExplanationChoose the algebra from the claim

    The next sum contains the old sum, a larger factorial contains the old product, and a larger power contains the old power. Expose that part before substituting the hypothesis.

    For divisibility, aim for an integer multiple of the divisor. For an inequality, the hypothesis gives one comparison; a second estimate may be needed to reach the target at the new index.

  8. 8
    ExampleExtract the previous power

    Prove 10∣11n−1 for n≥0. At zero, the expression is 0=10⋅0. Assume 11k−1=10m for an integer m.

    The next expression can be rewritten as

    11k+1−1=11(11k−1)+10.

    This places the old expression inside the new one, while the remaining term is visibly divisible by 10.

  9. 9
    ExampleFinish the integer-multiple argument

    Use the hypothesis in the exposed old expression:

    11(11k−1)+10=11⋅10m+10=10(11m+1).

    The coefficient 11m+1 is an integer, so the next expression is divisible by 10. Both the base and the general step are proved. The added 10 matters: multiplying 11k−1 by 11 changes the constant to −11, so the rewrite must compensate for that change.

  10. 10
    ChallengeFind the next comparison

    Suppose an induction step for 4n≥n+1 has reached 4k+1≥4k+4 with k≥0. What bound finishes the step?

    ---reveal---

    The new target is k+2. Since 4k+4−(k+2)=3k+2≥0,

    4k+1≥4k+4≥k+2.

    The hypothesis supplies the first comparison; the nonnegative difference supplies the second.

  11. 11
    TipInspect the first required link

    A proof may use a construction that works only once objects are large enough. Substitute the smallest index into that construction.

    In the same-color argument, removing opposite endpoint balls creates two groups whose overlap is supposed to connect their colors. For a two-ball set the groups are disjoint. A true one-ball base cannot pass that broken first link, even though larger groups overlap.

  12. 12
    ExplanationFind what a weak bound leaves out

    Let Sn=∑i=0n2−i. We want to prove Sn<2. Assuming only Sk<2 and adding the next positive term gives a bound above 2:

    Sk+1<2+2−(k+1).

    The statement has not recorded how far the partial sum lies below 2. A more informative claim can preserve that gap while the sum grows.

  13. 13
    ExampleProve the gap as part of the claim

    Prove instead Sn=2−2−n. At zero, S0=1=2−1. Assuming the formula at k,

    Sk+1=2−2−k+2−(k+1)=2−2−(k+1).

    This completes the equality proof. Since 2−n>0, it also proves Sn<2. The stronger statement tells us exactly how much remains below the bound; it is established, not added as an unsupported assumption.

  14. 14
    ChallengeCheck the stronger proof

    A learner checks S0<2, then uses Sk=2−2−k to derive the next equality. Has that proved the stronger claim needed for the argument? Explain the repair.

    ---reveal---

    The step assumes an equality, so its base must establish that equality too. Check S0=1=2−20. With the equality base and equality step in place, induction gives the stronger formula, which then implies the desired strict bound.

  15. 15
    Key InsightMore information can make the step easier

    A stronger statement can be easier to propagate because it describes the changing quantity more precisely. In the partial-sum proof, the explicit gap supplies what the next positive term needs.

    This is a proof-design choice: formulate the extra information, check its base, prove its own forward step, and only then use it to obtain the original result.

  16. 16
    RecapChoose the claim that supports the next case

    Use a base that matches the first claimed index, and make the forward step work for every allowed index. Inside the step, expose the old expression and show exactly where its hypothesis enters.

    If the step breaks, distinguish an invalid argument from an unhelpfully weak statement. Checking the first link can reveal a gap; adding proved quantitative information can supply a missing link.

2

Use smaller cases and least failures

13 steps
Choose the available earlier cases, supply enough bases, and reason from a least counterexample.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionWhen the previous case is not enough
  2. 2
    ExplanationMake the hypothesis an interval
  3. 3
    ExampleSplit a composite number
  4. 4
    ExampleCombine the smaller factorizations
  5. 5
    ExplanationCheck the first legal dependency
  6. 6
    ChallengeSupply a missing initial block
  7. 7
    ExplanationChoose the smallest possible failure
  8. 8
    ExampleA least number with no prime divisor
  9. 9
    ExamplePush the smaller success back to the failure
  10. 10
    ChallengeCheck whether a least element exists
  11. 11
    ConnectionSee why induction cannot have a first failure
  12. 12
    ChallengeApply minimality without stepping outside the domain
  13. 13
    RecapFollow the actual dependency
3

Build recursive values and objects

14 steps
Compute recursive terms, verify a guessed formula, and define functions on strings and trees.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionLet simple cases build the rest
  2. 2
    ExampleCompute before guessing
  3. 3
    ExplanationProve the guessed formula
  4. 4
    TipDraw the dependency chains
  5. 5
    ChallengeRepair the definition
  6. 6
    Key InsightThe property decides the proof’s bases
  7. 7
    ExplanationStart, construct, exclude
  8. 8
    ExampleAppend a symbol and define length
  9. 9
    ExampleReverse by following the final symbol
  10. 10
    ExplanationJoin two trees under a new root
  11. 11
    ChallengeUse both tree functions
  12. 12
    ExplanationGive evaluation a unique structure
  13. 13
    ChallengeConnect a tree construction to a sequence
  14. 14
    RecapMake every rule executable from the basis
4

Prove a property for every construction

14 steps
Follow the rules for strings and trees, then use their structure for counts and transformations.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionLet the definition choose the proof cases
  2. 2
    ExplanationMatch every rule
  3. 3
    ExampleKeep the two counts equal
  4. 4
    Key InsightA necessary condition may not characterize membership
  5. 5
    ChallengeFind the missing proof case
  6. 6
    ExampleCount a one-vertex tree
  7. 7
    ExampleCombine the subtree hypotheses
  8. 8
    ChallengeUse the count to test a proposed tree
  9. 9
    ExplanationUse the taller subtree for a bound
  10. 10
    ExampleSwap twice and use both hypotheses
  11. 11
    ConnectionRead an expression as a tree
  12. 12
    ChallengeCombine a construction and its property
  13. 13
    TipChoose a size only when it helps
  14. 14
    RecapCount the inputs and the new contribution
5

What a process can do—and why it stops

16 steps
Model transitions, prove invariants, and distinguish correct results from guaranteed termination.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionDescribe behavior before proving it
  2. 2
    ExplanationSpecify states, start, and moves
  3. 3
    ExampleModel diagonal motion
  4. 4
    ChallengeDistinguish a snapshot from a path
  5. 5
    ExplanationInitialize, then preserve
  6. 6
    ExampleUse the robot’s parity
  7. 7
    TipTest preservation where the predicate holds
  8. 8
    ChallengeCheck all the jug operations
  9. 9
    ExplanationMeasure what must run out
  10. 10
    ExampleTrack positive subtraction
  11. 11
    ExampleSeparate progress from the answer
  12. 12
    ChallengeFind the missing termination condition
  13. 13
    ExplanationLet the first coordinate take priority
  14. 14
    Key InsightFinite runs need not have a uniform bound
  15. 15
    ChallengeCombine a result invariant and a measure
  16. 16
    RecapProve preservation and progress separately
6

From an algorithm specification to a proof

15 steps
Prove recursive calls and loop updates correct, then add a termination argument.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionState what the algorithm must deliver
  2. 2
    ExplanationTurn recursive calls into hypotheses
  3. 3
    ExampleProve factorial’s return
  4. 4
    ExampleChoose Euclid’s second argument
  5. 5
    ExplanationProve the output relation too
  6. 6
    ChallengeCheck a recursive power algorithm
  7. 7
    ExplanationName the loop obligations
  8. 8
    ExampleInitialize the factorial loop
  9. 9
    ExampleMaintain the invariant in assignment order
  10. 10
    ExampleUse the exit condition and the measure
  11. 11
    ChallengeTest an off-by-one invariant
  12. 12
    ExplanationPreserve an expression, not each variable
  13. 13
    ChallengeProve matching recursive and iterative results
  14. 14
    ConnectionKeep the whole sorting promise
  15. 15
    RecapConnect each proof fact to the specification

Induction and Recursion practice questions

50 Practice Questions in 5 sets

Set 1: Practice 2: Check ranges and construction rules10 Practice Questions

Question 1 of 10

On nonnegative integers, let u0=4 and un=un−2+2 for n≥2. What information is missing for the definition to determine every term?
  1. A new value for u0.
  2. A value for u−2.
  3. An additional value for u2.
  4. An initial value for u1.
Show answerHide answer
Answer: D
The rule computes the even terms from u0 but the odd terms depend on u1, which has not been assigned. Supplying u2 adds no needed start because the rule already forces u2=6. The rule never applies at a negative input or at zero.

Question 2 of 10

A full binary tree has 9 internal vertices. How many vertices does it have in total?
  1. 17
  2. 19
  3. 18
  4. 10
Show answerHide answer
Answer: B
A full binary tree with 9 internal vertices has 9+1=10 leaves, giving 9+10=19 vertices. The value 10 counts only the leaves. Doubling the internal count misses the extra leaf supplied by the single-vertex basis.

Question 3 of 10

In an induction proof starting at 4, what is the hypothesis for the step from k to k+1?
  1. Assume P(n) for every integer n≥4.
  2. Assume P(4) and choose the specific integer k=4.
  3. Assume P(k) for an arbitrary integer k≥4.
  4. Assume P(k+1) for an arbitrary integer k≥4.
Show answerHide answer
Answer: C
The step temporarily assumes the claim at one arbitrary allowed index and derives the next case. Assuming every case would assume the desired theorem. Restricting the index to 4 proves only one forward link, leaving later links unestablished.

Question 4 of 10

To prove 4∣5n−1, assume 5k−1=4m. What integer coefficient expresses 5k+1−1 as a multiple of 4?
  1. 5m+1
  2. 5m+4
  3. 5m−1
  4. m+1
Show answerHide answer
Answer: A
Rewrite 5k+1−1=5(5k−1)+4=4(5m+1). Since m is an integer, the coefficient is an integer too. Using 5m+4 fails to divide the added 4 by the factored-out 4, so it counts that contribution four times.

Question 5 of 10

What is the least member of {m∈ℤ:m≥−6}?
  1. 0
  2. −5
  3. There is no least member.
  4. −6
Show answerHide answer
Answer: D
The set contains −6 and all larger integers, so −6 is its least element. Well-ordering extends to nonempty integer sets bounded below. Negative members do not prevent a least element; the absence of a lower bound would be the relevant obstacle.

Question 6 of 10

A proof about balanced strings treats the empty string and wrapping “(u),” but stops there. What proof case is still required?
  1. Concatenating any two balanced strings.
  2. Removing an arbitrary parenthesis.
  3. Reversing any balanced string.
  4. Appending any single parenthesis.
Show answerHide answer
Answer: A
The definition also constructs a balanced string by concatenating two balanced strings, so the proof needs hypotheses for both inputs and a conclusion for their join. Appending one arbitrary parenthesis is not a construction rule and can break balance.

Question 7 of 10

A machine has exactly one successor from each state and an execution 2→3→4→⋯. How should its behavior be classified?
  1. Deterministic, with a finite execution.
  2. Deterministic, with an infinite execution.
  3. Nondeterministic, with a finite execution.
  4. Nondeterministic, with an infinite execution.
Show answerHide answer
Answer: B
Exactly one successor gives no choice, so the machine is deterministic. The displayed run continues indefinitely. Having infinitely many states available along an execution does not make the machine nondeterministic; that classification concerns alternative next moves.

Question 8 of 10

Positive integer states (a,b) change by replacing the larger coordinate with its difference from the smaller, stopping at equality. Why does a+b prove termination?
  1. It stays constant while the larger coordinate drops.
  2. It remains natural and never increases on a move.
  3. It remains natural and strictly drops on each move.
  4. It remains positive and may drop by a real amount.
Show answerHide answer
Answer: C
The sum decreases by the smaller coordinate, which is a positive integer, and both coordinates remain positive. Thus every transition strictly reduces a natural-number measure. Merely showing that a natural number never increases would allow a constant value and endless stalling.

Question 9 of 10

For integer n≥0, run this loop:

i := 0
s := 0
while i < n:
    s := s + 2*i + 1
    i := i + 1

What invariant and exit result prove the returned s correct?

  1. s=i2, 0≤i≤n; at exit s=n2.
  2. s=i(i+1), 0≤i≤n; at exit s=n(n+1).
  3. s=(i+1)2, 0≤i≤n; at exit s=(n+1)2.
  4. s=i2, 0≤i<n; at exit s=(n−1)2.
Show answerHide answer
Answer: A
The basis gives s=02, and one pass changes i2 to i2+2i+1=(i+1)2 before incrementing the index. At exit the bounds and false guard give i=n. A strict upper invariant i<n fails on the last update and cannot be used at exit.

Question 10 of 10

A strong-induction proof of P(n) for n≥8 uses P(k−2) to prove P(k+1). What consecutive initial cases make that step available without going below 8?
  1. P(8) only
  2. P(9),P(10),P(11)
  3. P(8),P(9)
  4. P(8),P(9),P(10)
Show answerHide answer
Answer: D
The dependency is available when k−2≥8, or k≥10, so the first general target is 11. Cases 8, 9, and 10 must be established beforehand. Checking just 8 and 9 leaves 10 uncovered before this particular step can begin.
Set 2: Practice 1: Set up and apply the proof10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

An induction claim covers every integer n≥7. What is its required starting case?
  1. P(1)
  2. P(7)
  3. P(8)
  4. P(0)
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

Assume ∑i=1k(3i−1)=k(3k+1)/2. After adding the next term, what expression results in factored form?
  1. k(3k+7)2
  2. (k+1)(3k+1)2
  3. (k+1)(3k+2)2
  4. (k+1)(3k+4)2
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

A proof checks P(2) and proves P(k+1)⇒P(k) for every k≥2. What prevents this from establishing all cases n≥2?
  1. The implication carries truth toward smaller indices.
  2. The base case must always be the case at zero.
  3. An induction step must use two earlier cases.
  4. The implication must be checked at a fixed index.
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

A proof that every integer n≥2 factors into primes reaches the composite case 35=5⋅7. What earlier claims justify this step?
  1. The claims for 1 and 35, the endpoint factors.
  2. The claim for 35, used once for each prime factor.
  3. The claims for 5 and 7, both in the earlier range.
  4. The claim for 34, the immediately preceding integer.
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

Let c0=2 and cn+1=2cn+3 for n≥0. What is c2?
  1. 10
  2. 11
  3. 17
  4. 14
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

A full binary tree is formed by joining a new root to two single-vertex trees. What is its height when a single vertex has height 0?
  1. 0
  2. 1
  3. 2
  4. 3
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

Let S have basis 5 and rule x,y∈S⇒x+y∈S, with no other elements. What property proves that 23∉S?
  1. Every element is divisible by 5, including all constructed sums.
  2. Every element exceeds 5, including the basis element.
  3. Every element is a power of 5, including repeated sums.
  4. Every element is odd, including sums of two odd elements.
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

A machine has states {0,1,2,3}, start 0, and only transitions 0→2 and 2→0. Which states are reachable?
  1. {0}
  2. {2}
  3. {0,1,2,3}
  4. {0,2}
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

An integer pair starts at (0,0) and moves by either (x,y)→(x+2,y+1) or (x,y)→(x−2,y−1). Why is (6,2) unreachable?
  1. x+y stays 0 but is 8 at the target.
  2. x−2y stays 0 but is 2 at the target.
  3. x−y stays 0 but is 4 at the target.
  4. x+2y stays 0 but is 10 at the target.
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

For integer n≥0, a function returns 0 if n=0 and otherwise returns 2n−1+F(n−1). What specification and measure give a total-correctness proof?
  1. Return n2; use the decreasing measure n.
  2. Return n2; use the decreasing measure n mod 2.
  3. Return 2n−1; use the decreasing measure n−1.
  4. Return n(n+1); use the decreasing measure n.
Show answerHide answer

Save this lesson to see this answer.

Set 3: Practice 3: Choose the information the step needs10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

In proving 3n≥2n+1 for n≥0, the hypothesis gives 3k+1≥6k+3. What comparison completes the step?
  1. 6k+3≤2k+3 because 4k≥0.
  2. 6k+3≥2k+5 because 4k≥2.
  3. 6k+3≥2k+1 because 4k+2≥0.
  4. 6k+3≥2k+3 because 4k≥0.
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

Let Sn=∑i=1n1/[i(i+1)]. An induction attempt uses only Sk<1. What stronger claim closes the step and still implies the desired bound?
  1. Sn=1−1n+1
  2. Sn≥1−1n+1
  3. Sn=1−1n
  4. Sn≤1−2n+1
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

For P(n) meaning “an n-tile strip takes n−1 binary splits to separate,” a 17-tile strip first splits into 6 and 11 tiles. What total follows from the earlier cases?
  1. 1+(6−1)+(11−1)=17
  2. 1+(6−1)+(11−1)=16
  3. 1+6+11=18
  4. (6−1)+(11−1)=15
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

A least-counterexample proof concerns integers n≥9. If its least failure is m=12, which cases does minimality guarantee?
  1. P(9),P(10),P(11)
  2. P(9),P(10),P(11),P(12)
  3. P(13),P(14),…
  4. P(0),P(1),…,P(11)
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

With the usual wrapping and joining rules for balanced parentheses, is the string “(())()” balanced?
  1. Yes; every string with six symbols is balanced.
  2. No; only one wrapping operation is allowed.
  3. Yes; it joins a wrapped pair with a pair.
  4. No; joined strings must have equal length.
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

A full binary tree has height 3 and exactly 3 internal vertices. What is its number of leaves, and can the given height occur?
  1. 4 leaves; no, height 3 requires 7 internal vertices.
  2. 3 leaves; yes, with a chain of three internal vertices.
  3. 8 leaves; yes, with all leaves at depth 3.
  4. 4 leaves; yes, with a chain of three internal vertices.
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

A natural-number machine starts at 0 and moves by x→x+4. The goal is to prove x≠6 for every reachable state. What stronger preserved property works?
  1. x is not divisible by 3.
  2. x is divisible by 4.
  3. x is an odd number.
  4. x is at most 4.
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

A natural-number pair (r,b) either moves to (r−1,b+7) when r>0 or to (r,b−1) when b>0. What natural-number measure strictly decreases on every move and proves termination?
  1. r+8b
  2. 7r+b
  3. 8r+b
  4. r+b
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

Euclid’s recursive algorithm receives (a,b)=(154,63) with b>0. What next input supports its correctness proof?
  1. (28,63)
  2. (63,28)
  3. (63,0)
  4. (154,28)
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

For integer n≥0, run this loop:

i := 0
p := 1
while i < n:
    p := 3*p
    i := i + 1

What invariant and strictly decreasing natural-number measure prove the result?

  1. p=3i, 0≤i≤n; measure n−i.
  2. p=3i, 0≤i≤n; measure p.
  3. p=3i+1, 0≤i≤n; measure n−i.
  4. p=3n, 0≤i≤n; measure n−i.
Show answerHide answer

Save this lesson to see this answer.

Set 4: Practice 4: Diagnose and complete arguments10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

A proof establishes P(6) and P(k)⇒P(k+2) for all k≥6. What additional base case makes it cover every integer n≥6?
  1. P(5)
  2. P(7)
  3. P(10)
  4. P(8)
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

What is the smallest integer b ≥ 0 for which 2n>3n+4 holds for all n≥b, and what induction-step comparison proves that range?
  1. b=4; 2k+1>6k+8≥3k+7.
  2. b=5; 2k+1>6k+4≥3k+7.
  3. b=5; 2k+1>6k+8≥3k+7.
  4. b=6; 2k+1>6k+8≥3k+7.
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

An induction argument uses an overlap of k−2 objects to join two conclusions when proving P(k+1). Its base is P(2). At what first required step is a nonempty overlap missing?
  1. The step P(2)⇒P(3).
  2. The step P(3)⇒P(4).
  3. The step P(4)⇒P(5).
  4. The step P(5)⇒P(6).
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

Suppose 3=a/b for positive integers, with the least possible denominator b. You may use 3∣t2⇒3∣t for integers t. What reduction contradicts this choice?
  1. a=3c,b=d; 3=c/d with 0<d<b.
  2. a=c,b=3d; 3=c/d with 0<d<b.
  3. a=3c,b=3d; 3=3c/d with 0<d<b.
  4. a=3c,b=3d; 3=c/d with 0<d<b.
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

Let a0=3 and an+1=2an+5. What formula can be verified by matching both the basis and the recursive step?
  1. an=8⋅2n−5
  2. an=5⋅2n−2
  3. an=3⋅2n+5
  4. an=8⋅2n+5
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

Why does the string “())(” fail the balanced-parenthesis test?
  1. Its full string has more right than left parentheses.
  2. Its prefix “()” has equal left and right counts.
  3. Its prefix “())” has more right than left parentheses.
  4. Its full string begins with a left parenthesis.
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

An expression grammar has numeral atoms and the binary constructions (E+F) and (E⋅F), each adding one parenthesis pair. An expression has 7 operators. How many atoms and parentheses characters does it contain?
  1. 7 atoms and 14 parentheses characters.
  2. 14 atoms and 8 parentheses characters.
  3. 8 atoms and 7 parentheses characters.
  4. 8 atoms and 14 parentheses characters.
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

A machine starts at s. Its only transitions are s→u, s→v, and u→v. Which state is final?
  1. No state is final.
  2. v
  3. u
  4. s
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

A machine starts at (1,0). From (r,b)∈ℕ2 it may move to (r−1,b+k) for any chosen k≥0 when r>0, or decrement b when b>0. What is true of its runs?
  1. Every maximal run ends within one step from this start.
  2. An infinite run exists by choosing a larger finite value of k.
  3. Every maximal run ends, but their finite lengths are unbounded.
  4. Some maximal run stays forever at r=1,b=0.
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

A recursive procedure returns an empty list for lengths 0 or 1. For larger lists it recursively processes both halves and merges them in sorted order. Why does this fail as a sorting algorithm?
  1. Merging sorted lists always loses duplicate elements.
  2. The base case fails to return a sorted list at length zero.
  3. The recursive halves are not smaller for a two-element list.
  4. The base case loses the element of a one-element list.
Show answerHide answer

Save this lesson to see this answer.

Set 5: Practice 5: Transfer the proof methods10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

What identity lets an induction step prove 5∣6n−1 from the corresponding statement at k?
  1. 6k+1−1=6(6k−1)+5
  2. 6k+1−1=5(6k−1)+5
  3. 6k+1−1=6(6k+1)−5
  4. 6k+1−1=6(6k−1)+1
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

Let t0=1,t1=3 and tn+2=2tn+1−tn. To prove that every tn is positive, what stronger claim supplies enough information and is preserved by this rule?
  1. tn≤2n+1 for every n≥0.
  2. tn≥1 for every n≥0.
  3. tn=2n+3 for every n≥0.
  4. tn=2n+1 for every n≥0.
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

Tokens are packed in full packets of 6 or 7. What smallest b and induction setup prove that every integer total n≥b can be packed?
  1. b=29; check 29–34, then add 6 to an earlier total.
  2. b=30; check 30–35, then add 6 to an earlier total.
  3. b=30; check 30–34, then add 6 to an earlier total.
  4. b=36; check 36–41, then add 6 to an earlier total.
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

Let b0=2,b1=5 and bn=bn−1+bn−2 for n≥2. What is b4?
  1. 14
  2. 24
  3. 19
  4. 12
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

A set starts with a symbol a and closes under an ordered binary constructor J(u,v). Define weight by w(a)=2 and w(J(u,v))=w(u)+2w(v). What is w(J(J(a,a),a))?
  1. 12
  2. 14
  3. 8
  4. 10
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

A full binary tree has 10 leaves. What total number of vertices and smallest possible height are compatible with this, using height 0 for a single vertex?
  1. 19 vertices; smallest height 3.
  2. 19 vertices; smallest height 4.
  3. 19 vertices; smallest height 5.
  4. 21 vertices; smallest height 4.
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

Jugs have capacities 4 liters and 10 liters and start empty. Filling, emptying, and complete pours are allowed. What invariant rules out a state containing exactly 3 liters in either jug?
  1. The combined amount is always 14 liters.
  2. The larger jug always holds more water.
  3. Both amounts are even numbers of liters.
  4. Both amounts are multiples of 4 liters.
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

On natural-number states, start at 0 and allow only x→x+3. The predicate x≠5 is true in every reachable state but fails preservation. What transition exposes the failure, and what initialized invariant repairs it?
  1. 2→5; x is divisible by 3.
  2. 0→3; x is divisible by 2.
  3. 5→8; x is divisible by 3.
  4. 2→5; x is divisible by 2.
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

For states n∈ℕ, a machine moves n→n−1 only when n>0. Starting at 11, what upper bound follows directly from the measure v(n)=n?
  1. 11 transitions.
  2. 12 transitions.
  3. 10 transitions.
  4. No finite bound follows.
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

For integer n≥0, run this loop:

i := 0
s := 0
t := 4
while i < n:
    s := s + t
    t := t + 4
    i := i + 1

What invariant and strictly decreasing natural-number measure prove the final result s=2n(n+1)?

  1. s=2i(i−1), t=4(i+1), 0≤i≤n; measure n−i.
  2. s=2i(i+1), t=4(i+1), 0≤i≤n; measure n−i.
  3. s=2i(i+1), t=4i, 0≤i≤n; measure n−i.
  4. s=2i(i+1), t=4(i+1), 0≤i≤n; measure i.
Show answerHide answer

Save this lesson to see this answer.

Stuck on your own question? Homework Help

Key Terms

71 Key Terms, each with its definition

A

Alphabet
An alphabet is a finite set of symbols from which the strings under discussion are formed by finite concatenation.
The binary alphabet {0,1} builds strings such as “010” and includes neither 2 nor other symbols.
Atom
An atom is a variable or numeral used as a basis expression, with no binary operator joining smaller expressions inside it.
The expression ((x+3)⋅y) has the three atoms x,3,y and two binary operators.

B

Base case
A base case directly establishes a starting instance of the claim, allowing the inductive argument to begin.
For a theorem about all integers n≥5, the base case checks the statement at n=5.
Basis objects
Basis objects are the starting elements directly included in a recursive set definition before any construction rule is used.
The empty string is the basis object for strings built by appending one alphabet symbol at a time.
Bounded below
A set is bounded below when some fixed number is no greater than any element of that set.
The integers at least −6 are bounded below and have least element −6, despite containing negatives.

C

Circular reasoning
Circular reasoning uses the desired conclusion as an assumption, so it does not independently establish the claim.
Assuming “P(n) holds for every n” at the start of an induction step assumes the theorem itself.
Closed formula
A closed formula expresses a sequence term directly in terms of its index without requiring earlier terms to be computed.
For a0=1 and an+1=3an+2, induction verifies the closed formula an=2⋅3n−1.
Concatenation
Concatenation joins two strings in order by placing every symbol of the second immediately after the first.
Joining “01” to “10” yields “0110,” whose length is the sum of the two input lengths.
Consecutive base cases
Consecutive base cases establish a block of adjacent initial indices before a step that reaches back several indices can run.
To show stamps cover every amount from 12 cents, a step adding one 4-cent stamp starts after direct checks of 12, 13, 14, and 15 cents.
Construction rule
A construction rule specifies how objects already in a recursive set can be combined or extended to create another member.
The rule taking balanced u,v to uv joins them and requires a proof case using both hypotheses.
Counterexample
A counterexample is an allowed instance in which a universal claim fails, sufficient to refute that claim.
At n=40, the value n2+n+41=412 refutes the claim that this expression is always prime.
Cumulative claim
A cumulative claim asserts all cases from the starting index through the current index as one statement for induction.
Ordinary induction on “P(b),…,P(n) all hold” reproduces the assumptions of strong induction.

D

Dependency
A dependency is an earlier case or value that a recursive calculation or inductive argument needs to obtain its next result.
A step using P(k−3) must start late enough that k−3 lies within the proved range.
Derived variable
A derived variable assigns a value to a state by a formula, whether or not that value is stored explicitly by the process.
For state (a,b), the sum a+b is a derived variable useful in subtractive gcd termination.
Deterministic machine
A deterministic machine has at most one possible successor from every state, so it offers no choice of next state.
The increasing natural-number counter is deterministic even though its execution never ends.
Divisibility
Divisibility means that one integer is an integer multiple of another; d∣t means t=dm for some integer m.
The equality 7k+1−1=6(7m+1) proves divisibility by 6 when m is an integer.

E

Empty string
The empty string contains no symbols, has length 0, and is written λ here; another common notation is ε.
Concatenating the empty string to either end of “101” leaves that three-symbol string unchanged.
Exclusion rule
An exclusion rule restricts a recursive set to objects obtainable from its basis through finitely many allowed constructions.
The basis 3 and addition rule include positive multiples of 3 but exclude unrelated numbers such as 10.
Execution
An execution is a finite or infinite sequence beginning at the start state and following the allowed transition relation.
The counter’s execution 0→1→2→⋯ is infinite despite having a unique next state.
Exit argument
An exit argument combines a loop invariant with the false guard to establish the postcondition when the loop stops.
From i≤n and the false guard i<n, conclude i=n and identify the final factorial.

F

Factorial
The factorial of a natural number is defined by 0!=1 and by multiplying each later factorial by its new positive index.
The recursive step 5!=5⋅4! extends the product through 4 by one new factor.
Fibonacci sequence
The Fibonacci sequence starts with f0=0,f1=1 and defines each later term as the sum of the two preceding terms.
The terms 0,1,1,2,3,5,8 use zero-based indexing, so the entry 8 is f6.
Final state
A final state has no outgoing transitions, so a run that reaches it has no further move available.
A gcd machine that subtracts the smaller coordinate from the larger stops at equal positive coordinates, where no subtraction applies.
Full binary tree
A full binary tree is a rooted tree built from a single vertex or by joining two full binary trees to a new root.
A root with two leaves is full; a root with exactly one child fails the zero-or-two-children rule.

I

Inductive hypothesis
An inductive hypothesis is the claim temporarily assumed for earlier cases while proving an implication to a later case.
In ordinary induction, assume P(k) for an arbitrary allowed k before deriving P(k+1).
Inductive step
An inductive step proves that an earlier established case, or collection of cases, implies the next required case.
Splitting the last term from a sum lets an inductive step use the formula for the shorter sum.
Infinite descent
Infinite descent is an endless sequence of strictly smaller values, which is impossible when all values are natural numbers.
A rational representation of 2 with least positive denominator leads to a smaller denominator.
Initial value
An initial value assigns a starting term directly so that a recursive rule has the information needed to compute later terms.
The Fibonacci rule needs both f0=0 and f1=1 before it can compute f2.
Initialization
Initialization establishes that a candidate invariant is true in the start state before preservation is applied.
A grid robot starting at (0,0), where x+y=0 is even, supplies the base case for the invariant that x+y is even.
Input size measure
An input size measure assigns a natural-number size to an allowed recursive input so that smaller calls can support induction.
Euclid’s proof measures the second argument, which changes from b to the smaller a mod b.
Internal vertex
An internal vertex is a vertex that has children; in a full binary tree every such vertex has exactly two children.
A full binary tree with three internal vertices has four leaves, giving seven vertices in total.
Invariant principle
The invariant principle states that a predicate true initially and preserved by every transition holds at every reachable state.
Once even coordinate sum is proved invariant, a robot target with odd coordinate sum is unreachable.

L

Leaf
A leaf is a vertex with no children; in a single-vertex rooted tree, the root itself is also a leaf.
Joining two full binary trees preserves all their leaves and makes the added root an internal vertex.
Least-counterexample proof
A least-counterexample proof assumes failure, chooses the smallest allowed failure, and derives a contradiction from its minimality.
A least integer with no prime divisor would have a smaller factor that does have a prime divisor.
Lexicographic order
Lexicographic order compares pairs first by their first coordinate and, when those are equal, by their second coordinate.
The pair (2,100) precedes (3,0) even though its second coordinate is much larger.
Loop guard
A loop guard is the condition tested to decide whether another loop pass should run; it is false when the loop exits.
The factorial guard i<n becomes false at exit, supplying i≥n for the output proof.
Loop invariant
A loop invariant is a statement true before the first loop pass and reestablished after every completed pass through the body.
The factorial loop keeps f=i! at pass boundaries as its index and accumulated product advance.

M

Maintenance
Maintenance proves that the invariant and a true loop guard imply the invariant again after executing the loop body in order.
If f=j!, incrementing the index to j+1 and multiplying by it gives (j+1)!.
Mathematical induction
Mathematical induction proves all integer cases from a starting value by a true base and a universally valid forward step.
A base at 1 and implications P(k)⇒P(k+1) for all k≥1 establish every positive case.

N

Necessary property
A necessary property holds for every member of a class, so any candidate lacking that property lies outside the class.
Equal parenthesis totals are necessary for balance, but “)(” shows that they are insufficient.
Nondeterministic machine
A nondeterministic machine allows more than one successor from at least one state, so an execution can involve choices.
A grid robot that moves diagonally is nondeterministic because each grid position permits four different diagonal moves.

P

Partial correctness
Partial correctness guarantees the required postcondition for an allowed run if it terminates, without guaranteeing that it ends.
An invariant may prove the answer is right at exit while leaving the possibility of an infinite run open.
Postcondition
A postcondition specifies the required output or final-state property after an algorithm finishes from an allowed input.
For sorting, the postcondition requires an ordered list containing exactly the original elements.
Precondition
A precondition specifies allowed inputs or initial circumstances under which an algorithm’s correctness guarantee is required.
The recursive factorial algorithm requires an integer n≥0 so decreasing calls can reach zero.
Predicate
A predicate is an expression that becomes a true or false statement when values are assigned to its variables.
The predicate P(n) can say “1+⋯+n=n(n+1)/2,” giving one claim at each positive integer.
Prefix
A prefix is an initial segment of a string, possibly empty or the whole string, obtained by reading from its beginning.
The prefix “())” of “())(” has too many closing parentheses and reveals the balance failure.
Preservation
Preservation shows that a transition cannot break a predicate when that predicate holds before the transition.
A jug invariant must survive filling, emptying, and pouring; checking only fills leaves cases open.
Preserved invariant
A preserved invariant is a predicate carried from any state satisfying it to every allowed successor of that state.
Evenness of x+y is preserved by diagonal moves because each changes the sum by an even amount.
Proof gap
A proof gap is a missing justification needed for an argument to establish its conclusion over the full claimed domain.
The induction argument that any group of balls shares one color has a gap at two balls, where dropping each ball in turn leaves groups with no overlap.

R

Reachable state
A reachable state can be visited from the start by a finite sequence of allowed transitions, including zero transitions.
A path reaching (3,4) in the 3-liter and 5-liter jug model establishes that state’s reachability.
Recurrence relation
A recurrence relation is an equation relating terms of a sequence to other terms, typically at smaller indices.
The relation fn=fn−1+fn−2 expresses each later Fibonacci term using two earlier terms.
Recursive definition
A recursive definition specifies starting values or objects and rules determining further ones from previously defined parts.
The rule an+1=3an+2 computes later terms once the starting value a0=1 is given.

S

Specification
A specification states what an algorithm must accomplish, connecting its allowed inputs to the properties required of its output.
A factorial specification pairs the input condition n∈ℕ with the output requirement n!.
Start state
A start state is the designated state at which executions of a state machine begin, before any transition has occurred.
Two initially empty jugs start at (0,0); that pair is reachable even before the first fill.
State
A state is a snapshot containing the information a model needs to determine possible next actions and evaluate its properties.
For two jugs, the pair (a,b) records the liters currently held in each jug in a fixed order.
State machine
A state machine consists of a set of states, a designated start state, and a relation giving the allowed one-step transitions.
A robot moving diagonally on an integer grid has integer-pair states and four possible diagonal moves from each state.
Strengthened hypothesis
A strengthened hypothesis belongs to a more informative claim proved by induction because it also implies the desired claim.
For a sum Sn of n terms, the bound Sn≤2−1/n records a gap that can absorb each new term while proving Sn<2.
Strict inequality
A strict inequality says one quantity is greater or smaller than another and rules out equality between them.
The strict claim 2n>n2 fails at n=4 because both expressions equal 16 there.
Strictly decreasing measure
A strictly decreasing measure assigns a smaller value to every successor than to its predecessor on each transition.
A natural-number measure starting at 20 permits at most 20 strict decreases before reaching zero.
String
A string is a finite ordered sequence of symbols from an alphabet, including the sequence with no symbols.
The strings “01” and “10” use the same symbols but differ because their order matters.
Strong induction
Strong induction proves the next integer case using the assumption that every earlier case from the starting value holds.
When k+1=ab is composite, the strong hypothesis supplies prime factorizations for both factors.
Structural induction
Structural induction proves a property for basis objects and shows that each construction rule preserves it from the input parts.
A balanced-string proof has separate cases for the empty string, wrapping, and joining two strings.
Summation notation
Summation notation uses a sigma symbol and index bounds to specify the addition of a sequence of terms.
The expression ∑i=14i2 means 12+22+32+42, with each index included once.

T

Termination
Termination means that the process ends after finitely many steps; for a machine with choices, the guarantee concerns every run.
Positive integer subtraction ends because the sum strictly decreases and remains a natural number.
Total correctness
Total correctness guarantees both that every allowed run terminates and that its final result satisfies the postcondition.
A prefix-sum invariant and the decreasing measure n−i together prove the summation loop totally correct.
Transition
A transition is one allowed move from a current state to a successor state according to the machine’s rules.
Pouring from (0,5) into an empty 3-liter jug gives the transition to (3,2).
Tree height
The height of a rooted tree is the number of edges on its longest root-to-leaf path, giving a single vertex height 0.
A root above subtrees of heights 1 and 2 has height 1+max⁡(1,2)=3, not the sum of both paths.
Tree mirror
A tree mirror recursively swaps the left and right subtrees at every internal vertex while leaving a single vertex unchanged.
Mirroring twice restores both the order of the children and, by induction, the structure of each subtree.

W

Weakly decreasing measure
A weakly decreasing measure never increases on a transition but may stay equal, allowing repeated steps without progress.
On a self-loop q→q, every measure of that unchanged state remains equal to itself.
Well-defined function
A well-defined function assigns exactly one value to every input in its domain, with no missing or conflicting outcomes.
A two-step rule without a starting value for the odd indices leaves some inputs without values.
Well-ordering principle
The well-ordering principle states that every nonempty set of nonnegative integers has an element no larger than any other.
A nonempty set of failed natural-number cases therefore has a least failure to examine.

About this lesson

By StudeliReport a mistake

Make your own Study Materials

Turn your notes, slides and documents into Study Guides, Practice Questions, Flashcards and 6 more tools.

Get Started