This is the Java programming language. Please respond as soon as possible. To represent set partitions in this assignment, you will utilise a tree-based data structure. A collection of trees will be used to depict a set division. Each tree will represent a subset, with one node representing each subset element. 1.1 Getting Started - Create the SetPartition class. It should contain the following features: an inner class called Node, as mentioned before; an array of Node objects, one for each set element; and a function Object() { [native code] } called SetPartition (int numElements). The function Object() { [native code] } should set up the array and Nodes to reflect the partition of the set 0-1, numElements 1, where the subsets are 0-1, numElements 1, and numElements 1. 1.2 Finding roots - In your class, create a public int getRoot (int x) function that returns the value at the root of the tree containing x. (Note that the result of getRoot() won't be very interesting until you write merge(), which is described below, because each value will be in a subset containing only itself.) 1.3 Do they belong to the same subset? - Add a public boolean inSameSubset (int x, int y) function that checks if x and y will be in the same division subset. Code evaluation - Create a main method that accomplishes the following tasks. 1. Creates a SetPartition with 1000 components, then calls merge(0,1), merge(1,2),..., merge(998,999) to get the tree's maximum node depth. 2. Creates a SetPartition with 1000 members, calls merge(998,999), merge(997,998), etc., and reports the tree's maximum node depth. 3. Generates 1000 SetPartitions with 1000 items each, performs 750 random merges on each, and provides the average maximum node depth of these trees. (The answer should be in the range of 61–63.
This is the Java programming language.
Please respond as soon as possible.
To represent set partitions in this assignment, you will utilise a tree-based data structure. A collection of trees will be used to depict a set division. Each tree will represent a subset, with one node representing each subset element.
1.1
Getting Started - Create the SetPartition class. It should contain the following features: an inner class called Node, as mentioned before; an array of Node objects, one for each set element; and a function Object() { [native code] } called SetPartition (int numElements). The function Object() { [native code] } should set up the array and Nodes to reflect the partition of the set 0-1, numElements 1, where the subsets are 0-1, numElements 1, and numElements 1.
1.2 Finding roots - In your class, create a public int getRoot (int x) function that returns the value at the root of the tree containing x. (Note that the result of getRoot() won't be very interesting until you write merge(), which is described below, because each value will be in a subset containing only itself.)
1.3 Do they belong to the same subset? - Add a public boolean inSameSubset (int x, int y) function that checks if x and y will be in the same division subset.
Code evaluation - Create a main method that accomplishes the following tasks. 1. Creates a SetPartition with 1000 components, then calls merge(0,1), merge(1,2),..., merge(998,999) to get the tree's maximum node depth. 2. Creates a SetPartition with 1000 members, calls merge(998,999), merge(997,998), etc., and reports the tree's maximum node depth. 3. Generates 1000 SetPartitions with 1000 items each, performs 750 random merges on each, and provides the average maximum node depth of these trees. (The answer should be in the range of 61–63.
Step by step
Solved in 4 steps with 3 images