NOD algorithm