Solution to Regular Final Spring 2002

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

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

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

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

View Full Document
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; }
4. public Expression createPostfixExpression( Expression ex )
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/30/2010 for the course CS 307 taught by Professor Scott during the Spring '08 term at University of Texas.

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
Ask a homework question - tutors are online