algorithms implemention by java