fix bug in algorithm.c