COMP 2012H
Honors Object-Oriented Programming and Data Structures
Lab 2
Functions and Arrays
Common Errors
- Forgetting to return
0 in check() when clicking on the empty cell.
- Illegal swapping of empty cell with other diagonal cells.
- 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.
- Forgetting to count reverse pairs in
generate().
- Forgetting to ignore the empty cell when counting reverse pairs in
generate().
- 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.
- 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.