SlideShare a Scribd company logo
// TO DO: add your implementation and JavaDocs.
public class ThreeTenKTree {
//K-ary tree with an array as internal storage.
//All nodes are stored in the array following level-order top-down
//and left-to-right within one level.
//Root at index 0.
//underlying array for k-ary tree storage
// -- you MUST use this for credit! Do NOT change the name or type
private E[] storage;
//hash table to help remember the index of each stored value
private ThreeTenHashTable indexMap;
//branching factor
private int branchK;
// ADD MORE PRIVATE MEMBERS HERE IF NEEDED!
@SuppressWarnings("unchecked")
public ThreeTenKTree(int length, int k) {
//initialize tree storage as an array of given length
// and branching factor as k.
//May assyme the given length ensures the storage for a perfect tree.
//For example, if k=2, length will be of 1, 3, 7, 15, 29, etc.
//If k=3, length will be of length 1, 4, 13, etc.
//May also assume k>=2.
//Also initialize the hash table with ThreeTenHashTable.defaultTableLength.
}
public int getBranch(){
//report branching factor
//O(1)
return -1; //default return, change or remove as needed
}
public int size() {
//report number of non-null nodes in tree
//O(1)
return -1; //default return, change or remove as needed
}
public int capacity(){
//report the length of storage
//this should be the no. of nodes of a perfect tree of the current height
//O(1)
return -1; //default return, change or remove as needed
}
public int height() {
//report the tree height
//O(1)
return -1; //default return, change or remove as needed
}
@SuppressWarnings("unchecked")
public boolean set(int index, E value) {
// Set value at index in tree storage.
// If value is null, this method attempts to remove a (leaf) node.
// - If index is not valid or the given index does not have a node,
// no change to tree and return false;
// - If node at given index has any child, do not remove and return false;
// - Otherwise, remove the node and return true.
// If value is not null, this method attempts to add/replace a node.
// - If value is already in tree (any index), no change and return false;
// - If value is new and index denotes a valid node of current tree, set value
// at this node and return true;
// - You may need to grow the tree storage (i.e. add a level) for this node
// - If adding this node would make the tree invalid, no change and return false.
// See examples in main() below for different cases.
// Remember to update the hash table if tree is updated.
return false; //default return, change or remove as needed
}
public E get(int index) {
//Return value at node index.
// - return null for invalid index or index with no node in tree
// O(1)
return null; //default return, change or remove as needed
}
public String toStringLevelOrder() {
//Return a string of all nodes (excluding null nodes) in tree storage:
// - include all levels from top down
// - all nodes are printed with a single space separated
// - return an empty string if tree is null
// Note: use StringBuilder instead of String concatenation
// Example:
// binary tree: A
// / 
// B C
// / /
// D E
//
// toStringLevelOrder() should return "A B C D E"
return ""; //default return, change or remove as needed
}
@Override
public String toString() {
//Return a string of all nodes (including null nodes) in tree storage:
// - include all levels from top down
// - each level is printed on its own line
// - each node in the level is printed with a single space separated
// - null nodes included in string
// - return an empty string if tree is null
// Note: use StringBuilder instead of String concatenation
// Example:
// binary tree: A
// / 
// B C
// / /
// D E
//
// toString() should return "AnB CnD null E null"
return ""; //default return, change or remove as needed
}
public String getAncestors(E value){
//Find the node of the given value and return the ancestors of the node in a string:
// - if value not present, return null
// - return string should include all ancestors including the node itself
// - ancestors should start from root and separated by "-->"
// O(height) assuming hash table search is O(1)
return ""; //default return, change or remove as needed
}
public String getChildren(E value){
//Find the node of the given value and return the children of the node in a string:
// - if value not present, return null
// - if the node is a leaf, return an empty string
// - return string should include all children, from left to right,
// and separated by a single space
// O(K) where K is the branch factor assuming hash table search is O(1)
return ""; //default return, change or remove as needed
}
public boolean has(E value){
//Determine if value is in tree or not
// - return true if a tree node has value; false otherwise
// - null is not a valid value in tree
// O(1) assuming hash table search is O(1)
return false; //default return, change or remove as needed
}
public boolean isLeaf(E value){
//Determine if value is in a leaf node of tree or not
// - return true if a leaf node has value; false otherwise
// O(K) where K is the branching factor assuming hash table search is O(1)
return false; //default return, change or remove as needed
}
public boolean remove(E value){
//Remove value from tree if value is in a leaf node
// - if value not present, return false
// - if value present but not in a leaf node, do not remove and return false
// - if value is in a leaf node, remove node from tree and return true
return false; //default return, change or remove as needed
}
public static FcnsTreeNode createFcnsTree(ThreeTenKTree ktree){
//construct the corresponding first-child-next-sibling tree
//for this k-ary tree and return the root node of the FCNS tree.
// Consider helper methods; consider a recursive approach.
// O(N) where N is the size of the current K-ary tree.
return null; //default return, change or remove as needed
}

More Related Content

DOCX
Once you have all the structures working as intended- it is time to co.docx
PDF
Add to BST.java a method height() that computes the height of the tr.pdf
PDF
I have a .java program that I need to modify so that it1) reads i.pdf
PDF
This is to test a balanced tree. I need help testing an unbalanced t.pdf
PDF
How to do the main method for this programBinaryNode.javapublic.pdf
PDF
A perfect left-sided binary tree is a binary tree where every intern.pdf
DOCX
Required to augment the authors Binary Search Tree (BST) code to .docx
PDF
On the code which has a class in which I implementing a binary tree .pdf
Once you have all the structures working as intended- it is time to co.docx
Add to BST.java a method height() that computes the height of the tr.pdf
I have a .java program that I need to modify so that it1) reads i.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdf
How to do the main method for this programBinaryNode.javapublic.pdf
A perfect left-sided binary tree is a binary tree where every intern.pdf
Required to augment the authors Binary Search Tree (BST) code to .docx
On the code which has a class in which I implementing a binary tree .pdf

