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

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

View Full Document Right Arrow Icon
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 )
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online