add balanced partition algorithm code