American University of Science & Technology Faculty of Arts and Sciences
American University of Science & Technology Faculty of Arts and Sciences
Title: Mathematical induction /Java program to find Union and intersection of two sets.
Section: A
Outline
1. History
2. Type of proofs
3. Mathematical induction
6. Reference
7. JAVA Program.
History
Type of proofs
1) Direct proof: Many theorems are implication of the form p→q if p then q.
Assume p is true and you show q is true T→T true.
2) Indirect Proof:
p→q ⇔ ¬q → ¬p
We prove ¬q → ¬p true using the direct proof then p→q will be true.
3) Mathematical Induction:
Induction step: Assume p(n) true, we prove p(n+1) true then p(n) is true for
all x ⇒ p(n)→ p(n+1).
The simplest and most common form of mathematical induction infers that a
statement involving a natural number n holds for all values of n. The proof consists
of two steps:
1. The base case: prove that the statement holds for the first natural number n0.
Usually, n0 = 0 or n0 = 1; rarely, but sometimes conveniently, the base value
of n0 may be taken as a larger number, or even as a negative number (the
statement only holds at and above that threshold), because these extensions
do not disturb the property of being a well-ordered set.
2. The step case or inductive step: prove that for every n ≥ n0, if the statement
holds for n, then it holds for n + 1. In other words, assume the statement
holds for some arbitrary natural number n ≥ n0, and prove that then the
statement holds for n + 1.
The hypothesis in the inductive step, that the statement holds for some n, is called
the induction hypothesis or inductive hypothesis. To prove the inductive step,
one assumes the induction hypothesis and then uses this assumption, involving n,
to prove the statement for n + 1.
Whether n = 0 or n = 1 is taken as the standard base case depends on the preferred
definition of the natural numbers. In the fields of combinatorics and mathematical
logic it is common to consider 0 as a natural number.
The method of mathematical induction for proving results is very important in the
study of Stochastic Processes. This is because a stochastic process builds up one
step at a time, and mathematical induction works on the same principle.
Usage of mathematical induction in real life
1)I'll start with the standard example of falling dominoes. In a line of closely
arranged dominoes, if the first domino falls, then all the dominoes will fall
because if any one domino falls, it means that the next domino will fall, too.
2) I will leave this question unanswered. There are lots of solutions on the web for
this, if you don't get it.
Consider a long circular road that has several fuel depots along the way. All in all,
the depots contain just the right amount of fuel to get your car around. You start
with an empty tank. Show that you can always find a depot at which to start so
that it's possible to get all the way round. (You can make the road one-way if you
like.)
3) Another example is the solution to the tower of Hanoi and other similar
problems (see sources). Although there are several other proofs, induction is the
most common and elegant of them all.
4) You are in line at Taco Bell. The first person in line orders a cheesy crunch.
Also, if the person in front of you orders a cheesy crunch, you order it too,
because it sounds so good. How many people in line order cheesy crunches? ;)
5) A truly real-life example is the sinking of the Titanic: The crew of the Titanic
realized that the ship was doomed when they realized that the bulkhead that was
being flooded would be completely flooded, and that when a given bulkhead was
completely flooded, the next bulkhead would undergo the same fate, thus sinking
the whole ship.
https://cpb-us-e1.wpmucdn.com/sites.northwestern.edu/dist/4/1328/files/2017/05/mathinduct3a-
1ph0lrp.pdf
https://www.stat.auckland.ac.nz/~fewster/325/notes/ch5annotated.pdf
JAVA Program:
Code:
import javax.swing.JOptionPane;
import java.io.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class Discrete
{
// Function to find intersection
static void intersection(int a[], int b[])
{
System.out.println("Intersection of the two sets is :");
for(int i = 0; i<a.length; i++ )
{
for(int j = 0; j<b.length; j++)
{
if(a[i]==b[j])
{
System.out.println(b[j]);
}
}
int menu;
do
{
menu=Integer.parseInt(JOptionPane.showInputDialog("Please Type:\n 1-
Intersection\n2-Union\n3-Exit"));
switch(menu)
{
case 1:{
intersection(a,b);
break;
}
case 2:{
union(a,b);
break;
}
case 3:{
System.out.println("EXIT");
break;
}
default:{
System.out.println("INVALID INPUT");
}
}while(menu!=3);
}
}
OutPut:
First the program will ask
to enter the size of set A
and set B(How many
elements are in set A and
B).
Second the Program will ask to
add The elements of Set A and
set B
After the two first steps, the
program will show a menu bar
which we can choose from an
option.
We enter 1 for the intersection
of the two sets.
We enter 2 for the union of the
two sets.
And 3 to exit the program.
(the Menu will reappear every
time we choose an option until
we choose 3(exit)).