My program works correctly for some values of n, but not all of them. Any ideas why?
Often this problem is related to forgetting how for loops work. Suppose you have a loop of the form: for (i=0; i < n; i++){ loop body } Remember that the value of i in the last iteration of the loop is n-1 (since it is the last integer value less than n). Recall that the above loop is equivalent to: i=0; while (i < n){ loop body i++; } I personally discourage the use of less than above but rather recommend the for loop is written like: for (i=0; i <= n-1; i++){ loop body } The most common place where I’m seeing this error is in the final loop. In class I put: for i = 0 to |Y’|-2 First, by |Y’| I mean the number of elements placed into the Y’ array. In the above for loop i should go from 0 (the lowest point) to |Y’|-2 (the second to highest point).