01B - Inductive Reasoning, Study notes of Computer science

01B - Inductive Reasoning - Great T

Typology: Study notes

2025/2026

Uploaded on 05/02/2026

qwartz-brinz
qwartz-brinz 🇶🇦

20 documents

1 / 18

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Inductive Reasoning
Slides by
Victor Adamchik
WHAT IS INDUCTIVE
REASONING?
example 1: candy!
4
In order to share some candy,
ܰ
students are assigned numbers
from ͳ
to
ܰ
.
Then, the following rules are applied:
1.
Student ͳgets candy.
2.
For all ݅: if student ݅gets candy,
then student ݅൅ͳalso gets candy.
Question.
Will student
ܰ
get candy?
Answer.
Of course!
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download 01B - Inductive Reasoning and more Study notes Computer science in PDF only on Docsity!

Inductive Reasoning

Slides byVictor Adamchik

WHAT IS INDUCTIVE REASONING

?

example 1: candy!

4

In order to share some candy,ܰ

students are assigned numbers from

ͳ

to

Then, the following rules are applied:1.

Student

ͳ

gets candy.

  1. For all

݅ : if student

݅ gets candy,

then student

݅ ൅ ͳ

also gets candy.

Question.

Will student

get candy?

Answer.

Of course!

example 2: dominos

6

A number of

dominos stand in a row:

They are close enough to each other, so:2. For all

݅ : if the

th݅

domino in the row

falls, then the

݅ ൅ ͳ

st

domino also falls.

Then, we push the

th

domino, so:

The

th

domino falls.

Question.

Does the

th

domino fall?

Answer.

Of course!

Question.

Does the 3

rd

domino fall?

Answer.

Of course not.

7

A number of

dominos stand in a row:

They are close enough to each other, so:2. For all

݅ : if the

th݅

domino in the row

falls, then the

݅ ൅ ͳ

st

domino also falls.

Then, we push the

th

domino, so:

The

th

domino falls.

Question.

What if

ܰ ൌ λ

Which of the infinitely many dominos will fall? Answer.

All dominos from the

th

one onwards.

[^ Why:

Pick any of them, say

th

, for some

Look at first

dominos. Then (as before) the

th

domino falls. So, they all do.]

You see the pattern?

Let P(n) be a statement about n.

(e.g., P(n):=“the n

th^

student gets candy”)

The value of it: Instead of attacking aproblem directly, we just explain:1.

why P(0) is true; and

  1. how to get a proof for P(k+1) out of P(k).

Then the following holds: Parts of an Inductive Proof

Inductive step: Fix an arbitrary k

Assume that P(k) holds.

Use that to prove that P(k+1) holds too.

Base step(s): Show that P(0) holds.

Conclusion:

Therefore, P(n) holds for all n.

There is nothing sacred about the base case

n=0, we could just as well start at n = 11. We have chosen to describe the induction step

as moving from k to k+1, where k

There is the obvious alternative to change the

induction step from k-1 to k, where k

Parts of an Inductive Proof

Example

Prove that 2

n^ < n! for all n

Base step:

For n=4: We have 2

Inductive step: Fix arbitrary k

Assume 2

k^

< k!.

We will prove that 2

k+

< (k+1)!.

We have:

k+

k^ < 2·k! < (k+1)·k! = (k+1)!. Conclusion:

Therefore, 2n < n! for all n

A Template for Inductive Proofs

State that the proof is by induction. If there are

several variables, indicate which serves as n.

Clearly state your inductive hypothesis P(n).

Prove base case(s).

Fix arbitrary k. Assume P(k). Prove P(k+1).

State that the induction principle allows you to

conclude that P(n) is true for all n

Example

Induction is helpful for proving the

correctness of a statement, butnot helpful for discovering it.

Recall our recurrence

from last lecture for bounding P

:n

Prove T(n) = 2·n-.

T(n) = 2 + T(n-1)T(2) = 1

Example

Base case: n =2, T(2) = 2·2-3 = 1 Inductive step: Assume T(k) = 2·k-

Prove it for k+

T(k+1) = 2 + T(k) = 2 + 2·k-3 = 2·(k+1)-

T(n) = 2 + T(n-1)T(2) = 1Prove T(n) = 2·n-

pitfalls

Soundness of InductionHow do we know that INDUCTION

really works?

Soundness of Induction

Proof by contradiction

Assume that for statement P(n), wecan establish the base step P(0), andthe induction step, but nonetheless itis not true that P(n) holds for all n.

So, for some values of n,

P(n) is false.

Soundness of Induction

Certainly, n

0

cannot be 0.

Thus, it must be n

0

= n

+1, where 1

n

< n 1

Let n

0

be the least such n that P(n

) is false. 0

Now, by our choice of n

