/>
/>
/>
Coding Skills (Advanced)
Question Number 1
Given the following code snippet:
void InsertNode(tNode** node, int i){
if(*node == NULL){
*node = new tNode;
(*node)->pLeft = NULL;
(*node)->data = i;
(*node)->pRight = NULL;
SetRootNode(node);
return;
}
else{
if(i < (*node)->data)
InsertNode(&((*node)->pLeft), i);
if(i > (*node)->data)
InsertNode(&((*node)->pRight), i);
return;
}
}
void Func(tNode **node){
if(*node!=NULL){
Func(&(*node)->pLeft);
tNode *temp;
temp = (*node)->pLeft;
(*node)->pLeft= (*node)->pRight;
(*node)->pRight = temp;
Func(&(*node)->pRight);
}
}
void traverse(tNode** nd){
if(*nd!=NULL){
traverse(&((*nd)->pLeft));
traverse(&((*nd)->pRight));
std::cout<<(*nd)->data<
}
}
Let the input given be
98,15,100,10,78,120,5,12,96,110
What would be the output of the following code snippet?
int main(void)
{
tree *bT = new tree;
int i = 10;
int data;
while(i--){
/>
/>std::cout<<"Enter the node"<
std::cin>>data;
bT->InsertNode(bT->GetRootNode(), data);
}
bT->InsertNode(bT->GetRootNode(), 99);
bT->traverse(bT->GetRootNode());
}
110,5,12,96,78,15,99,110,120,
100,98
5,10,12,15,78,96,98,99,100,11
0,120
120,110,100,99,98,96,78,15,1
2,10,5
98,100,120,110,99,15,78,96,1
2,5,110
Question Number 2
Given the following code snippet:
void InsertNode(tNode** node, int i){
if(*node == NULL){
*node = new tNode;
(*node)->pLeft = NULL;
(*node)->data = i;
(*node)->pRight = NULL;
SetRootNode(node);
return;
}
else{
if(i < (*node)->data)
InsertNode(&((*node)->pLeft), i);
if(i > (*node)->data)
InsertNode(&((*node)->pRight), i);
return;
}
}
void Func(tNode **node){
if(*node!=NULL){
Func(&(*node)->pLeft);
tNode *temp;
temp = (*node)->pLeft;
(*node)->pLeft= (*node)->pRight;
(*node)->pRight = temp;
Func(&(*node)->pRight);
/>
/>}
}
void traverse(tNode** nd){
if(*nd!=NULL){
traverse(&((*nd)->pLeft));
traverse(&((*nd)->pRight));
std::cout<<(*nd)->data<
}
}
Let the input given be
98,15,100,10,78,120,5,12,96,110
What would be the output of the following code snippet?
int main(void)
{
tree *bT = new tree;
int i = 10;
int data;
while(i--){
std::cout<<"Enter the node"<
std::cin>>data;
bT->InsertNode(bT->GetRootNode(), data);
}
bT->Func(bT->GetRootNode());
bT->InsertNode(bT->GetRootNode(), 99);
bT->Func(bT->GetRootNode());
bT->traverse(bT->GetRootNode());
}
5,10,12,15,78,96,98,99,100,1
10,120
5,12,10,99,96,78,15,110,120,
100,98
5,10,12,15,78,96,99,98,100,1
10,120
98,100,120,110,15,78,96,99,
10,12,5
Question Number 3
Given the following code snippet:
/>
/>
void InsertNode(tNode**
node, int i){
if(*node == NULL){
*node = new tNode;
(*node)->pLeft =
NULL;
(*node)->data = i;
(*node)->pRight =
NULL;
SetRootNode(node);
return;
}
else{
if(i < (*node)>data)
InsertNode(&((*node)>pLeft), i);
if(i > (*node)>data)
InsertNode(&((*node)>pRight), i);
return;
}
}
void Func(tNode **node){
if(*node!=NULL){
Func(&(*node)>pLeft);
tNode *temp;
temp = (*node)>pLeft;
(*node)->pLeft=
(*node)->pRight;
(*node)->pRight =
temp;
Func(&(*node)>pRight);
}
}
void traverse(tNode** nd){
if(*nd!=NULL){
traverse(&((*nd)>pLeft));
traverse(&((*nd)>pRight));
std::cout<<(*nd)>data<
}
}
Let the input given be
/>
/>
98,15,100,10,78,120,5,12,96,110
What would be the output of the
following code snippet?
int main(void)
{
tree *bT = new tree;
int i = 10;
int data;
while(i--){
std::cout<<"Enter
the node"<
std::cin>>data;
bT->InsertNode(bT>GetRootNode(), data);
}
bT->Func(bT>GetRootNode());
bT->InsertNode(bT>GetRootNode(), 99);
bT->traverse(bT>GetRootNode());
}
100,110,120,98,5,10,12,15,7
8,96,99
99,96,78,15,12,10,5,98,120,1
10,100
110,120,100,5,12,10,99,96,7
8,15,98
98,15,78,96,99,10,12,5,100,1
20,110
Question Number 4
Given the following code snippet:
void InsertNode(tNode** node, int i){
if(*node == NULL){
*node = new tNode;
(*node)->pLeft = NULL;
(*node)->data = i;
/>
/>(*node)->pRight = NULL;
SetRootNode(node);
return;
}
else{
if(i < (*node)->data)
InsertNode(&((*node)->pLeft), i);
if(i > (*node)->data)
InsertNode(&((*node)->pRight), i);
return;
}
}
void Func(tNode **node){
if(*node!=NULL){
Func(&(*node)->pLeft);
tNode *temp;
temp = (*node)->pLeft;
(*node)->pLeft= (*node)->pRight;
(*node)->pRight = temp;
Func(&(*node)->pRight);
}
}
void traverse(tNode** nd){
if(*nd!=NULL){
traverse(&((*nd)->pLeft));
traverse(&((*nd)->pRight));
std::cout<<(*nd)->data<
}
}
Let the input given be
98,15,100,10,78,120,5,12,96,110
What would be the output of the following code snippet?
int main(void)
{
tree *bT = new tree;
int i = 10;
int data;
while(i--){
std::cout<<"Enter the node"<
std::cin>>data;
bT->InsertNode(bT->GetRootNode(), data);
}
bT->InsertNode(bT->GetRootNode(), 97);
bT->Func(bT->GetRootNode());
bT->InsertNode(bT->GetRootNode(), 99);
bT->traverse(bT->GetRootNode());
}
98,15,78,96,97,99,10,12,5,100,120,110
110,120,100,5,12,10,99,97,96,78,15,98
/>
/>
100,110,120,98,5,10,12,15,78,96,97,99
None of these
Question Number 5
The subject of these questions is an unusually simple kind of binary tree, defined by these
properties:
Terminal nodes contain a string.
Internal nodes have one or two children, called "left" and "right".
Either child of an internal node may be null, but not both.
Internal nodes contain no other information.
By "tree" we simply mean a node and all of its descendants.
A tree rooted at a node having left child A and right child B is a different tree than
one rooted at a node having left child B and right child A.
Here's an example, with plus signs (+) used to indicate internal nodes:
+
/ \
/
\
/
\
+
+
/
/ \
/
/
\
/
/
\
"A"
+
"D"
/ \
/
\
/
\
"B"
"C"
Suppose we want the classes to implement getLeft and getRight to allow external code to
navigate the tree. What should their return type be?
Object
Node
InternalNode
TerminalNode
/>
/>
Question Number 6
The subject of these questions is an unusually simple kind of binary tree, defined by these
properties:
Terminal nodes contain a string.
Internal nodes have one or two children, called "left" and "right".
Either child of an internal node may be null, but not both.
Internal nodes contain no other information.
By "tree" we simply mean a node and all of its descendants.
A tree rooted at a node having left child A and right child B is a different tree than
one rooted at a node having left child B and right child A.
Here's an example, with plus signs (+) used to indicate internal nodes:
+
/ \
/
\
/
\
+
+
/
/ \
/
/
\
/
/
\
"A"
+
"D"
/ \
/
\
/
\
"B"
"C"
Should InternalNode have simple “setters”, as follows?
void setLeft(Node nd) {
left = nd;
}
void setRight(Node nd) {
right = nd;
}
Yes
Optional—the specifications don’t imply either yes or no
No—the specifications directly forbid it
No—the specifications don’t say one way or another but these implementations are
inadequate
/>
/>
Question Number 7
The subject of these questions is an unusually simple kind of binary tree, defined by these
properties:
Terminal nodes contain a string.
Internal nodes have one or two children, called "left" and "right".
Either child of an internal node may be null, but not both.
Internal nodes contain no other information.
By "tree" we simply mean a node and all of its descendants.
A tree rooted at a node having left child A and right child B is a different tree than
one rooted at a node having left child B and right child A.
Here's an example, with plus signs (+) used to indicate internal nodes:
+
/ \
/
\
/
\
+
+
/
/ \
/
/
\
/
/
\
"A"
+
"D"
/ \
/
\
/
\
"B"
"C"
Consider this implementation of toString():
abstract class Node {
String toString();
}
class TerminalNode extends Node {
String toString() {
return value;
}
}
class InternalNode extends Node {
String toString() {
if (null == left)
return "[" + right + "]";
else if (null == right)
return "[" + left + "]";
else
return "[" + left + " " + right + "]";
}
}
/>
/>
Under what conditions will this implementation distinguish (i.e. produce different strings
for) two trees that have the same strings in the same sequence in their terminal nodes but
different internal structures?
Never
Only for “full” trees (ones in which every internal node has two children, except
possibly the parent of the rightmost terminal node)
Always
Question Number 8
Given the following code snippet answer the following question.
struct AVLTree
{
AVLTree * left;
AVLTree * right;
int element;
int height;
};
int MAX(int a, int b){
if(a>=b)
return a;
if(a
return b;
}
int height(AVLTree *node)
{
if (node == NULL)
{
return -1;
}
else
{
return node->height;
}
}
AVLTree * single_rotation_with_left(AVLTree *k2)
{
AVLTree *k1;
k1 = k2->left;
k2->left = k1->right;
k1->right = k2;
/>
/>k2->height = MAX(height(k2->left), height(k2->right)) + 1;
k1->height = MAX(height(k1->left), height(k2->right)) + 1;
return k1;
}
AVLTree * single_rotation_with_right(AVLTree *k2)
{
AVLTree *k1;
k1 = k2->right;
k2->right = k1->left;
k1->left = k2;
k2->height = MAX(height(k2->left), height(k2->right)) + 1;
k1->height = MAX(height(k1->right), height(k2->left)) + 1;
return k1;
}
AVLTree *double_rotation_with_left(AVLTree *k3)
{
k3->left = single_rotation_with_right(k3->left);
return single_rotation_with_left(k3);
}
AVLTree *double_rotation_with_right(AVLTree *k3)
{
k3->right = single_rotation_with_left(k3->right);
return single_rotation_with_right(k3);
}
void insert(int value, AVLTree **node)
{
if (*node == NULL)
{
*node = new AVLTree;
if (*node == NULL)
{
return;
}
(*node)->element = value;
(*node)->height = 0;
(*node)->left = (*node)->right = NULL;
return;
}
else if (value < (*node)->element)
{
insert(value, &((*node)->left));
if (height((*node)->left) - height((*node)->right) == 2)
{
if (value < (*node)->left->element)
{
*node = single_rotation_with_left(*node);
}
else
{
*node = double_rotation_with_left(*node);
}
}
}
else if (value > (*node)->element)
{
/>
/>insert(value, &((*node)->right));
if (height((*node)->right) - height((*node)->left) == 2)
{
if (value > (*node)->right->element)
{
*node = single_rotation_with_right(*node);
}
else
{
*node = double_rotation_with_right(*node);
}
}
}
(*node)->height = MAX(height((*node)->left), height((*node)->right)) +
1;
}
Consider an input sequence that is provided as an input to the insert method
20,5,15,9,13,2,6,12,14,15,16,17,18,19
How many times method single_rotation_with_left is called while inserting 18
1
0
2
None of these
Question Number 9
Given the following code snippet answer the following question.
struct AVLTree
{
AVLTree * left;
AVLTree * right;
int element;
int height;
};
int MAX(int a, int b){
if(a>=b)
return a;
if(a
return b;
}
/>
/>int height(AVLTree *node)
{
if (node == NULL)
{
return -1;
}
else
{
return node->height;
}
}
AVLTree * single_rotation_with_left(AVLTree *k2)
{
AVLTree *k1;
k1 = k2->left;
k2->left = k1->right;
k1->right = k2;
k2->height = MAX(height(k2->left), height(k2->right)) + 1;
k1->height = MAX(height(k1->left), height(k2->right)) + 1;
return k1;
}
AVLTree * single_rotation_with_right(AVLTree *k2)
{
AVLTree *k1;
k1 = k2->right;
k2->right = k1->left;
k1->left = k2;
k2->height = MAX(height(k2->left), height(k2->right)) + 1;
k1->height = MAX(height(k1->right), height(k2->left)) + 1;
return k1;
}
AVLTree *double_rotation_with_left(AVLTree *k3)
{
k3->left = single_rotation_with_right(k3->left);
return single_rotation_with_left(k3);
}
AVLTree *double_rotation_with_right(AVLTree *k3)
{
k3->right = single_rotation_with_left(k3->right);
return single_rotation_with_right(k3);
}
void insert(int value, AVLTree **node)
{
if (*node == NULL)
{
*node = new AVLTree;
if (*node == NULL)
{
return;
}
(*node)->element = value;
(*node)->height = 0;
(*node)->left = (*node)->right = NULL;
return;
}
/>
/>else if (value < (*node)->element)
{
insert(value, &((*node)->left));
if (height((*node)->left) - height((*node)->right) == 2)
{
if (value < (*node)->left->element)
{
*node = single_rotation_with_left(*node);
}
else
{
*node = double_rotation_with_left(*node);
}
}
}
else if (value > (*node)->element)
{
insert(value, &((*node)->right));
if (height((*node)->right) - height((*node)->left) == 2)
{
if (value > (*node)->right->element)
{
*node = single_rotation_with_right(*node);
}
else
{
*node = double_rotation_with_right(*node);
}
}
}
(*node)->height = MAX(height((*node)->left), height((*node)->right)) +
1;
}
Consider an input sequence that is provided as an input to the insert method
20,5,15,9,13,2,6,12,14,15,16,17,18,19
Which one of the following would be the root node after inserting 16.
16
17
15
9
/>
/>
Question Number 10
Given the following code snippet answer the following question.
struct AVLTree
{
AVLTree * left;
AVLTree * right;
int element;
int height;
};
int MAX(int a, int b){
if(a>=b)
return a;
if(a
return b;
}
int height(AVLTree *node)
{
if (node == NULL)
{
return -1;
}
else
{
return node->height;
}
}
AVLTree * single_rotation_with_left(AVLTree *k2)
{
AVLTree *k1;
k1 = k2->left;
k2->left = k1->right;
k1->right = k2;
k2->height = MAX(height(k2->left), height(k2->right)) + 1;
k1->height = MAX(height(k1->left), height(k2->right)) + 1;
return k1;
}
AVLTree * single_rotation_with_right(AVLTree *k2)
{
AVLTree *k1;
k1 = k2->right;
k2->right = k1->left;
k1->left = k2;
k2->height = MAX(height(k2->left), height(k2->right)) + 1;
k1->height = MAX(height(k1->right), height(k2->left)) + 1;
return k1;
}
AVLTree *double_rotation_with_left(AVLTree *k3)
{
k3->left = single_rotation_with_right(k3->left);
return single_rotation_with_left(k3);
}
AVLTree *double_rotation_with_right(AVLTree *k3)
/>
/>{
k3->right = single_rotation_with_left(k3->right);
return single_rotation_with_right(k3);
}
void insert(int value, AVLTree **node)
{
if (*node == NULL)
{
*node = new AVLTree;
if (*node == NULL)
{
return;
}
(*node)->element = value;
(*node)->height = 0;
(*node)->left = (*node)->right = NULL;
return;
}
else if (value < (*node)->element)
{
insert(value, &((*node)->left));
if (height((*node)->left) - height((*node)->right) == 2)
{
if (value < (*node)->left->element)
{
*node = single_rotation_with_left(*node);
}
else
{
*node = double_rotation_with_left(*node);
}
}
}
else if (value > (*node)->element)
{
insert(value, &((*node)->right));
if (height((*node)->right) - height((*node)->left) == 2)
{
if (value > (*node)->right->element)
{
*node = single_rotation_with_right(*node);
}
else
{
*node = double_rotation_with_right(*node);
}
}
}
(*node)->height = MAX(height((*node)->left), height((*node)->right)) +
1;
}
Consider an input sequence that is provided as an input to the insert method
20,5,15,9,13,2,6,12,14,15,16,17,18,19
/>
/>
In the process of inserting the above nodes how many times double_rotation_with_left is
being called?
5
0
3
2
Coding Skills (Advanced)
Question Number 1
The subject of these questions is an unusually simple kind of binary tree, defined by these
properties:
Terminal nodes contain a string.
Internal nodes have one or two children, called "left" and "right".
Either child of an internal node may be null, but not both.
Internal nodes contain no other information.
By "tree" we simply mean a node and all of its descendants.
A tree rooted at a node having left child A and right child B is a different tree than one
rooted at a node having left child B and right child A.
Here's an example, with plus signs (+) used to indicate internal nodes:
+
/ \
/
\
/
\
+
+
/
/ \
/
/
\
/
/
\
"A"
+
"D"
/ \
/
\
/
\
"B"
"C"
Which expression would create a representation of the following tree?
IN0
/ \
/
\
/
\
/>
/>IN1
IN2
/
/ \
/
/
\
/
/
\
"A"
"D"
IN3
/ \
/
\
/
\
"B"
"C"
InternalNode tree =
new InternalNode(
new InternalNode(new TerminalNode("A"),
null),
new InternalNode(new TerminalNode("D"),
new InternalNode(
new TerminalNode("B"),
new TerminalNode("C"))));
InternalNode tree =
new InternalNode(
new InternalNode(new TerminalNode("D"),
new InternalNode(
new TerminalNode("B"),
new TerminalNode("C"))),
new TerminalNode("A"))
InternalNode tree =
new InternalNode(
new InternalNode(new TerminalNode("A")),
new InternalNode(new TerminalNode("D"),
new InternalNode(
new TerminalNode("B"),
new TerminalNode("C"))));
InternalNode tree =
new InternalNode(
new InternalNode(new TerminalNode("A", null),
null),
new InternalNode(new TerminalNode("D", null),
new InternalNode(
new TerminalNode("B", null),
new TerminalNode("C", null))));
Question Number 2
The subject of these questions is an unusually simple kind of binary tree, defined by these
properties:
Terminal nodes contain a string.
Internal nodes have one or two children, called "left" and "right".
Either child of an internal node may be null, but not both.
Internal nodes contain no other information.
/>
/>
By "tree" we simply mean a node and all of its descendants.
A tree rooted at a node having left child A and right child B is a different tree than one
rooted at a node having left child B and right child A.
Here's an example, with plus signs (+) used to indicate internal nodes:
+
/ \
/
\
/
\
+
+
/
/ \
/
/
\
/
/
\
"A"
+
"D"
/ \
/
\
/
\
"B"
"C"
Having created a pathTo(String) method we’d like to have the reverse
operation, atPath(List). Here is a proposed implementation. (Note that it
returns a Node, not a String.)
abstract class Node {
abstract bool isTerminal();
abstract Node atPath(List lst);
}
class TerminalNode extends Node {
boolean isTerminal { return True; }
Node atPath(List lst) {
if (lst.isEmpty())
return this;
return null;
}
}
class InternalNode extends Node {
boolean isTerminal { return False; }
Node atPath(List lst) {
Node curnode = this;
InternalNode ind = null;
for (int n = 0; n < lst.size(); n++) {
if (curnode.isTerminal())
return null;
String dir = lst.get(n);
if (!dir.equals("L") && !dir.equals("R"))
return null;
ind = (InternalNode) curnode;
if (dir.equals("L"))
curnode = ind.getLeft();
else
curnode = ind.getRight();
}
/>
/>return curnode;
}
}
Which of the possible conditions does the code handle correctly?
A. An empty subtree is encountered before the end of the path.
B. The path leads to a TerminalNode.
C. The path leads to an InternalNode.
All of them.
A but neither B nor C.
A and B but not C
B and C but not A.
Question Number 3
The subject of these questions is an unusually simple kind of binary tree, defined by these
properties:
Terminal nodes contain a string.
Internal nodes have one or two children, called "left" and "right".
Either child of an internal node may be null, but not both.
Internal nodes contain no other information.
By "tree" we simply mean a node and all of its descendants.
A tree rooted at a node having left child A and right child B is a different tree than one
rooted at a node having left child B and right child A.
Here's an example, with plus signs (+) used to indicate internal nodes:
+
/ \
/
\
/
\
+
+
/
/ \
/
/
\
/>
/>/
"A"
/
\
+
"D"
/ \
/
\
/
\
"B"
"C"
We want to locate the first occurrence of a string in the tree and return a
“path” that shows how to navigate to it from the root. The path will be
represented as a list of strings, with “L” indicating that the left child
should be followed and “R” that the right child should be followed. The list
“L”, “R” would identify the right child of the left child of the root of the
tree.
Assume there is a List data structure available that provides
a constructor for creating an empty List
addLast(String) to add a string to the end of the list returning the
(modified) list so that, for example, a series of additions could be
chained—for example:
lst.addLast("a").addLast("b")
Similarly, addFirst(String) adds to the front of the list and returns
the modified list.
Given an abstract definition in Node:
abstract pathTo(String str);
and the definition in TerminalNode:
List pathTo(String str) {
if (value.equals(str))
return new List();
else
return null;
}
Which of the following definitions will work correctly to produce the path as
described above (or null if the string was not found in the tree)?
List pathTo(String str) {
List lst = null;
if ((left != null) && (null != (lst = left.pathTo(str))))
return lst.addFirst("L");
if ((right != null) && (null != (lst = right.pathTo(str))))
return lst.addFirst("R");
return null;
}
List pathTo(String str) {
List lst = null;
if (left != null)
return left.pathTo(str).addFirst("L");
if (right != null)
/>
/>return right.pathTo(str)).addFirst("R");
return null;
}
List pathTo(String str) {
List lst = new List();
if ((left != null) && (null != (lst = left.pathTo(str))))
return lst.addFirst("L");
if ((right != null) && (null != (lst = right.pathTo(str))))
return lst.addFirst("R");
return lst;
}
List pathTo(String str) {
List lst = null;
if ((left != null) && (null != (lst = left.pathTo(str))))
return lst.addLast("L");
if ((right != null) && (null != (lst = right.pathTo(str))))
return lst.addLast("R");
return null;
}
Question Number 4
The subject of these questions is an unusually simple kind of binary tree, defined by these
properties:
Terminal nodes contain a string.
Internal nodes have one or two children, called "left" and "right".
Either child of an internal node may be null, but not both.
Internal nodes contain no other information.
By "tree" we simply mean a node and all of its descendants.
A tree rooted at a node having left child A and right child B is a different tree than one
rooted at a node having left child B and right child A.
Here's an example, with plus signs (+) used to indicate internal nodes:
+
/ \
/
\
/
\
+
+
/
/ \
/
/
\
/
/
\
"A"
+
"D"
/ \
/
\
/
\
"B"
"C"
/>
/>
One problem with the proposed implementation of equals is that two nodes of different types
cannot be equal. In the following code which of TerminalNode.equals and
InternalNode.equals correct this problem assuming the argument to each method is not null?
(The relevant parts of the class definitions are included.)
abstract class Node {
abstract boolean isTerminal();
abstract boolean equals(Node);
}
class TerminalNode {
boolean isTerminal() {
return true;
}
boolean equals(Node nd) {
return
nd.isTerminal() && value.equals(nd.getValue());
}
}
class InternalNode {
boolean isTerminal() {
return false;
}
boolean equals(Node nd) {
return
!nd.isTerminal() &&
left.equals(nd.getLeft()) &&
right.equals(nd.getRight());
}
}
Neither TerminalNode nor InternalNode
TerminalNode but not InternalNode
InternalNode but not TerminalNode
Both TerminalNode and InternalNode
Question Number 5
The subject of these questions is an unusually simple kind of binary tree, defined by these
properties:
Terminal nodes contain a string.
Internal nodes have one or two children, called "left" and "right".
Either child of an internal node may be null, but not both.
Internal nodes contain no other information.
By "tree" we simply mean a node and all of its descendants.
/>
/>
A tree rooted at a node having left child A and right child B is a different tree than one
rooted at a node having left child B and right child A.
Here's an example, with plus signs (+) used to indicate internal nodes:
+
/ \
/
\
/
\
+
+
/
/ \
/
/
\
/
/
\
"A"
+
"D"
/ \
/
\
/
\
"B"
"C"
Here is a proposed implementation of equals for the tree structure:
abstract class Node {
abstract boolean equals(Node nd);
}
class TerminalNode {
boolean equals(Node nd) {
return value.equals(nd.getValue());
}
}
class InternalNode {
boolean equals(Node nd) {
return left.equals(nd.getLeft()) &&
right.equals(nd.getRight());
}
}
Which classes contain correctly implemented methods?
A. TerminalNode
B. InternalNode
Neither
A
B
/>