K2 algorithm