Question: c++ I learned that we cannot recognize the languages like a n b n using FSM (basically, we need to output 1 whenever # of

c++

I learned that we cannot recognize the languages like anbn using FSM (basically, we need to output 1 whenever # of a's followed by same # of b's. So, ab, aabb, aaabbb are in that language, but aa, aab, ba, bbaa, aaabb... are not in that language). However, if I add a few variables, then we can recognize the language!

How do I write code to recognize the following languages(in c++):

L1 = {anbncndn for any n > 0, a, b, c & d are the possible input symbols} For example, abcd, aabbccdd are in the language, whereas abd, ad, aabcd, dbca, dcba ... are not in the language. For this first language, L1, You are allowed to have 2 variables (Interestingly, anbncmdm for any n, m > 0 requires only one variable - how?)

L2 = {any string made up of a's and b's s.t. # of a's is same as # of b's, a, & b the possible input symbols}. For this language L2, You are allowed to have only one additional variable.

Include your code and a few screenshots showing the sample runs for specified strings above.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!