Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We shall consider rooted (not necessarily binary) trees; for such a tree T we le

ID: 3676626 • Letter: W

Question

We shall consider rooted (not necessarily binary) trees; for such a tree T we let N(T) denote the number of nodes in T, and h(T) denote the height of T.Let Union be a function that as input takes two rooted trees U and V, and as output returns a tree T given as follows:
• if N(U) > N(V ) then T is like U except that its root has V as an extra child;

• otherwise, then T is like V except that its root has U as an extra child.

Consider a tree T that is formed (from one-element trees) by successive applications of Union. Prove that then h(T) log2(N(T)).

Explanation / Answer

******Try this code ******* public class Node { private List children = new ArrayList(); private Node parent = null; private T data = null; public Node(T data) { this.data = data; } public Node(T data, Node parent) { this.data = data; this.parent = parent; } public List getChildren() { return children; } public void setParent(Node parent) { parent.addChild(this); this.parent = parent; } public void addChild(T data) { Node child = new Node(data); child.setParent(this); this.children.add(child); } public void addChild(Node child) { child.setParent(this); this.children.add(child); } public T getData() { return this.data; } public void setData(T data) { this.data = data; } public boolean isRoot() { return (this.parent == null); } public boolean isLeaf() { if(this.children.size() == 0) return true; else return false; } public void removeParent() { this.parent = null; } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote