Basic algorithm implementations in PHP