small algorithm questions