COMP 2012H Honors Object-Oriented Programming and Data Structures

Lab 2 Functions and Arrays

Common Errors

  1. Forgetting to return 0 in check() when clicking on the empty cell.

  2. Illegal swapping of empty cell with other diagonal cells.

  3. Not able to move the middle cell and the clicked cell, if there is a middle cell in between the clicked cell and the empty cell.

  4. Forgetting to count reverse pairs in generate().

  5. Forgetting to ignore the empty cell when counting reverse pairs in generate().

  6. Double-counting the number of reverse pairs with an incorrect indexing of nested for loops. For example, index j = 0 instead of j = i + 1 in the inner loop.

  7. Counting reverse pairs wrongly. For example, returning solvable for odd number of reverse pairs, or returning solvable when there exists a reverse pair without checking if there are an even number.