Implementation with efficiency for all algorithms in algorithm class