Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Consider the following code segment from the implementation of the binary search tree: import ch05.queues.*; import ch03.stacks.*; importsupport.BSTNode; public class BinarySearchTree implementsBSTInterface { protectedBSTNode

1. Consider the following code segment from the implementation of the binary search tree:

import ch05.queues.*;

import ch03.stacks.*;

importsupport.BSTNode;

public class BinarySearchTree>

implementsBSTInterface

{

protectedBSTNode root; // reference to the root of this BST

boolean found; // used by remove

// for traversals

protectedLinkedUnbndQueueinOrderQueue; // queue of info

protectedLinkedUnbndQueuepreOrderQueue; // queue of info

protectedLinkedUnbndQueuepostOrderQueue; // queue of info

publicBinarySearchTree()

// Creates an empty BST object.

{

root = null;

}

publicbooleanisEmpty()

// Returns true if this BST is empty; otherwise, returns false.

{

return (root == null);

}

privateintrecSize(BSTNode tree)

// Returns the number of elements in tree.

{

if (tree == null)

return 0;

else

returnrecSize(tree.getLeft()) + recSize(tree.getRight()) + 1;

}

publicint size()

// Returns the number of elements in this BST.

{

returnrecSize(root);

}}//End of code segment

Add a method to the class to calculate number of leafs in a tree.

2. To implement a simple directed graph, write two Java classes: nodes and edges. Nodes must have an ID number (integer) a name (String) and a simple constructor. Edges must have an ID number (integer), label (String), a source node (reference to a node) and a target node (reference to node).

3. Consider the Array representation of a binary search tree. Write a java method that receives the index of a node and returns the index of the parent.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

What is topology? Explain with examples

Answered: 1 week ago