I think you should try to define some criteria for the algorithm you are looking for. You may want a guaranteed response time. Or you might prefer absolute data consistency. It seems unlikely to achieve both at the same time.
The subject you are talking about is called Operational Transformation: http://en.wikipedia.org/wiki/Operational_transformation
Some open source software do amazing things in this field, like http://sharejs.org/ or http://etherpad.org/