0

I want to code this for PDA. How would I do that in C#?

a^nbc^n (n>=0) 
DanM7
  • 2,203
  • 3
  • 28
  • 46
ozkank
  • 1,464
  • 7
  • 32
  • 52

1 Answers1

6

Algorithm:

Read one letter at a time from the input, in a loop.

Stage 1:

If the letter read is "a" then increment a counter, and repeat Stage 1. If the letter read is not "a" then proceed to the next part.

Stage 2:

If the letter read is "b" then proceed to the next stage. If the letter read is not "b" then the algorithm fails.

Stage 3:

If if the letter read is "c" then decrement the counter, and repeat Stage 3. If the letter read is not "c" then proceed to the next stage.

Stage 4:

If the counter is zero, then the algorithm succeeds, otherwise it fails.

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
  • I do not see why abcc should fail while abcd should suceed. – Taemyr Nov 12 '20 at 13:21
  • @Taemyr because the number of `a` must equal the number of `c`. (The number `n` in the formula given.) – Kevin Panko Nov 13 '20 at 23:02
  • Let me rephrase; I do not see why aabcca should suceed and aabccc fail. I can see aabcca suceeding if you consider reaching an accepting state at some point in the reading the string, but in that case aabccc should also suceed. If you only consider sucees as ending in an accepting state when the string terminates then aabcca should not suceed. – Taemyr Nov 15 '20 at 22:35
  • @Taemyr Ah, I understand. Yes, it is necessary to check for the end of the input. – Kevin Panko Nov 18 '20 at 23:06