Discrete Mathematics
Discrete Mathematics
"LINEAR SEARCH"
Algorithm
Step 1: Start
Step 2: Declare a,b,c as your set of array
Step 3: Declare your target variable
Step 4: i is index, set i=0
Step 5: FOR i<number of items in the list
Step 6: IF i is equal to target element, then return 1
Step 7: ENDIF
Step 8: ENDFOR
Step 9: return -1
Pseudocode
Start
Array (a,b,c)
target= (enter your target element)
FOR i<number of items in the list
IF i == target element THEN
return 1
ENDIF
ENDFOR
return -1
Recursion:
if <number of items in the list is = target element, otherwise (i+1)
A = { 3, 8, 12, 16}
target element = 16
if array = 16
(i+1)
Induction
1. Assume that our target value is in the index k. so it holds true.
2. If our target value is on the index k, then our algorithm will return to 1. Indicates that our
target variable is in the array.
3. If not, it will return to -1. Indicates that our target variable are not in our index k.
“FIBONACCI SERIES”
Algorithm
Step 1: Start
Step 2: Set up the initial two terms
Let the first term, a = 0
Let the second term, b = 1
Step 3: Print the first term a
Step 4: Print the second term b
Step 5: Since the first two terms have already been printed, set a counter n = 2
Step 6: Loop Repeat this steps until your n reaches 13.
1. Calculate: c = a+b
2. Print the next term (c)
3. Update a = b and b = c
4. Increment the counter n by 1
Step 7: ENDWHILE
Pseudocode
Start
Initialize variables:
a=0
b=1
Print a,b
n=2
WHILE n<13 Do
c=a+b
Print c
a=b
b=c
n= n+1
ENDWHILE
Recursion:
n<10, c=a+b
a=b
b=c
n=n+1
Induction:
Base case: n < 2
“PALINDROME”
Algorithm
Step 1: Start
Step 2: Read the variable value for k, b, and g
Step 3: Print the variable for k,b and g
Step 4: Reverse the variable of k and g
Step 5: If it still the same, print same variable
Step 6: Else, print not the same variable
Pseudocode
Start
For k=3
b=5
g=3
Reverse [k] and [g]
If [k,b,g] == [g,b,k]
Then print [g,b,k]
End if
End
Recursion:
If the value of [k,b, and g] == to the value of [g,b,and k] it will print the same set of variable
value g,b,k.
Induction:
Base Case: k=0 b=0 g=0
Formula: k = g
g=k
Example: Swap the values of k and g
k=g=3
g=k=3
With this mathematical induction,we've shown that the recursive function correctly prints
[g,b,k] or it' true.
Algorithm
Step 1: Start
Step 2: Read n
Step 3: Set factorial to 1 (initial value)
Step 4: While n > 1 do
1. multiply factorial by n
2.Decrement n by 1
Step 5: End while
Step 6: Print factorial
Step 7: End
Pseudocode
Start
READ n, fact
fact = 1
WHILE n > 1
fact = fact * n
n=n-1
ENDWHILE
PRINT factorial
END
Recursion
For n>0, n! = n*(n-1)!
Calculate 6!
Factorial = 1
n=6
6* factorial (5)
6*(5*factorial (4))
6*(5*(4*factorial (3))
6*(5*(4*(3*(2*1))
= 720
Induction:
Base case : F (0)=1
Inductive hypothesis: Assume F (k)=k! is true for some specific k
Inductive step: Prove that if F (k) = k! is true, then F(k+1)=(k+1)! is also true.
Formula: F(k+1)=(k+1)*F(k)
Ex:
We know F(6)=6!=720 is true
We can prove F(7)=7! is true
F(6+1)=F(6+1)*F(6)
= F(7)*F(6)// from the inductive hypothesis, we assume F(k)=k!
is true so we know F(6)=6!
=720 is true
=7*120
= 5,040
= 7!
Conclusion: if it works for any number k, it also works for k+1.
Algorithm
Step 1: Start
Step 2: Declare a and b
Step 3: Input a and b
Step 4: FOR a and b
Step 5: a is equal to sum of a+b
Step 6: b is equal to sum of the new value of a-b
Step 7: a is equal to sum of the new value of a and b
Step 8: PRINT a and b
Step 9: ENDFOR
Step 10: END,
Pseudocode
Start
Input a and b
FOR a= a+b
b= a-b
a= a-b
PRINT a, b
ENDFOR
END
Recursion:
a = 10
b = 20
a= 10+20 = 30
b= 30 - 20 = 10
a= 30-20 = 20
Induction:
Base Case: a and b
Inductive Hypothesis: assume that the formula work for any pair of integers a and b. And can also
works to the next pairs of integer a and b.
Inductive Step:
Prove that a= a+k, b= a+k can be swapped using this formula:
[a=a+b=(a+k)+(b+k)=k]
[b=a-b=(a+k)-(b+k)=k]
[a=a-b=(a+k)-(b+k)=k]
Solution:
a=a+b=10+20=30
b=a-b=30-20=10
a=a-b=30-10=20
Conclusion: we can prove that using the given formula, can now swapped a and b.
BSIT 1-2
MEMBERS:
CLAIRE VILLAMOR
KRIS MARIE BADA
ALYSSA MAY DAGOHOY