Recursively Defined Functions
- We use two steps to define a function with the set of nonnegative integers as its domain:
INFO
BASIS STEP: Specify the value of the function at zero.
RECURSIVE STEP: Give a rule for finding its value at an integer from its values at smaller integers.
- Note that,
INFO
Recursive function on integers = sequence defined by recurrence
- Example,
is defined recursively by BASIS STEPRECURSIVE STEP
Recursively Defined Sets and Structures
- Recursive definitions play an important role in the study of strings
- Example, consider the subset
of the set of integers recursively defined by BASIS STEPRECURSIVE STEPIfand , then
Recursive Definition of Strings
INFO
Let
BASIS STEP:
RECURSIVE STEP:
Recursive Definition of Concatenation
Let
The concatenation of two strings is denoted by
INFO
BASIS STEP:
where
RECURSIVE STEP:
Intuition
- Nối chuỗi với chuỗi rỗng
không làm thay đổi chuỗi - Để nối
với : - trước tiên nối
với - sau đó thêm ký tự
vào cuối
- trước tiên nối
Recursive Definition of Rooted Trees
- A rooted tree is defined recursively as follows:
INFO
BASIS STEP:
RECURSIVE STEP: Suppose that
Form a new graph by:
- introducing a new vertex
(not in any ), and - adding edges from
to each for
Then this graph is also a rooted tree.
Exclusion Rule
No graph is a rooted tree unless it can be formed using the basis step and recursive step.
Recursive Definition of Extended binary trees
INFO
BASIS STEP:
RECURSIVE STEP:
Recursive Definition of Full Binary Trees
INFO
BASIS STEP:
RECURSIVE STEP:
Recursive Algorithms
Definition
An algorithm is called recursive if it solves a problem by reducing it to an instance of the same problem with smaller input
- Some examples of recursive algorithms:
FibonaccinumbersPowerFactorialsBinary search
- Proving recursive algorithms correctly requires a
strong inductionapproach.
Structural Induction
- Structural induction can be used to prove that all members of a set constructed recursively have a particular property.
Proof template on Strings (Σ*)
INFO
BASIS STEP: Show that
RECURSIVE STEP: Assume
- Build string by adding characters at the end
- If property holds for
→ must hold for
Proof template on Full Binary Trees
TIP
BASIS STEP: Show that
RECURSIVE STEP: Assume
- Tree is built by combining smaller trees
- If property holds for subtrees → must hold for the combined tree
Example on Well-Formed Formulae
Goal
Prove that every well-formed formula (WFF) has an equal number of left and right parentheses.
Basis Step
- T, F, and propositional variables (s) contain no parentheses
- ⇒ number of left = number of right = 0 ✔️
Recursive Step
Induction hypothesis:
- p and q are WFF
- p has equal left/right parentheses
- q has equal left/right parentheses
Check new constructions:
- (¬p)
- left: lp + 1
- right: rp + 1
- ⇒ still equal ✔️
- (p ∨ q), (p ∧ q), (p → q), (p ↔ q)
- left: lp + lq + 1
- right: rp + rq + 1
- since lp = rp and lq = rq
- ⇒ still equal ✔️
Conclusion
- Property holds for basis
- Preserved under recursive construction
⇒ True for all WFF (by structural induction)
Comparison of Induction Methods
| Type | Core Idea | When to Use | Basis | Induction Step | "Build" Pattern |
|---|---|---|---|---|---|
| Mathematical Induction | Progress step-by-step over integers | Problems on ℕ (numbers) | Prove P(0) or P(1) | Assume P(n) → prove P(n+1) | n → n+1 |
| Strong Induction | Use all previous cases | When current case depends on multiple earlier ones | Prove initial cases (P(0), P(1), ...) | Assume P(0)...P(n) → prove P(n+1) | depends on entire history |
| Structural Induction | Follow how objects are constructed | Recursively defined structures (strings, trees, sets) | Prove for simplest object | Assume true for components → prove for constructed object | build from smaller parts |