Solution to Regular Final Spring 2002

Solution to Regular Final Spring 2002 - Solution to Regular...

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

View Full Document Right Arrow Icon
Solution to Regular Final Spring 2002 1A 1B 37 7 17 13 29 101 47 53 401 1C 7 13 17 29 37 47 53 101 401 1D 13 29 17 7 53 47 401 101 37 1E Yes 1F O( log N ) 1G O( N ) 1H O ( N log N ) 1I O( N ^ 2 ) 1J O( N ^ 3 ) IK O( N ^ 2 log N ) 1L O( N ^ 2 ) 1M O( N ) 1N O( N ) 1O 63 1P 63 1Q 1R 25 seconds 1S 160 seconds 1T Yes. add an if statement to do a range check on list before accessing the 12 th element
Background image of page 1

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

View Full DocumentRight Arrow Icon
2. public int[] getNodesAtEachDepth( BTNode n ) { int[] depths = new int[ getHeight( n ) ]; addDepths( depths, n, 0 ); return depths; } public static void addDepths( int[] depths, BTNode n, int curDepth) { if( n != null ) { depths[curDepth]++; addDepths( depths, n.left, curDepth + 1); addDepths( depths, n.right, curDepth + 1); } } 3. public int getSize( Directory dir ) { // get sub directories Directory[] ds = dir.getDirectories(); // get files in dir File[] fs = dir.getFiles(); int total = 0; for( int i = 0; i < fs.length; i++) total += fs[i].getSize(); for( int i = 0; i < ds.length; i++) total += getSize( ds[i] ); return total; }
Background image of page 2
4. public Expression createPostfixExpression( Expression ex )
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

Solution to Regular Final Spring 2002 - Solution to Regular...

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

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