I have seen words which are spelled either with a "z" or with a "s" like "optimizer" and " optimiser". I thought that the ones with "z" are wrong but on searching the web I found that both are correct. Why so? Is there any difference in the use also?
"-ize" is the common AmE suffix, while in BrE "-ise" is more commonly used:
word-forming element used to make verbs, Middle English -isen, from Old French -iser, from Late Latin -izare, from Greek -izein, a verb-forming element denoting the doing of the noun or adjective to which it is attached.
English picked up the French form, but partially reverted to the correct Greek -z- spelling from late 16c. In Britain, despite the opposition to it (at least formerly) of OED, Encyclopaedia Britannica, the "Times of London," and Fowler, -ise remains dominant.
Fowler thinks this is to avoid the difficulty of remembering the short list of common words not from Greek which must be spelled with an -s- (such as advertise, devise, surprise).***