Given a tree design an algorithm that returns a list of lists. The sublist at index i should contain all the nodes at depth i. [Java], use this template for the rooted tree. import java.util.*; public...

Given a tree design an algorithm that returns a list of lists. The sublist at index i should contain all the nodes at depth i. [Java], use this template for the rooted tree. import java.util.*; public class RTree { public static class rootedTree { int element; ArrayList child = new ArrayList<>(); rootedTree parent; static int depth = 0; public rootedTree(rootedTree parent) { this.parent = parent; } public void setElement(int element) { this.element = element; } public int getElement() { return element; } public rootedTree getParent() { return parent; } public ArrayList getChild() { return child; } } public static rootedTree addChild(rootedTree parent, int element) { rootedTree branch = new rootedTree(parent); branch.setElement(element); parent.getChild().add(branch); return branch; } }

Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here