Similar to TO DO add your implementation and JavaDocs.public class ThreeT.pdf (20)

PDF
(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf
PDF
Objective Binary Search Tree traversal (2 points)Use traversal.pp.pdf
PDF
Given the following codepackage data1;import java.util.;p.pdf
PDF
4. The size of instructions can be fixed or variable. What are advant.pdf
PPT
binary tree power point presentation for iT
PPT
Data structures algoritghm for binary tree method.ppt
PDF
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
DOCX
Table.java Huffman code frequency tableimport java.io.;im.docx
DOCX
Write a program that displays an AVL tree along with its balance fac.docx
PPTX
unit 4 for trees data structure notes it is
PDF
Create an implementation of a binary tree using the recursive appr.pdf
PDF
For the code below complete the preOrder() method so that it perform.pdf
PDF
usingpackage util;import java.util.;This class implements.pdf
DOCX
#include iostream using namespace std; const int nil = 0; cl.docx
PDF
Please read the comment ins codeExpressionTree.java-------------.pdf
PDF
Binary tree in java
DOCX
Decision tree handson
PDF
package DataStructures; public class HelloWorld AnyType extends.pdf
DOCX
Write a program that displays an AVL tree along with its balance fact.docx
PDF
in this assignment you are asked to write a simple driver program an.pdf
(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf
Objective Binary Search Tree traversal (2 points)Use traversal.pp.pdf
Given the following codepackage data1;import java.util.;p.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf
binary tree power point presentation for iT
Data structures algoritghm for binary tree method.ppt
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
Table.java Huffman code frequency tableimport java.io.;im.docx
Write a program that displays an AVL tree along with its balance fac.docx
unit 4 for trees data structure notes it is
Create an implementation of a binary tree using the recursive appr.pdf
For the code below complete the preOrder() method so that it perform.pdf
usingpackage util;import java.util.;This class implements.pdf
#include iostream using namespace std; const int nil = 0; cl.docx
Please read the comment ins codeExpressionTree.java-------------.pdf
Binary tree in java
Decision tree handson
package DataStructures; public class HelloWorld AnyType extends.pdf
Write a program that displays an AVL tree along with its balance fact.docx
in this assignment you are asked to write a simple driver program an.pdf

More from jkcs20004 (20)

PDF
Thi wiecis only eartaint pat a The seial wadar production emet=1 EEtr.pdf
PDF
This lab deals with the layers of the Earth, Endogenic and Exogenic s.pdf
PDF
This continuous probability distribution always has a =0 and =1 T.pdf
PDF
There is mountain with a popular hiking trail. At one point on the tr.pdf
PDF
There is a bacteria called C. difficile that is found in the large in.pdf
PDF
There is discussion among the board about our dividend strategy, alth.pdf
PDF
These transactions took place for Blossom Co. 2024 May 1 Recelved a $.pdf
PDF
This is a study case in all the photosthe SIPOC diagram bel.pdf
PDF
There are ten colour cards in a perfectly covered box, each in a diff.pdf
PDF
This is a pedigree for a family with a history of alkaptonuria, a rar.pdf
PDF
Topic - research and choose a company that has committed to BI. Descr.pdf
PDF
Tom collected an informal gender based data sample at his university..pdf
PDF
To which of the following facts is the anatomy of birds not s.pdf
PDF
Tobac Company reported an operating loss of $132,000 for financial re.pdf
PDF
to orpere 8- Ourrot Liablities and the Ziquidity Anabyis subtopic f.pdf
PDF
to sate that the previlenon of salmonela in the regions water difers.pdf
PDF
Theres no doubt that today we face many environmental problems poll.pdf
PDF
Therefore, converted to a z interval, we wish to find P(z0.61). Note .pdf
PDF
To map a newly discovered mutation that is proposed to contribute to .pdf
PDF
There is a relationship between tables T1 and T2, and the columns inv.pdf
Thi wiecis only eartaint pat a The seial wadar production emet=1 EEtr.pdf
This lab deals with the layers of the Earth, Endogenic and Exogenic s.pdf
This continuous probability distribution always has a =0 and =1 T.pdf
There is mountain with a popular hiking trail. At one point on the tr.pdf
There is a bacteria called C. difficile that is found in the large in.pdf
There is discussion among the board about our dividend strategy, alth.pdf
These transactions took place for Blossom Co. 2024 May 1 Recelved a $.pdf
This is a study case in all the photosthe SIPOC diagram bel.pdf
There are ten colour cards in a perfectly covered box, each in a diff.pdf
This is a pedigree for a family with a history of alkaptonuria, a rar.pdf
Topic - research and choose a company that has committed to BI. Descr.pdf
Tom collected an informal gender based data sample at his university..pdf
To which of the following facts is the anatomy of birds not s.pdf
Tobac Company reported an operating loss of $132,000 for financial re.pdf
to orpere 8- Ourrot Liablities and the Ziquidity Anabyis subtopic f.pdf
to sate that the previlenon of salmonela in the regions water difers.pdf
Theres no doubt that today we face many environmental problems poll.pdf
Therefore, converted to a z interval, we wish to find P(z0.61). Note .pdf
To map a newly discovered mutation that is proposed to contribute to .pdf
There is a relationship between tables T1 and T2, and the columns inv.pdf

Recently uploaded (20)

PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Institutional Correction lecture only . . .
PDF
Insiders guide to clinical Medicine.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
01-Introduction-to-Information-Management.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
GDM (1) (1).pptx small presentation for students
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Cell Structure & Organelles in detailed.
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Sports Quiz easy sports quiz sports quiz
Supply Chain Operations Speaking Notes -ICLT Program
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Institutional Correction lecture only . . .
Insiders guide to clinical Medicine.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
01-Introduction-to-Information-Management.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
GDM (1) (1).pptx small presentation for students
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Module 4: Burden of Disease Tutorial Slides S2 2025
Cell Structure & Organelles in detailed.
Final Presentation General Medicine 03-08-2024.pptx
human mycosis Human fungal infections are called human mycosis..pptx
Microbial disease of the cardiovascular and lymphatic systems
2.FourierTransform-ShortQuestionswithAnswers.pdf
Sports Quiz easy sports quiz sports quiz

TO DO add your implementation and JavaDocs.public class ThreeT.pdf

  • 1. // TO DO: add your implementation and JavaDocs. public class ThreeTenKTree { //K-ary tree with an array as internal storage. //All nodes are stored in the array following level-order top-down //and left-to-right within one level. //Root at index 0. //underlying array for k-ary tree storage // -- you MUST use this for credit! Do NOT change the name or type private E[] storage; //hash table to help remember the index of each stored value private ThreeTenHashTable indexMap; //branching factor private int branchK; // ADD MORE PRIVATE MEMBERS HERE IF NEEDED! @SuppressWarnings("unchecked") public ThreeTenKTree(int length, int k) { //initialize tree storage as an array of given length // and branching factor as k. //May assyme the given length ensures the storage for a perfect tree. //For example, if k=2, length will be of 1, 3, 7, 15, 29, etc. //If k=3, length will be of length 1, 4, 13, etc. //May also assume k>=2. //Also initialize the hash table with ThreeTenHashTable.defaultTableLength. } public int getBranch(){ //report branching factor //O(1) return -1; //default return, change or remove as needed }
  • 2. public int size() { //report number of non-null nodes in tree //O(1) return -1; //default return, change or remove as needed } public int capacity(){ //report the length of storage //this should be the no. of nodes of a perfect tree of the current height //O(1) return -1; //default return, change or remove as needed } public int height() { //report the tree height //O(1) return -1; //default return, change or remove as needed } @SuppressWarnings("unchecked") public boolean set(int index, E value) { // Set value at index in tree storage. // If value is null, this method attempts to remove a (leaf) node. // - If index is not valid or the given index does not have a node, // no change to tree and return false; // - If node at given index has any child, do not remove and return false; // - Otherwise, remove the node and return true. // If value is not null, this method attempts to add/replace a node. // - If value is already in tree (any index), no change and return false; // - If value is new and index denotes a valid node of current tree, set value // at this node and return true;
  • 3. // - You may need to grow the tree storage (i.e. add a level) for this node // - If adding this node would make the tree invalid, no change and return false. // See examples in main() below for different cases. // Remember to update the hash table if tree is updated. return false; //default return, change or remove as needed } public E get(int index) { //Return value at node index. // - return null for invalid index or index with no node in tree // O(1) return null; //default return, change or remove as needed } public String toStringLevelOrder() { //Return a string of all nodes (excluding null nodes) in tree storage: // - include all levels from top down // - all nodes are printed with a single space separated // - return an empty string if tree is null // Note: use StringBuilder instead of String concatenation // Example: // binary tree: A // / // B C // / / // D E // // toStringLevelOrder() should return "A B C D E" return ""; //default return, change or remove as needed }
  • 4. @Override public String toString() { //Return a string of all nodes (including null nodes) in tree storage: // - include all levels from top down // - each level is printed on its own line // - each node in the level is printed with a single space separated // - null nodes included in string // - return an empty string if tree is null // Note: use StringBuilder instead of String concatenation // Example: // binary tree: A // / // B C // / / // D E // // toString() should return "AnB CnD null E null" return ""; //default return, change or remove as needed } public String getAncestors(E value){ //Find the node of the given value and return the ancestors of the node in a string: // - if value not present, return null // - return string should include all ancestors including the node itself // - ancestors should start from root and separated by "-->" // O(height) assuming hash table search is O(1) return ""; //default return, change or remove as needed }
  • 5. public String getChildren(E value){ //Find the node of the given value and return the children of the node in a string: // - if value not present, return null // - if the node is a leaf, return an empty string // - return string should include all children, from left to right, // and separated by a single space // O(K) where K is the branch factor assuming hash table search is O(1) return ""; //default return, change or remove as needed } public boolean has(E value){ //Determine if value is in tree or not // - return true if a tree node has value; false otherwise // - null is not a valid value in tree // O(1) assuming hash table search is O(1) return false; //default return, change or remove as needed } public boolean isLeaf(E value){ //Determine if value is in a leaf node of tree or not // - return true if a leaf node has value; false otherwise // O(K) where K is the branching factor assuming hash table search is O(1) return false; //default return, change or remove as needed } public boolean remove(E value){ //Remove value from tree if value is in a leaf node // - if value not present, return false
  • 6. // - if value present but not in a leaf node, do not remove and return false // - if value is in a leaf node, remove node from tree and return true return false; //default return, change or remove as needed } public static FcnsTreeNode createFcnsTree(ThreeTenKTree ktree){ //construct the corresponding first-child-next-sibling tree //for this k-ary tree and return the root node of the FCNS tree. // Consider helper methods; consider a recursive approach. // O(N) where N is the size of the current K-ary tree. return null; //default return, change or remove as needed }