How to tell if a code is lossless Consider the following code mapping:
$$a \mapsto 010, \quad b\mapsto 001, \quad c\mapsto 01$$
It's easy to see that the code isn't lossless by observing the code $01001$, which can be translated to "ac" or "cb".  
Given a general code, how can you tell if it's lossless or not? I don't think trial and error is the best approach (though for small examples like the one I presented it's enough).  

Thats kind of hard for a general code but you can use the Sardinas-Patterson algorithm.
The algorithm generates all possible "dangling suffixes" and checks to see if any of them is a codeword. A dangling suffix is the bits that are "left over" when you compare two similar sequences of your code. If you want your code to be decodable, there can be no dangling suffixes that are codewords.
In your example, if we compare "ac" and "c" we get
ac = 01001
c  = 01

As you can see, ac is three bits longer than c, those bits (001) are the dangling suffix. And since 001 is also a codeword, the code is not uniquely decodable.
In a real life scenario though, we would probably use prefix codes instead of general codes since they are just as effective, faster and guaranteed to be uniquely decodable.
