Pushdown Automaton (PDA) Example: {0^n 1^n}

Here we derive a PDA for the infamous non-regular language {0^n 1^n : n at least 0}. We give some tips as well for how to solve other PDAs. The general aspect here is to "match" 0s with 1s by pushing 0s onto the stack, and popping the 1s in tandem. There is some complication with popping an empty stack, so we push a "dummy" character on the stack to detect when the matching has concluded to avoid this problem.
What is a pushdown automaton? It is a finite state machine, where on each transition, items can be pushed or popped off of a stack it has, which has unlimited height. See • What is a Pushdown Aut... for more details.
▶ABOUT ME◀
I am a professor of Computer Science, and am passionate about CS theory. I have taught many courses at several different universities, including several sections of undergraduate and graduate theory-level classes.

Пікірлер: 53

  • @tonyjaimep
    @tonyjaimep2 жыл бұрын

    Explains in 10 minutes what my professor took two hours to skim over, thank you!

  • @EasyTheory

    @EasyTheory

    2 жыл бұрын

    I wouldn't discount another professor that easily, but thanks anyway!

  • @Kevin-bb7wk
    @Kevin-bb7wk Жыл бұрын

    Ryan your videos are saving my bacon in my Models of Computation class. You're the man!

  • @hamedpanjeh3947
    @hamedpanjeh39473 жыл бұрын

    Indeed, awesome explanation in a very short time is an art! recording date of this video tells me I am super lucky to have such rich resource on the exact time! Thank you Ryan!

  • @EasyTheory

    @EasyTheory

    3 жыл бұрын

    Thanks

  • @AlexReyesInHD
    @AlexReyesInHD3 жыл бұрын

    Thank you for these videos! They're really helpful for me to understand theory of computation. The amazing work you're doing it helping out many students!

  • @EasyTheory

    @EasyTheory

    3 жыл бұрын

    Thanks very much!

  • @user-ln6hz2nb7o
    @user-ln6hz2nb7o11 ай бұрын

    that triple e transition was good point thank you.

  • @mahesh_bvn
    @mahesh_bvn10 ай бұрын

    great video mate keep going. Much love!!!

  • @ianskinner3426
    @ianskinner34266 ай бұрын

    Thank you so much. Very clear and exactly what I needed to understand this

  • @slhx8956
    @slhx89562 жыл бұрын

    This is a great video. Thank you so much

  • @Taayjus
    @Taayjus7 ай бұрын

    thank you so so much! I don't pay attention in class and just look for your video on the topic before the quiz and I've passed all of them

  • @vimalathithand917
    @vimalathithand9174 ай бұрын

    thank you for such a simple and easy to understand video :D

  • @stijnjongbloed1
    @stijnjongbloed1 Жыл бұрын

    Thanks for the video!

  • @sarudesu2883
    @sarudesu28833 жыл бұрын

    very helpful, thank you :)

  • @brianna1347
    @brianna13472 жыл бұрын

    Thank you so much!

  • @omar.alnounou
    @omar.alnounou2 жыл бұрын

    i stopped mid-video just to say THANK YOU

  • @sravanikatasani6502
    @sravanikatasani65023 жыл бұрын

    Can you just put up a worksheet kinda thing ,that'll be great i feel

  • @jaebee229
    @jaebee2296 ай бұрын

    Can you do both loops for 1 and 0 on the same state? Or do you have to have a seperate state to do each

  • @samjudelson
    @samjudelson2 жыл бұрын

    Thanks!

  • @artmissgns8315
    @artmissgns83152 жыл бұрын

    great video

  • @rizzbod
    @rizzbod4 ай бұрын

    Thanks a much!

  • @sravanikatasani6502
    @sravanikatasani65023 жыл бұрын

    Thank you Ryan sir😊

  • @EasyTheory

    @EasyTheory

    3 жыл бұрын

    Thanks!

  • @unordinary27
    @unordinary272 жыл бұрын

    thank you for the video! it was really helpful.

  • @muratpinkman9679
    @muratpinkman9679 Жыл бұрын

    thank you

  • @jonathancohen7653
    @jonathancohen76533 жыл бұрын

    Excellent

  • @EasyTheory

    @EasyTheory

    3 жыл бұрын

    Thanks

  • @iuseyoutubealot
    @iuseyoutubealot27 күн бұрын

    so how come no q loop here or thats for cfg

  • @kudakwashejuniormuzenda5432
    @kudakwashejuniormuzenda54322 жыл бұрын

    helpful indeed

  • @EasyTheory

    @EasyTheory

    2 жыл бұрын

    Glad it helped!

  • @charlesroseman9466
    @charlesroseman94662 жыл бұрын

    Would q0 also be an accept state since 0^n1^n can be an empty string? I know that the empty string is able to go through every state, but I'm just curious if it's appropriate to also make q0 an accept state.

  • @EasyTheory

    @EasyTheory

    2 жыл бұрын

    It can, but no need, since there is a way for empty input to make its way through the machine as-is.

  • @charlesroseman9466

    @charlesroseman9466

    2 жыл бұрын

    @@EasyTheory Okay. Just making sure cuz my professor is a hardass and will probably take credit away for something like that lol. Thanks for the video! Very helpful.

  • @farwahbatool6247

    @farwahbatool6247

    2 жыл бұрын

    @@charlesroseman9466 lol

  • @0x44Monad
    @0x44MonadАй бұрын

    2 stack pushdown automata?

  • @rafaela2400
    @rafaela24003 жыл бұрын

    stupid question but here it goes: If we wanted could we pop off all the 1's at q2, but twice as fast? Meaning if I wanted to have 0^n and 1^2n, could i just have the same thing as your pda, but instead at q2, pop off (11,0) instead of (1,0)? Thank you so much for your tutorials! they are amazing.

  • @EasyTheory

    @EasyTheory

    3 жыл бұрын

    No such thing as a stupid question if you really want to know the answer :) Yes, but only if the language is {0^n 1^(2n) : n at least 0}. If you wanted to apply this to {0^n 1^n : n at least 0} (note the difference in the 1 exponent), then this won't work whenever the input string has n being odd. But if you instead insisted that n be even, then yes you could. The only "problem" is that the PDA definition only allows one character to be read/popped/whatever in one transition. You can augment the definition to an "extended" PDA, where more than one can occur at once. This is usually done on the stack, not the input though. And thanks for watching!

  • @rafaela2400

    @rafaela2400

    3 жыл бұрын

    @@EasyTheory Many thanks for your answer and even more thanks for putting out such great content!!

  • @sayantaniguha8519
    @sayantaniguha85192 жыл бұрын

    Instead of that E-transition b/w q1 & q2 , Can we make the initial state final & write that transition as *1,0->E* ?

  • @zahidgul5811

    @zahidgul5811

    2 жыл бұрын

    then you wouldn't be able to pop $ sign. Which is on stack.

  • @Elrog3

    @Elrog3

    Жыл бұрын

    @@zahidgul5811 the $ isn't on the stack at q0. Its onlt on the stack after you go to q1.

  • @Elrog3

    @Elrog3

    Жыл бұрын

    Yes. That is how the PDA for this language is shown in the textbook I am using.

  • @Fahodinho
    @Fahodinho2 жыл бұрын

    cheers mate

  • @Nikifuj908
    @Nikifuj908 Жыл бұрын

    Hey, I keep following the automaton you drew to verify that it rejects "10". But it keeps landing on the accepting state q3. Am I doing something wrong? Stack: [], String: "10", State: q0 Stack: [$], String: "10", State: q1 Stack: [$], String: "10", State: q2 Stack: [], String: "10", State: q3 (accepting) Or do you have to exhaust the entire input string for it to accept?

  • @Edigor100

    @Edigor100

    Жыл бұрын

    yes he said that at the end, the entire input has to be read in order for it to be able to accept.

  • @TheSpruut
    @TheSpruut3 жыл бұрын

    if the stack needs to be empty to be accepted, why the need for the $ symbol, even without the $ symbol if the input will only finish if there are as many (or more) 1's to 0's and the stack will only empty if there are as many (or more) 0's to 1's so the number of 0's and 1's will need to be the same and no $ should be needed?

  • @farwahbatool6247

    @farwahbatool6247

    2 жыл бұрын

    that way we would not know that the PDA's stack is empty. It's like putting a slab over void to ensure that we're standing on rock bottom 😛

  • @lukesmith9289
    @lukesmith92892 жыл бұрын

    why do # of 0s and 1s need to be equal?

  • @moatef1886

    @moatef1886

    2 жыл бұрын

    That's the definition of the language we are working with. So that's kind of a given, and we're just designing a machine that recognizes that language

  • @andrewliao1351
    @andrewliao13512 жыл бұрын

    9:02 why can't you take that transition? You have read the whole input and it is trying to read epsilon.

  • @moatef1886

    @moatef1886

    2 жыл бұрын

    You can't take that transition because look at what is required to pop off the stack in order to take it? You must be able to pop off the $ symbol from the stack but...the $ is not at the top of the stack! A 0 will be on the top of the stack after you have read all the 0s and all the 1s in the case of there being more 0s than 1s. So yes, epsilon can be read but you cannot pop something off the stack if it is not at the top of the stack.

  • @Yenaled1
    @Yenaled1 Жыл бұрын

    the other type of PDA would be a lot more fun than this