java algorithms implement