In general, when looking at a language, a good rule of thumb for whether the language is regular or not is to think of a program that can read a string and answer the question "is this string in the language?"
To write such a program, do you need to store some arbitrary value in a variable or is the program's state (that is, the combination of all possible variables' values) limited to some finite fixed number of possibilities? If the language can be recognized by a program that only needs a fixed number of variables that can only have a fixed number of values, then you've got a regular language. If not, then not.
Using this, I can see that the first language is not regular, but the second language is. In the first language, I need to remember how many a
s I've seen, and how many b
s. (Or at the very least, I need to keep track of (# of a
s) - (# of b
s), and accept if the string ends while that count is negative). At the same time, there's no limit on the number of a
s, so this count could go arbitrarily large.
In the second language, I don't care what n
and m
are at all. So with the second language, my program would just keep track of "have I seen at least one b
yet?" to make sure we don't have any a
characters that occur after the first b
. (So, one variable with only two values - true or false)
So one way to make language 1 into a regular language is to change it to be:
1. L={w ∈ {a,b}*/no of a in (w) < no of b in (w), and no of a in (w) < 100}
Now I don't need to keep track of the number of a
s that I've seen once I hit 100 (since then I know automatically that the string isn't in the language), and likewise with the number of b
s - once I hit 100, I can stop counting because I know that'll be enough unless the number of a
s is itself too large.
One common case you should watch out for with this is when someone asks you about languages where "number of a
s is a multiple of 13" or "w ∈ {0,1}* and w is the binary representation of a multiple of 13". With these, it might seem like you need to keep track of the whole number to make the determination, but in fact you don't - in both cases, you only need to keep a variable that can count from 0 to 12. So watch out for "multiple of"-type languages. (And the related "is odd" or "is even" or "is 1 more than a multiple of 13")
Other mathematical properties though - for example, w ∈ {0,1}* and w is the binary representation of a perfect square - will result in non-regular languages.