Library

DPDA · Deterministic context-free

As many a’s as b’s, in any order

The stack holds the surplus: A’s while a is ahead, B’s while b is. A letter either adds to the surplus or cancels one. After a cancellation the machine looks at the top to see whether it is back to even, which is the only accepting state.

evenaheadcheck
The machine as drawn — 3 states, 9 transitions.

The author’s examples, run

ε → acceptaabb → acceptba → acceptbaabbaabbaab → accepta → rejectbabb → rejectaa → rejectaaabbaabbaab → reject