diff algorithm