, this means that P(n^0

holds.

because of IH, since n

< n 1

0

Soundness of Induction

But then by Induction Step, P(n

+1) also holds. 1

Which is the same as P(n

), and we have a 0

contradiction.

Review that proof We used the fact that we can pick n

0

to be the least n where P(n) fails.

Namely, we used the

LEAST ELEMENT PRINCIPLE:^ Every non-empty subset of thenatural numbers must contain a

least element.So, we proved that

LEP

WI

Similarly, we can also prove that

WI

LEP. So: LEP

WI.

STRONG INDUCTION

Base case: 2 is primeInductive step:Fix any n

Assume all k

n can be factored into primes.

We must prove that n+1 can be factored too. Case 1: n+1 is primeCase 2: n+1 is composite, n+1 = p q

p, q > 1

(easy to finish from here…)

Theorem. Every natural number > 1

can be factored into primes

Strong Induction

How to justify the proof by strong

induction?

The proof is by contradiction.

Note that again we used theLEAST ELEMENT PRINCIPLE: Every non-empty subset of thenatural numbers must contain a

least element.So, we proved that

LEP

SI

Similarly, we can also prove that

SI

LEP. So: LEP

SI.

Strong Induction vs Weak InductionIt follows that there two forms are equivalent.The conversion from weak to strong form is trivialFrom strong in P to weak:Let Q(n) :

P(0) and P(1) and ... and P(n)

Base Step: Q(0) = P(0)Inductive Step: Q(n)

Î

P(n+1)

Q(n)

Î

Q(n) and P(n+1)

Q(n)

Î

Q(n+1)

Therefore, the strong induction in P can bewritten as a weak induction in Q.

example: ATM

ATM Machine

Suppose an ATM machine hasonly seven dollar and tendollar bills. You can type inthe amount you want, and itwill figure out how to dividethings up into the propernumber of 7's and 10's.Claim: The ATM can generateany output amount n

≥^

ATM Machine: Proof

Base case: 54 = 2·7 + 4·10Induction step: assume k = 7·a + 10·b,for all k = 54, …, nHow do we proceed for k=n+1 dollars?

ATM Machine: Proof n + 1 = n

n

By IH:

n

6 = 7·a + 10·b

Hmm…,Therefore, we have to extend the base cases to55, 56, 57, 58 and 59

n

6 could be less than 54...

Chocolate Bar

Claim. It requires nk-1 snaps

Note, there are two variables n and k.We prove it by strong induction on thenumber of squares s = n k.If s = 1, no breaks are required andn k-1 = s -1 = 1-1 = 0

Chocolate Bar

Claim. It requires s-1 snaps

IH: assume that this is true

s < n

Consider a chocolate bar with s = n totalpieces.After the first snap, there will be two smallerbars with k

and n-k 1

pieces. 1

Chocolate Bar

Claim. It requires s-1 snaps

After the first snap, there will be two smallerbars with k

and n-k 1

pieces. 1

By IH, it requires k

-1 and n-k 1

-1 breaks. 1

Totally, (k

-1)+(n-k 1

-1)+1= n-1 1

INVARIANTS

In Programming.

A rule that

applies throughout the life of adata structure or procedure orloop. Each change to the datastructure or loop maintains the

Yet another packaging ofinductive reasoning is tocorrectness of the invariant

define “invariants”

15-122 again …

Loop invariants int fast_exp (int x, int y)//@requires y > 0;//@ensures result == pow(x,y);{

int r = 1; int b = x; int e = y;while (e > 1)//@loop_invariant r * pow(b,e) == pow(x,y);{

if (e % 2 == 1) r = b * r;b = b * b; e = e / 2; } return r * b; }

15-122 again …

Data structure invariants:

BST, Heaps, AVL Trees

h-

h-

BIG PICTURE

Fractals

Fractals are geometric objects that

are self-similar, i.e. composed ofinfinitely many pieces, all of which

look the same.

The Koch Curve

Alphabet: { F, +, - }Rules:

Rule(-) = -

Rule(w

…w 1

) = Rule(wn

) … Rule(w 1

)n

Rule (F):

F+F--F+F

Rule(Rule (F)):F+F--F+F+F+F--F+F--F+F--F+F+F+F--F+F

Rule(F) = F+F--F+FRule(+) = +

F+F--F+F

Visual representation: F^

draw forward one unit

+^

turn 60 degree left

-^

turn 60 degrees right The Koch Curve Visual representation: F^

draw forward one unit

+^

turn 60 degree left

-^

turn 60 degrees right The Koch Curve

F+F--F+F+F+F--F+F--F+F--F+F+F+F--F+F

The Koch Curve a non-differentiable curveStructural Induction

Useful for proving properties ofinductively-defined sets.

Same steps as weak/strong induction.•^

Prove the property holds on each of the basecases of the definition.

-^

Prove the property holds on the result of anyinductive rule, assuming that it holds on eachof the parts on which the rule applies.

example

Base case:

3 is in S

Consider a set S defined byInductive rule:if x in S and y in S , then x+y in S

What does S contain?