




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





CS 61B, Spring, 2006, Hilfinger
Code Result d. class Thing { int x; "equal" – the equals method returns true public Thing( int x ) { this.x = x; } public boolean equals( Object p ) { return x == ((Thing) p).x; } public static void main(String[] args) { Thing p1 = new Thing(3), p2 = new Thing(3); if( p1.equals( p2 )) System.out.println("equal"); else System.out.println("not equal"); } } e. class Thing { int x; runtime error – cannot cast "(3)" to Thing public Thing( int x ) { in equals method. this.x = x; } public boolean equals( Object p ) { return x == ((Thing) p).x; } public static void main(String[] args) { Thing p1 = new Thing(3); if( p1.equals( "(3)" )) System.out.println("equal"); else System.out.println("not equal"); } }
private List
c. Assuming that next and hasNext on Powerset iterators take constant time, what is the worst-case time for subsetSum (Be as precise as possible). n2n −^1 n where n is ints.size()
/* b. / /* A list that is identical to L, except that the first