I'm trying to isolate the key differences between induction and recursion so that I am able to know when to use one over the other.
From my understanding, both can be used to prove properties about recursive structures.
For example:
Consider a recursive structure $x \in X$. In order to prove that for all $x$, $P(x)$ is $true$ one could do this inductively by showing that its $true$ for a base case, then for an inductive case that says if its $true$ for the constituents of a non-base $x$, its $true$ for $x$.
This can also be proved by defining the property $P(x)$ as a function $P:X \xrightarrow{} Bool$ which evaluates to $true$ for every $x$.
Which approach is better in general? I'm leaning towards defining recursive functions as it seems more natural for me as a programmer but maybe its just better here for this specific case, how would one decide what to do in general?
For example lets consider a simple P(x) below. It should be clear to see P(x) is true for all x, given x is an instance of a simple binary tree node.
boolean P(BinaryTreeNode x){ if (x instanceof Leaf){ return true; } else { return P(x.getLeft()) || P(x.getRight()); } }
p || qisfalseif bothpandqarefalse. How do you prove that that ultimately never results in areturn false? By induction. $\endgroup$