Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.ArrayList; import java.util.Collection; import java.util.List; public class BST implements Tree { private int height; private int size; private BinaryNode root; public BST(){ this.root =

import java.util.ArrayList; import java.util.Collection; import java.util.List; public class BST> implements Tree { private int height; private int size; private BinaryNode root; public BST(){ this.root = null; this.height = 0; this.size = 0; } // TODO: BST public BST(BinaryNode root){ } // Access field public BinaryNode root() { return this.root; } // Basic properties public int height() { return this.height; } public int size() { return this.size; } public boolean isBalanced() { return root.isBalanced(); } // TODO: updateHeight - Update the root height to reflect any changes public void updateHeight() { } // Traversals that return lists // TODO: Preorder traversal public List preOrderList() { return new ArrayList<>(); } // TODO: Inorder traversal public List inOrderList() { return new ArrayList<>(); } // TODO: Postorder traversal public List postOrderList() { return new ArrayList<>(); } // Helpers for BST/AVL methods // TODO: extractRightMost // This will be called on the left subtree and will get the maximum value. public BinaryNode extractRightMost(BinaryNode curNode) { return null; } // AVL & BST Search & insert same // TODO: search public BinaryNode search(E elem) { return null; } // TODO: insert public void insert(E elem) { } // TODO: delete public BinaryNode delete(E elem) { return null; } // Stuff to help you debug if you want // Can ignore or use to see if it works. static > Tree mkBST (Collection elems) { Tree result = new BST<>(); for (E e : elems) result.insert(e); return result; } public TreePrinter.PrintableNode getLeft() { return this.root.hasLeft() ? this.root.left() : null; } public TreePrinter.PrintableNode getRight() { return this.root.hasRight() ? this.root.right() : null; } public String getText() { return (this.root != null) ? this.root.getText() : ""; } } 

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

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions

Question

Solve the equation for x. |x + 3| = |2x + 1|

Answered: 1 week ago