all the 3 algorithms: almost done ...