MATH203-1403A-02
Applications of Discrete
Mathematics
Phase 4 / IP 1
Mark L. Simon II
Instructor: Doris Schantz
July 31, 2014
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.
• 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)
{1, 3, 5, 7, 9, 12,
14, 16, 18, 21,
23, 25, 27, 28,
30, 32, 34, 36}
{2, 4, 6, 8, 10,
11, 13, 15, 17,
19, 20, 22, 24,
26, 29, 31, 33,
35
{1, 3, 5,
7, 9, 21,
23, 25, 27,}
{ 2, 4, 6, 8,
10, 20, 22,
24, 26, }
(A∩D) = {12, 14,16, 18, 28, 30, 32, 34,
36}
(A U B) = {1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24 25,26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36}
U U
A B
A D
Null
12, 14,16,
18,28,30,
32,34,36
2, 4, 6, 8, 10,
11, 13, 15, 17,
19, 20, 22, 24,
26, 29, 31, 33,
35
0, 00 0, 00
1, 3, 5, 7, 9,
11, 13, 15, 17,
19, 21, 23, 25,
27, 39, 31, 33,
35
(B∩C) = {Φ} (C ∪ E) = {0, 00, 1, 3, 5, 7, 9, 11,
13, 15, 17,
19, 21, 23, 25, 27, 39, 31, 33,
35}
U U
B C C E
NullNull
13, 15, 17,
19, 20, 22, 24,
26, 29, 31, 33,
35
1,3,5,
7,9,12
13, 15, 17,
19, 21, 23,
25, 27, 39,
31, 33, 35
2,4,6,
8,10,12
(B ∩ F) = {2, 4, 6, 8, 10, 11} (E∩F) = {1, 3, 5, 7, 9, 11}
U U
B F E F
1, 3, 5, 7,
9, 11,
2, 4, 6,
8, 10, 11
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
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)
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
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)
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 )
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.
P/V - Algorithm Analysis
• Consider searching algorithms on the following array of data:[22 21 9 4 16 2 10 14 20 31 26
19 17 28 8 13]
• Suppose you want to implement a searching algorithm to see if the data set contains the
number 19. Demonstrate how the search would go if you used:
– A sequential search
– A binary search
• State the runtime for each of the searches, in this example, and for general data sets of
size n. Address the issue of the order of the data in binary searching.
• 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.
P/V - Algorithm Analysis
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
}
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
Algorithmic Sequential (Binary)
Search
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
}
The Binary Search
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[(4 + 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.
P/V - Algorithm Analysis
P/V - Algorithm Analysis
P/V - Algorithm Analysis

Discrete Math IP4 - Automata Theory

  • 1.
    MATH203-1403A-02 Applications of Discrete Mathematics Phase4 / IP 1 Mark L. Simon II Instructor: Doris Schantz July 31, 2014
  • 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 tableof 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)
  • 4.
    {1, 3, 5,7, 9, 12, 14, 16, 18, 21, 23, 25, 27, 28, 30, 32, 34, 36} {2, 4, 6, 8, 10, 11, 13, 15, 17, 19, 20, 22, 24, 26, 29, 31, 33, 35 {1, 3, 5, 7, 9, 21, 23, 25, 27,} { 2, 4, 6, 8, 10, 20, 22, 24, 26, } (A∩D) = {12, 14,16, 18, 28, 30, 32, 34, 36} (A U B) = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 25,26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36} U U A B A D Null 12, 14,16, 18,28,30, 32,34,36
  • 5.
    2, 4, 6,8, 10, 11, 13, 15, 17, 19, 20, 22, 24, 26, 29, 31, 33, 35 0, 00 0, 00 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 39, 31, 33, 35 (B∩C) = {Φ} (C ∪ E) = {0, 00, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 39, 31, 33, 35} U U B C C E NullNull
  • 6.
    13, 15, 17, 19,20, 22, 24, 26, 29, 31, 33, 35 1,3,5, 7,9,12 13, 15, 17, 19, 21, 23, 25, 27, 39, 31, 33, 35 2,4,6, 8,10,12 (B ∩ F) = {2, 4, 6, 8, 10, 11} (E∩F) = {1, 3, 5, 7, 9, 11} U U B F E F 1, 3, 5, 7, 9, 11, 2, 4, 6, 8, 10, 11
  • 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: AutomataTheory, 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.
    P/V - AlgorithmAnalysis • Consider searching algorithms on the following array of data:[22 21 9 4 16 2 10 14 20 31 26 19 17 28 8 13] • Suppose you want to implement a searching algorithm to see if the data set contains the number 19. Demonstrate how the search would go if you used: – A sequential search – A binary search • State the runtime for each of the searches, in this example, and for general data sets of size n. Address the issue of the order of the data in binary searching. • 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.
  • 14.
    P/V - AlgorithmAnalysis 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 }
  • 15.
    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
  • 16.
    Algorithmic Sequential (Binary) Search Thisalgorithm 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 }
  • 17.
    The Binary Search Searchfor 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[(4 + 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.
  • 18.
  • 19.
  • 20.