Adding algorithm3