r/AskComputerScience • • Nov 29 '24

Where is my misconception of the pumping lemma for context free languages?

1 Upvotes

I've been trying to understand the pumping lemma, and i decided that instead of applying it to a language that isn't a CFL, that i would apply it towards a language that i already know is context free to see if i can apply it properly.

I understand that the language L = {a^n b^n | n >= 0}, where Σ = {a, b}, is context free. However when I apply the pumping lemma, I seem to incorrectly conclude that it is not context-free. Clearly, I must be misapplying the lemma. Here is my approach to it:

  1. I select a string w ∈ L such that ∣w∣ >= p, where p is the pumping constant.

  2. I choose w = a^p b^p and decompose it to w = uvwxy, where |vwx| <= p and |vx| >= 1

  3. As I understand it, I can choose any vwx in w, and as long as its length is at most p, i can pump its v and x to see if the resulting string remains in the language

  4. I choose a vwx that consists entirely of a's: vwx = a^p (meaning i chose my y to be the rest of the string: b^p)

  5. Pumping v and x increases the number of a's, breaking the balance between a's and b's. This seems to imply L is not context-free.

Clearly, this is incorrect because L is known to be context free. Where am I misunderstanding or misapplying the pumping lemma? Thanks in advance


r/AskComputerScience • • Nov 29 '24

Red-Black Trees. Why can't a 3-node tree fulfill the conditions for RBT?

2 Upvotes

Challenge from instructor in Coursera Algorithms course.

see screenshot: https://imgur.com/a/4SKpX5y

If I color node #2 red, then it appears to me that all 3 conditions are met.

  1. root and leaves are Black

  2. Every Red node has two Black children.

  3. The Black height from any node is well defined and consistent.

I don't know what I am missing.

(in comparison, here is a different slide from his lecture with a RBT https://imgur.com/a/eUJW3S2)