Question: I have a question here in java The subject is Ternary tree A tree that has three sons to the junction of a left-handed, middle-aged

I have a question here in java

The subject is Ternary tree

A tree that has three sons to the junction of a left-handed, middle-aged and right-handed son

I have two Node, Ternary classes here

(The Node class from France may need it)

The Ternary class has two static methods

Class Ternary

public class Ternary

{

private int _number;

private Ternary _leftSon, _middleSon, _rightSon;

public Ternary(int number) {

_number = number;

_leftSon = null;

_middleSon = null;

_rightSon = null;

}

public int getNumber() {return _number;}

public Ternary getLeftSon() {return _leftSon;}

public Ternary getMiddleSon() {return _middleSon;}

public Ternary getRightSon() {return _rightSon;}

public void setNumber(int number) {_number = number;}

public void setLeftSon(Ternary node) {_leftSon = node;}

public void setMiddleSon(Ternary node){_middleSon = node;}

public void setRightSon(Ternary node) {_rightSon = node;}

public static int what (Ternary t)

{

if (t == null)

return 0;

int temp = 0;

if (t.getLeftSon() != null) temp++;

if (t.getMiddleSon() != null) temp++;

if (t.getRightSon() != null) temp++;

return temp;

}

public static boolean something (Ternary t)

{

if (t == null)

return true;

if (what(t) == 3)

return false;

return something (t.getLeftSon())

&& something (t.getMiddleSon())

&& something (t.getRightSon());

}

}

Class Node

public class Node {

private int _value;

private Node _next;

public Node(int val, Node n) {

_value = val;

_next = n;

}

public Node(int val) {

_value = val;

_next = null;

}

public Node getNext() {

return _next;

}

public void setNext(Node node) {

_next = node;

}

public int getValue() {

return _value;

}

public void setValue(int val) {

_value = val;

}

public String toString() {

return ("" + _value);

}

}

This question has 4 parts and I have to choose the right answer

Please attach the tester and Output to me

There is the Ternary tree:

1 = root

Right son:

3 child of 1

6 child of 3

11, 12 children of 6

(12 right side of 6, 11 left side of 6)

Left son:

2 child of 1

4 child of 2

7 child of 4

son means:

5 child of 2 (5 right side of 2)

8, 9, 10 children of 5

(10 right side of 5, 9 in the middle of 5, 8 left side of 5)

14, 15, 16 children of 10

(16 right side of 10, 15 in the middle of 10, 14 left side of 10)

13 child of 8

part 1:

One correct answer must be chosen:

What does the what method do in general, given it a t junction of a ternary tree?

a. The method returns the maximum number of sons of a node in a tree rooted t.

b. The method receives a t node and returns the number of its offspring (including its direct sons)

c. The method receives a t node and returns the number of its offspring (excluding its direct sons)

d. The method receives a t junction and returns the number of its (direct) sons

e. There is no correct answer a-d

Please attach the tester and Output to me

part 2:

One correct answer must be chosen:

Given the ternary tree above that is rooted, what value will the method return to something following the call

BinaryTree.something (root)

a. 3

b. 1

c. true

d. false

Please attach the tester and Output to me

Part 3:

One correct answer must be chosen:

If we want the method something will not return this answer 10 6 5 2 1 3 4 9 8 7 PreOrder

What minimum changes should we make to the tree above (changes that will come with a minimum of nodes)

a. Nodes 9 and 15 should be deleted from the tree

b. Nodes 8 and 15 should be deleted from the tree

c. Junction 10 and its sons should be deleted from the tree

d. A node must be added as a son of node 6

God. There is no correct answer between a-d

Please attach the tester and Output to me

Part 4:

One correct answer must be chosen:

What does the something method do in general, given the t junction of a ternary tree?

a. The method checks the number of sons of each node in the rooted tree, and returns true if it is 3 and false if it is less than 3.

b. The method checks the number of sons of each node in the tree rooted t, and returns false if it is 3 and true if it is greater than 3.

c. The method checks if the t node is up and returns true if so, and false if not.

d. The method checks if the t node is the root of a binary tree and returns true if so, and false if not.

e. There is no correct answer between a-d

Please attach the tester and Output to me

Thank you!!!!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!