Princeton algorithms implementation (scala)