Java algorithm implementations