bob afro
bob afro

Reputation: 213

Constructor for this disjoint-set data structure?

We need to implement a class called DisjointSet.java that will be our data-structure for the program we are using. Here are the instructions for creating the data structure:

instructions

I understand most of the instructions and how to code it, but I am a little confused what a "list of Node objects" will look like in the constructor method? I made a inner Node class, and created a Node parent in the DisjointSet.java class, but I don't really know what he wants for the "list of Node objects".

Any ideas??

Upvotes: 1

Views: 266

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726489

I am a little confused what a "list of Node objects" will look like in the constructor method?

List of node objects does not need to be initialized in the constructor. It is an initially empty list of Node objects, so you would initialize it like this:

List<Node> nodeList = new ArrayList<>();

I would replace the list List<Node> with a Map<T,Node>, so that it is faster to find (i.e. O(1) instead of O(n) lookup time).

Upvotes: 1

Related Questions