Question: Problem 6: Professor LeBlanc decides to create a custom implementation of a min-heap of Java Integer objects called IntHeap. For simplicity, an IntHeap object cannot


Problem 6: Professor LeBlanc decides to create a custom implementation of a min-heap of Java Integer objects called IntHeap. For simplicity, an IntHeap object cannot store duplicate elements. To account for the fact that left and right children are interchangeable in a min-heap, Prof. Stack designs the IntHeap equals) method to have the following logic. Note that this is not necessarily a good design, it is simply the one chosen by Prof. LeBlanc. Two IntHeap objects "this" and "other" are considered equal if and only if ALL theollowing conditions are met: 1. this and other have the same size. 2. Each Integer contained in this has a corresponding Integer in other with the same int value. Each Integer in this has a parent that equals the parent of its corresponding element in other (with the root Integers having null parents) 3. Now consider the following implementations of the hashCode ) function for the IntHeap class. For each implementation, please state (a) whether the function is correct according to Java's requirements for the hashCode () function (b) regardless of correctness, whether the function does a good job or a poor job of satisfying the Uniform Hashing Assumption for a reasonable range of inputs (i.e., how well the function distributes outputs across possible int values) . a) public int hashCode ) return size; / "size" stores the number of elements in the heap Correct hashCode function (yeso)? If "no", sketch two heaps that prove it is incorrect: Regardless of correctness, how well does the function satisfy uniform hashing (well/poorly)? If "poorly," sketch two heaps that are not equal according to the equals() function given above, yet still return the same hashCode value: Problem 6: Professor LeBlanc decides to create a custom implementation of a min-heap of Java Integer objects called IntHeap. For simplicity, an IntHeap object cannot store duplicate elements. To account for the fact that left and right children are interchangeable in a min-heap, Prof. Stack designs the IntHeap equals) method to have the following logic. Note that this is not necessarily a good design, it is simply the one chosen by Prof. LeBlanc. Two IntHeap objects "this" and "other" are considered equal if and only if ALL theollowing conditions are met: 1. this and other have the same size. 2. Each Integer contained in this has a corresponding Integer in other with the same int value. Each Integer in this has a parent that equals the parent of its corresponding element in other (with the root Integers having null parents) 3. Now consider the following implementations of the hashCode ) function for the IntHeap class. For each implementation, please state (a) whether the function is correct according to Java's requirements for the hashCode () function (b) regardless of correctness, whether the function does a good job or a poor job of satisfying the Uniform Hashing Assumption for a reasonable range of inputs (i.e., how well the function distributes outputs across possible int values) . a) public int hashCode ) return size; / "size" stores the number of elements in the heap Correct hashCode function (yeso)? If "no", sketch two heaps that prove it is incorrect: Regardless of correctness, how well does the function satisfy uniform hashing (well/poorly)? If "poorly," sketch two heaps that are not equal according to the equals() function given above, yet still return the same hashCode value
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
