m2solution

# m2solution - 1 Solution and criteria Matching answer or 2 A...

This preview shows pages 1–2. Sign up to view the full content.

1. Solution and criteria Matching answer or –2 A. 4 B. wheels: 6, 2 wheel drive (missing : or , okay) C. wheels: 4 wheels: 6, 6 wheel drive (missing : or , okay) D. 20 E. 55 F. Infinite Recursion or Runtime Error or Stack Overflow Error or Out of Memory Error or Exception G. 12,502,500 or 5000(5001)/2 or evidence of attempting to compute 5000(5001)/2 H. N or O(N) I. N log N or O( N log N ) (if base 2 included on log okay) J. 24 2. Model solution The biggest problems were with people not tracking cells they had already visited. Because water can flow to equal elevations in this problem not tracking this and not moving to a cell if it has already been visited leads to infinite recursion. A number of people also did not check elevations to see if a move was legal. public boolean drains(int[][] world, int row, int column) { public boolean[][] visited = new boolean[world.length][world[0].length]; // all set to false when created so no need to initialize return recursiveDrains(world, row, column, visited, world[row][column); } public boolean recursiveDrains(int[][] world, int row, int col, boolean[][] visited, int previousElevation) { boolean result = false; if(row == 0) || row == world.length – 1 || col == 0 || col == world[0].length – 1) result = true; else if( visited[row][col] || world[row][col] > previousElevation )

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 4

m2solution - 1 Solution and criteria Matching answer or 2 A...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online