This presentation is the full application of discrete mathematics throughout a course and includes Set Theory, Functions nd Sequences, Automata Theory, Grammars and algorithm building.
2. Set Theory Revisited
• Look up a roulette wheel diagram. The following sets are definedA = the set of red numbers D = the set of even numbers
B = the set of black numbers E = the set of odd numbers
C = the set of green numbers F = {1,2,3,4,5,6,7,8,9,10,11,12}
For the purposes of this presentation, we will be using the American
Roulette Wheel as we are in America.
3. • The table of numbers to the right are for the American Roulette.
We will take from here to develop our sets.
• Red #’s “A” = {1, 3, 5, 7, 9, 12, 14, 16, 18, 21, 23, 25, 27, 28, 30, 32,
34, 36}
• Black #’s “B” = {2, 4, 6, 8, 10, 11, 13, 15, 17, 19, 20, 22, 24, 26, 29,
31, 33, 35}
• Green #’s “C” = {0, 00}
• Even #’s “D” = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
32, 34, 36}
• Odd #’s “E” = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 39, 31,
33, 35}
• Set “F” = {1,2,3,4,5,6,7,8,9,10,11,12}
Now that we a have assessed the determinant sets, we will
start assessing each of the below “U” – Unions and “∩” –
Intersections for each required configuration.
They are as follows :
• (A∪B) (A∩D) (B∩C) (C∪E) (B∩F) (E∩F)
7. Part II: Relations, Functions, and Sequences
The implementation of the program that runs the game involves testing. One of the necessary
tests is to see if the simulated spins are random. Create an n-ary relation, in table form, that
depicts possible results of 10 trials of the game. Include the following results of the game:
Number
Color
Odd or even (note: 0 and 00 are considered neither even nor odd.)
Trial # (P/K] Number Color Odd or Even
1 6 Black Even
2 33 Black Odd
3 12 Red Even
4 16 Black Even
5 10 Red Even
6 25 Red Odd
7 4 Black Even
8 36 Red Even
9 11 Black Odd
10 27 Red Odd
11 32 Red Even
8. Part 4: Automata Theory, Grammars and Languages
INSTRUCTIONS
• A gate with three rotating arms at waist height is used to control access to a
subway in New York city. Initially, the arms of the gate are locked preventing
customers from passing through. Unlocking the arms requires depositing a token
in a slot, which allows the arms to rotate to a complete turn which allows one
customer to push through and enter. Once the customer passes through the arms
are then locked again until another customer deposits another token in the slot.
• The gate has two states: LOCKED and UNLOCKED. It also has two inputs: TOKEN
and PUSH. When the gate is locked, pushing the arm of the gate has no effect
regardless of how many times it is pushed. The input TOKEN changes the state
from LOCKED to UNLOCKED. When the gate is in the UNLOCKED state, inserting
additional tokens has no effect on the state. But when in the UNLOCKED state, a
PUSH input changes the state to LOCKED.
• (i). Provide a transition table showing each state, the inputs, and the resulting
new states for each input
• (ii). Represent your transition table into a digraph (transition diagram)
9. Part - 4: Automata Theory,
Grammars and Languages
START
STATE
INPUT NEXT STATE OUTPUT
LOCKED
TOKEN INSERTED UNLOCK Turn Stile OPEN
PUSH BAR LOCKED Turn Stile LOCKED
UNLOCK
TOKEN INSERTED UNLOCK Turn Stile LOCKED
PUSH LOCKED After Turn Stile
Pushed / Locked
• Provided is a transition table showing each state, the inputs, and the resulting
new states and output for each input
• Below is a representation of a transition table into a digraph (transition diagram)
LOCKED UN
LOCKEDPush Coin
Push
Coin
10. Part - 4: Automata Theory,
Grammars and Languages
• Here is a context-free grammar that can be used to generate algebraic
expressions via the arithmetic operators (addition, subtraction, multiplication,
and division), in the variables p, q, and r. The letter E stands for expression:
• Rule 1: E —› p
• Rule 2: E —› q
• Rule 3: E —› r
• Rule 4: E —› E + E
• Rule 5: E —› E – E
• Rule 6: E —› E X E
• Rule 7: E —› E/E
• Rule 8: E —›(E)
Use the above grammar to derive the string given by the mathematical expression E
= (p + q) X p – r X p/(q + q)
11. Grammars and Languages - Continued
E = (p + q) X p – r X p/(q + q)
E ( the start symbol)
E – E ( by rule 5, applied to the middle)
E – E * E (by rule 6, applied to the rightmost E)
(E) * E – E * E (by rule 6, applied to the leftmost E)
(E) * E – E * E/(E) (By Rule 8, applied to the rightmost E)
(E + E) * E – E * E/(E) (By Rule 4 of the leftmost E)
(E + E) * E – E * E/(E + E) (By Rule 4 applied to the rightmost E)
(p + E) * E – E * E/(E + E) ( by rule 1 , by the leftmost E )
(p + q) * E – E * E/(E + E) ( by rule 2 , by the leftmost E )
(p + q) * p – E * E/(E + E) ( by rule 1 , by the leftmost E )
(p + q) * p – E * E/(E + q) ( by rule 2 , by the rightmost E )
(p + q) * p – E * E/(q + q) ( by rule 2 , by the rightmost E )
(p + q) * p – E * p/(q + q) ( by rule 1 , by the rightmost E )
(p + q) * p – r * p/(q + q) ( by rule 3 , by the rightmost E )
12. Part - 4: Continued
Automata Theory, Grammars and Languages
E
/ |
E - E
/ | / |
E * E E * E
/| | | /|
( E ) p r E / E
/| | /|
E + E p ( E )
| | /|
p q E + E
| |
q q
(E + E) * E – E * E/(E + E)
to
(p + q) * p – r * p/(q + q)
To the right is my attempt
to accomplish the sparse
tree configuration. As is
seen, the initial inner
variables break down
pretty easily, but the
outer configurations take
a little more break down
to accomplish the sparse
tree.
13. Part -V Algorithm (Sequential) Search
This algorithm finds an object “x” (number, string) from a
given set A where |A| = n.
Input: x, A, n
Output: index // location of x in set A
(array A)
seq_search(x, A, n)
{ i = 1
while (i <= n and x ~= A(i)) i = i + 1
if (i <= n) then index = i
else index = 0
return index
}
14. Algorithmic Sequential (Linear)
Search
Input: x = 19, A = {22, 21, 9, 4, 16, 2, 10, 14, 20, 31, 26, 19, 17, 28, 8, 13}, n = 16
It took 13 steps (same as n). It could have been as much as 16 and as little as 2. The
worst case seems to be n + 1 steps to find x.
Step 1: test: 1 < 16 and 19 ~= 22 true i = 2 Step 9: test:9 < 16 and 19 ~= 20 true I =10
Step 2: test: 2 < 16 and 19 ~= 21 true i = 3 Step 10: test: 10 < 16 and 19 ~= 31 true i = 11
Step 3: test: 3 < 16 and 19 ~= 9 true i = 4 Step 11: test: 11 < 16 and 19 ~= 26 true i = 12
Step 4: test: 4 < 16 and 19 ~= 4 true i = 5 Step 12: test: 12 < 16 and 19 ~= 19 false i = 13
Step 5: test: 5 < 16 and 19 ~= 16 true i = 6 Step 13: test: 12 < 16 true index = 19
Step 6: test: 6 < 16 and 19 ~= 2 true i = 7
Step 7: test: 7 < 16 and 19 ~= 10 true i = 8
Step 8: test: 8 < 16 and 19 ~= 14 true i = 9
15. This algorithm performs a binary search to find “x” in a
set – (A). The algorithm determines the location of “x”.
Using the same set in the sequential search we will run
the binary algorithm.
Input: x, A, n
Output: index // location of x in A
Binary search (x, A, n)
{ i = 1, j = n
while ( i < j)
m =int[(i + j)/2]
if (x > A(m)) then i = m + 1
else j = m
if x = A(i) then index = i
else index = 0
}
16. Search for 19 in the set A = {2,4,8, 9, 10, 13, 14, 16, 17, 19, 20, 21, 22, 26, 28, 31}
Sorted list = {2, 4, 8, 9, 10, 13, 14, 16, 17, 19, 20, 21, 22, 26, 28, 31}, n = 16
2 4 8 9 10 13 14 16 17 19 20 21 22 26 28 31
Int[(15 + 1)/2] = 8th cell ↑ 16 < 19 1st set
2 4 8 9 10 13 14 16 17 19 20 21 22 26 28 31
Int[( 7 + 1)/2] = 4th cell ↑ 21 > 19 2nd set
2 4 8 9 10 13 14 16 17 19 20 21 22 26 28 31
Int[(3 + 1)/2] = 2nd cell ↑ 19 = 19 index found
It took 3 steps for index found (same as n). It could have been as much as 4 and as
little as 3. The worst case seems to be int(n+1/2) steps to find x. Therefore, a
binary search is quicker in loop search then a sequential search.
17. INSTRUCTIONS
• Suppose an algorithm that processes a data set of size 8 has a runtime of 72.
The same algorithm has a runtime of 110 when applied to a data set of size 10;
and when applied to a data set of size 20, it has a runtime of 420. Using big-O
notation, state the runtime for this algorithm for the general case of a data set
of size n.
• Suppose you develop an algorithm that processes the first element of an array
(length of n), then processes the first 2 elements, then the first 3 elements, and
so on, until the last iteration of a loop, when it processes all elements. Thus, if n
= 4, the runtime would be 1 + 2 + 3 + 4 = 10.
– Create a table that depicts the runtime for arrays of length 1 to 10. Would
you expect the general runtime to be O(n), O(n2), O(n3), or some other
function of n? Explain
18. For size 8 the run time is 72 which is for one element. It results in 72/8 = 9.
(9) is the element runtime.
8 = (8 * 8) + 8 = 72
For size 10, the run time is 110 which is for one element it is 110/10 = 11 ,
which has incremented by 2 for an increment of 2 numbers of elements.
In this case the element runtime is (11).
10 = (10 * 10) + 10 = 110
For size 20, the run time is 420, is applied to one element it will be 420/20 = 21,
which is incremented by 10 again for an increment of 10 additional elements.
In this case the element runtime is (21)
20 = (20 * 20) + 20 = 420
Now following this trend the value is supposed to be as follows:
Element Formula Value O = int(n2) + n = r.
The runtime of the above computation in Big-Order Notation will be O = int(n2) + n
19. • Suppose you develop an algorithm that processes the first element of an array (length
of n), then processes the first 2 elements, then the first 3 elements, and so on, until the
last iteration of a loop, when it processes all elements. Thus, if n = 4, the runtime would
be 1 + 2 + 3 + 4 = 10.
• SOLUTION: The binary search formula would be Big Oh notation = 𝑂(𝑛 ∗
𝑛+1
2
)
• The table below shows the progression of the algorithm to get the solution.
• N/value = runtime value
The “N” runtime value would be = 55 at 10
1 = 1 = 1
2 = 1+2 = 3
3 = 1+2+3 = 6
4 = 1+2+3+4 = 10
5 = 1+2+3+4+5 = 15
6 = 1+2+3+4+5+6 = 21
7 = 1+2+3+4+5+6+7 = 28
8 = 1+2+3+4+5+6+7+8 = 36
9 = 1+2+3+4+5+6+7+8+9 = 45
10 = 1+2+3+4+5+6+7+8+9+10 = 55
By utilizing the above equation 𝑶(𝒏 ∗
𝒏+𝟏
𝟐
) the value may be plugged in to represent the 10 tables
and outcomes. Therefore, it would NOT just fall into O(n), O(n2) or O(n3) but as modification of
O(n).