ddh algorithm