0

I am trying to recognize a particular language,

L= {a^n b^k | n<=k<=2n}

and according to me it should not be CFL, as i can see two comparision i.e. firstly number of a is compare to keep count less than equal to k, and secondly for count of b that should be less than twice n. My question then how it is still CFL??

Thankyou in advance for sharing your wisdom!! :)

Niraj Jain
  • 19
  • 5

1 Answers1

0

If you're using grammars, then this is easy to see: $$S\to aSb\mid aSbb\mid \epsilon$$ That is, each $a$ corresponds to either 1 or 2 $b$'s.

If you're thinking about it from the automata perspective, then a PDA can push to the stack $n$ symbols while reading $a^n$, and then start popping those symbols upon reading $b^k$, with the following change: it may nondeterministically choose not to pop a symbol, but the it moves to a new state from which it must pop a symbol after reading $b$. This ensures that the number of $b$'s that are read is between $n$ and $2n$.

Shaull
  • 17,159
  • 1
  • 38
  • 64
  • Thanks!! @Shaull , i truly respect you for your answer also for other answer you mention for Finite Automata mixture combinatorics, here i am able to get grammar part, but with respect to PDA, as per your approach will it not accept number of b greater than 2 times n? – Niraj Jain Oct 21 '22 at 05:59
  • No, because after not popping a symbol upon reading $b$, you move to a new state where you have to pop upon reading $b$, and then go back to the first state. – Shaull Oct 21 '22 at 06:06
  • got it completely!! Thanks for clarification @Shaull !! :) – Niraj Jain Oct 21 '22 at 06:41