Create a class called Sample that supports the following two actions and has a function Object() { [native code] } that accepts a collection p[] of double values as an argument. Change(i, v) changes the value of p[i] to v and random() returns an index i with a chance of p[i]/T (where T is the total of the numbers in p[]). Use a full binary tree with inferred weights of p[i] at each node. The total weight of all the nodes in a subtree should be stored in each node. Choose a random integer between 0 and T to create a random index, and then use the accumulated weights to decide which branch of the subtree to investigate. Change each node's weight along the route from the base to i when updating p[i]. Avoid using direct references,
Create a class called Sample that supports the following two actions and has a function Object() { [native code] } that accepts a collection p[] of double values as an argument. Change(i, v) changes the value of p[i] to v and random() returns an index i with a chance of p[i]/T (where T is the total of the numbers in p[]). Use a full binary tree with inferred weights of p[i] at each node. The total weight of all the nodes in a subtree should be stored in each node. Choose a random integer between 0 and T to create a random index, and then use the accumulated weights to decide which branch of the subtree to investigate. Change each node's weight along the route from the base to i when updating p[i]. Avoid using direct references,
Step by step
Solved in 4 steps with 2 images