Question

L = { w | w ∈ {a, b}* and a(w) != b(w) }. Implement the...

L = { w | w ∈ {a, b}* and a(w) != b(w) }.

Implement the pushdown automaton A in python

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Pushdown Automata that accepts the given language is as follows:

2 λλ baZZ abbaZZ

Above PDA is implemented below:

CODE:

def PDA(string):
    Stack = ['Z']

    for s in string:
        TOS = Stack[-1]

        if (s == 'a' or s == 'b') and TOS == 'Z':
            Stack.append(s)
        
        if (s == 'a' and TOS == 'a') or (s == 'b' and TOS == 'b'):
            Stack.append(s)
    
        if (s == 'a' and TOS == 'b') or (s == 'b' and TOS == 'a'):
            Stack.pop()     
        
    if Stack == ['Z']:
        return 'REJECTED'
    else:
        return 'ACCEPTED'
        
        
s1 = 'ababab'
s2 = 'baba'
s3 = 'abbba'
s4 = 'abbbbbbbbbbaaaaaa'
print(s1,":",PDA(s1))
print(s2,":",PDA(s2))
print(s3,":",PDA(s3))
print(s4,":",PDA(s4))

OUTPUT:

def PDA (string): stack = [,2] for s in string: TOS stack[-1] = Stack.append(s) if (s == a, and TOS . a.) or (s- , b. and TO

Add a comment
Know the answer?
Add Answer to:
L = { w | w ∈ {a, b}* and a(w) != b(w) }. Implement the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT