direct algorithm