I have this NFA in the book given:
And their solved DFA result was this:
But According to my solved solution (by finding e-closure of each state), it looks something like this:
| a | b | c
----+----- +-----+---
ABD | CEBD | Φ | C
BD | EBD | Φ | C
C | Φ | EBD | Φ
D | EBD | Φ | Φ
EBD | EBD | Φ | C
CEBD| EBD | EBD | C
What am I missing?
Your solution is identical to the DFA diagram, with two differences:
Your table contains unreachable states (BD, D). Those are culled from the diagram.
There is a misprint in the diagram. The two arrows between {C} and {BDE} have their labels switched. (The arrow going from {C} to {BDE} should be labeled b, and the arrow from {BDE} to {C} should be labeled c.)
Related
I want to design a DFA for the following language after fixing ambiguity.
I thought and tried a lot but couldn't get a proper answer.
S->aA|aB|lambda
A->aA|aS
B->bB|aB|b
I recommend first getting an NFA by considering this to be a regular grammar; then, determinize the NFA, and then we can write down a new grammar that's equivalent to this one but unambiguous (for the same reason the determinized automaton is deterministic). Writing down the NFA for this grammar is easy: productions of the form X -> sY translate into transitions from state X to state Y on input s. Similarly, transitions of the form X -> lambda mean X is an accepting state, and transitions of the form X -> b imply a new accepting state that transitions to a dead state.
We need states for each nonterminal symbol S, A and B; and we will have transitions for every production. Our NFA looks like this:
/---a----\
| |
V |
----->(S)--a-->(A)<--\
| | |
a \--a-/ /--a,b--\
| | |
V V |
/--->(B)--b-->(X)-a,b->(Y)<-----/
| |
\-a,b-/
Here, states (S) and (X) are accepting, state (Y) is a dead state (we didn't really need to depict this explicitly, but bear with me) and this automaton is totally equivalent to the grammar. Now, we need to determinize this. States of the determinized automaton will correspond to subsets of states from the nondeterministic version. Our first deterministic state will correspond to the set containing just (S), and we will figure out the other required subsets (of which we can have at most 32, since we have 5 states and 2 to the power of 5 is 32) using the transitions:
Q s Q'
{(S)} a {(A),(B)}
{(S)} b empty
{(A),(B)} a {(A),(B),(S)}
{(A),(B)} b {(B),(X)}
{(A),(B),(S)} a {(A),(B),(S)}
{(A),(B),(S)} b {(B),(X)}
{(B),(X)} a {(B),(Y)}
{(B),(X)} b {(B),(X),(Y)}
{(B),(Y)} a {(B),(Y)}
{(B),(Y)} b {(B),(X),(Y)}
{(B),(X),(Y)} a {(B),(Y)}
{(B),(X),(Y)} b {(B),(X),(Y)}
We encountered six states, plus a dead state (empty) which we can name q1 through q6, plus qD. All of the states corresponding to subsets with either (S) or (X) in them are accepting, and (S) is the initial state. Our DFA looks like this:
/-a,b-\
| |
V |
----->(q1)--b-->(qD)----/
|
a /--a--\
| | |
V V |
(q2)--a-->(q3)----/
| |
b |
| b
V |
/--(q4)<------/ /--b--\
| | | |
| \------b------(q6)<---+
a /--a----\ | |
| | | | |
\-->(q5)<-----+--a-/ |
| |
\---------b---------/
Finally, we can read off the unambiguous regular grammar from our DFA:
(q1) -> a(q2) | b(qD) | lambda
(qD) -> a(qD) | b(qD)
(q2) -> a(q3) | b(q4)
(q3) -> a(q3) | b(q4) | lambda
(q4) -> a(q5) | b(q6) | lambda
(q5) -> a(q5) | b(q6)
(q6) -> a(q5) | b(q6) | lambda
I'm looking for a way to show (in the Google Spreadsheet) the most frequently occurring word in the row, but if it isn't one word I want to display all of them separated by semicolon which have the same count of occurrence.
Explanation:
For example, I want to fill the last column with values as below:
+---+------+------+------+------+------+-------------------+
| | A | B | C | D | E | F |
+---+------+------+------+------+------+-------------------+
| 1 | Col1 | Col2 | Col3 | Col4 | Col5 | Expected response |
| 2 | A | A | C | D | E | A |
| 3 | A | A | B | B | B | B |
| 4 | A | A | B | B | E | A, B |
| 5 | A | B | C | D | E | A, B, C, D, E |
+---+------+------+------+------+------+-------------------+
Here's what I have achieved (formula for cell F2):
=INDEX(A2:E2; MODE(MATCH(A2:E2; A2:E2; 0)))
but it doesn't work for 4th and 5th row as I expect.
This works in Office 365 Excel, but probably will not in Excel online, as it is an array formula.
=TEXTJOIN(", ",TRUE,INDEX(A2:E2,,N(IF({1},MODE.MULT(IF(((MATCH(A2:E2,A2:E2,0)=COLUMN(A2:E2))*(COUNTIF(A2:E2,A2:E2)=MAX(COUNTIF(A2:E2,A2:E2)))),COLUMN(A2:E2)*{1;1}))))))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. If done correctly then Excel will put {} Around the formula.
EDIT:
To do it with Google Sheets as you now want:
=join(", ",filter(A2:E2,column(A2:E2)=match(A2:E2,A2:E2,0),countif(A2:E2,A2:E2)=max(countif(A2:E2,A2:E2))))
F2:
=JOIN(",",SORTN(TRANSPOSE(A2:E2),1,1,ARRAY_CONSTRAIN(FREQUENCY(MATCH(A2:E2,A2:E2,0),COLUMN(A2:E2)),COUNTA(A2:E2),1),0))
See syntax # https://support.google.com/docs/table/25273
I have created a BNF for a certain language and want to check if a certain input is valid for that BNF. For instance, if I have a BNF like
<palindrome> ::= a <palindrome> a | b <palindrome> b |
c <palindrome> c | d <palindrome> d |
e <palindrome> e | ...
| z <palindrome> z
<palindrome> ::= <letter>
<letter> ::= a | b | c | ... | y | z
the string 'bcdcb' and 'hannah' will return true.
the string 'joe' will return false.
Can someone describe an algorithm that can do this.
This algorithm doesn't work with joe because it's checking are first and last letter same, it's searching palindromes words. 'joe' is not palindrome word. So it's ok that it doesn't pass.
I have a column chart in Highcharts that looks roughly like this:
| |
| |
S | |
e | | M
c | +-+ | e
o | +-+ | | +-+ +-+ +-+ | t
n | +-+ | | | | | | | | +-+ | | | e
d | | | | | | | | | +-+ | | | | | | | r
s | | | +-+ | | | | | | | | | | | | | | | s
| |1| |2| |3| |1| |2| |3| |1| |2| |3| |
+-------------------------------------------------------------+
Fld A (s) Fld B (s) Fld C (m)
The labels "1", "2", and "3" refer to records; while "A", "B", and "C" refer to fields. So record #1 is represented as three separate values over fields A, B, and C, as represented by the labeled columns. I achieved this result by:
Providing an array to the series config option, one series for each record.
Providing an array to the xAxis/categories config option, one element for each field name.
Providing a 2-element array to the yAxis config option.
My problem is that values in field C will are shown on the Seconds axis, even though they are in units of Meters. I could change the entire series to be on the Meters axis (via the series/yAxis config option), but then fields A and B would show on the wrong axis.
Is there any way to map values within a series to different axes?
EDIT 9/12/2011: If this is impossible as stated, I'm willing to accept an alternate method, such as a different configuration or modifying Highcharts internals, via a plugin or otherwise.
EDIT 9/13/2011: I asked the same question on the HighCharts forum here: http://highslide.com/forum/viewtopic.php?f=9&t=12315, and no one has answered it there either. I'm beginning to think there is probably not any easy answer. :)
A demo is available here: http://www.highcharts.com/demo/combo-dual-axes
chart.yAxis should be an array of two yAxis objects and your series object should specify the yAxis that it corresponds to.
A highslide support person told me this is not possible.
However, another person gave me a possible workaround: create a separate set of series for field C. Then set the values for fields A and B in the second set to null, and set the values in the first set of series for field C to null.
There is a link to a jsfiddle that demonstrates this workaround in the forum topic: http://highslide.com/forum/viewtopic.php?f=9&t=12315
How can i implement an eliminator for this?
A := AB |
AC |
D |
E ;
This is an example of so called immediate left recursion, and is removed like this:
A := DA' |
EA' ;
A' := ε |
BA' |
CA' ;
The basic idea is to first note that when parsing an A you will necessarily start with a D or an E. After the D or an E you will either end (tail is ε) or continue (if we're in a AB or AC construction).
The actual algorithm works like this:
For any left-recursive production like this: A -> A a1 | ... | A ak | b1 | b2 | ... | bm replace the production with A -> b1 A' | b2 A' | ... | bm A' and add the production A' -> ε | a1 A' | ... | ak A'.
See Wikipedia: Left Recursion for more information on the elimination algorithm (including elimination of indirect left recursion).
Another form available is:
A := (D | E) (B | C)*
The mechanics of doing it are about the same but some parsers might handle that form better. Also consider what it will take to munge the action rules along with the grammar its self; the other form requires the factoring tool to generate a new type for the A' rule to return where as this form doesn't.