SlideShare a Scribd company logo
1 of 5
Download to read offline
Java:
Create a java application using the code example in the following URL regarding a binary search
tree structure:
CODE EXAMPLE:
class BST_class {
//node class that defines BST node
class Node {
int key;
Node left, right;
public Node(int data){
key = data;
left = right = null;
}
}
// BST root node
Node root;
// Constructor for BST =>initial empty tree
BST_class(){
root = null;
}
//delete a node from BST
void deleteKey(int key) {
root = delete_Recursive(root, key);
}
//recursive delete function
Node delete_Recursive(Node root, int key) {
//tree is empty
if (root == null) return root;
//traverse the tree
if (key < root.key) //traverse left subtree
root.left = delete_Recursive(root.left, key);
else if (key > root.key) //traverse right subtree
root.right = delete_Recursive(root.right, key);
else {
// node contains only one child
if (root.left == null)
return root.right;
else if (root.right == null)
return root.left;
// node has two children;
//get inorder successor (min value in the right subtree)
root.key = minValue(root.right);
// Delete the inorder successor
root.right = delete_Recursive(root.right, root.key);
}
return root;
}
int minValue(Node root) {
//initially minval = root
int minval = root.key;
//find minval
while (root.left != null) {
minval = root.left.key;
root = root.left;
}
return minval;
}
// insert a node in BST
void insert(int key) {
root = insert_Recursive(root, key);
}
//recursive insert function
Node insert_Recursive(Node root, int key) {
//tree is empty
if (root == null) {
root = new Node(key);
return root;
}
//traverse the tree
if (key < root.key) //insert in the left subtree
root.left = insert_Recursive(root.left, key);
else if (key > root.key) //insert in the right subtree
root.right = insert_Recursive(root.right, key);
// return pointer
return root;
}
// method for inorder traversal of BST
void inorder() {
inorder_Recursive(root);
}
// recursively traverse the BST
void inorder_Recursive(Node root) {
if (root != null) {
inorder_Recursive(root.left);
System.out.print(root.key + " ");
inorder_Recursive(root.right);
}
}
boolean search(int key) {
root = search_Recursive(root, key);
if (root!= null)
return true;
else
return false;
}
//recursive insert function
Node search_Recursive(Node root, int key) {
// Base Cases: root is null or key is present at root
if (root==null || root.key==key)
return root;
// val is greater than root's key
if (root.key > key)
return search_Recursive(root.left, key);
// val is less than root's key
return search_Recursive(root.right, key);
}
}
class Main{
public static void main(String[] args) {
//create a BST object
BST_class bst = new BST_class();
/* BST tree example
45
/ 
10 90
/  /
7 12 50 */
//insert data into BST
bst.insert(45);
bst.insert(10);
bst.insert(7);
bst.insert(12);
bst.insert(90);
bst.insert(50);
//print the BST
System.out.println("The BST Created with input data(Left-root-right):");
bst.inorder();
//delete leaf node
System.out.println("nThe BST after Delete 12(leaf node):");
bst.deleteKey(12);
bst.inorder();
//delete the node with one child
System.out.println("nThe BST after Delete 90 (node with 1 child):");
bst.deleteKey(90);
bst.inorder();
//delete node with two children
System.out.println("nThe BST after Delete 45 (Node with two children):");
bst.deleteKey(45);
bst.inorder();
//search a key in the BST
boolean ret_val = bst.search (50);
System.out.println("nKey 50 found in BST:" + ret_val );
ret_val = bst.search (12);
System.out.println("nKey 12 found in BST:" + ret_val );
}
}

More Related Content

Similar to JavaCreate a java application using the code example in the follo.pdf

Objective Binary Search Tree traversal (2 points)Use traversal.pp.pdf
Objective Binary Search Tree traversal (2 points)Use traversal.pp.pdfObjective Binary Search Tree traversal (2 points)Use traversal.pp.pdf
Objective Binary Search Tree traversal (2 points)Use traversal.pp.pdfsivakumar19831
 
1)(JAVA) Extend the Binary Search Tree ADT to include a public metho.pdf
1)(JAVA) Extend the Binary Search Tree ADT to include a public metho.pdf1)(JAVA) Extend the Binary Search Tree ADT to include a public metho.pdf
1)(JAVA) Extend the Binary Search Tree ADT to include a public metho.pdfpetercoiffeur18
 
Help to implement delete_node get_succ get_pred walk and.pdf
Help to implement delete_node get_succ get_pred walk and.pdfHelp to implement delete_node get_succ get_pred walk and.pdf
Help to implement delete_node get_succ get_pred walk and.pdfcontact32
 
MAINCPP include ltiostreamgt include ltstringgt u.pdf
MAINCPP include ltiostreamgt include ltstringgt u.pdfMAINCPP include ltiostreamgt include ltstringgt u.pdf
MAINCPP include ltiostreamgt include ltstringgt u.pdfadityastores21
 
Tree Traversals A tree traversal is the process of visiting.pdf
Tree Traversals A tree traversal is the process of visiting.pdfTree Traversals A tree traversal is the process of visiting.pdf
Tree Traversals A tree traversal is the process of visiting.pdfajayadinathcomputers
 
To create a node for a binary search tree (BTNode, ) and to create a .pdf
To create a node for a binary search tree (BTNode, ) and to create a .pdfTo create a node for a binary search tree (BTNode, ) and to create a .pdf
To create a node for a binary search tree (BTNode, ) and to create a .pdfbhim1213
 
A perfect left-sided binary tree is a binary tree where every intern.pdf
A perfect left-sided binary tree is a binary tree where every intern.pdfA perfect left-sided binary tree is a binary tree where every intern.pdf
A perfect left-sided binary tree is a binary tree where every intern.pdfmichardsonkhaicarr37
 
Binary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structureBinary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structureZarghamullahShah
 
Im having trouble implementing a delete function for an AVL tree. .pdf
Im having trouble implementing a delete function for an AVL tree. .pdfIm having trouble implementing a delete function for an AVL tree. .pdf
Im having trouble implementing a delete function for an AVL tree. .pdfsktambifortune
 
There is BinarySearchTree class. When removing a node from a BST, we.pdf
There is BinarySearchTree class. When removing a node from a BST, we.pdfThere is BinarySearchTree class. When removing a node from a BST, we.pdf
There is BinarySearchTree class. When removing a node from a BST, we.pdfDhanrajsolanki2091
 
Complete code in Java The hashtable you'll be making will use String.pdf
Complete code in Java   The hashtable you'll be making will use String.pdfComplete code in Java   The hashtable you'll be making will use String.pdf
Complete code in Java The hashtable you'll be making will use String.pdfaarifi9988
 
Lecture 7-BinarySearchTrees.ppt
Lecture 7-BinarySearchTrees.pptLecture 7-BinarySearchTrees.ppt
Lecture 7-BinarySearchTrees.pptDrBashirMSaad
 
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfA)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfanton291
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfmichardsonkhaicarr37
 
I have a .java program that I need to modify so that it1) reads i.pdf
I have a .java program that I need to modify so that it1) reads i.pdfI have a .java program that I need to modify so that it1) reads i.pdf
I have a .java program that I need to modify so that it1) reads i.pdfallystraders
 
The hashtable youll be making will use Strings as the keys and Obje.pdf
The hashtable youll be making will use Strings as the keys and Obje.pdfThe hashtable youll be making will use Strings as the keys and Obje.pdf
The hashtable youll be making will use Strings as the keys and Obje.pdfvicky309441
 
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docxAvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docxrock73
 
Data Structures and Agorithm: DS 10 Binary Search Tree.pptx
Data Structures and Agorithm: DS 10 Binary Search Tree.pptxData Structures and Agorithm: DS 10 Binary Search Tree.pptx
Data Structures and Agorithm: DS 10 Binary Search Tree.pptxRashidFaridChishti
 
usingpackage util;import java.util.;This class implements.pdf
usingpackage util;import java.util.;This class implements.pdfusingpackage util;import java.util.;This class implements.pdf
usingpackage util;import java.util.;This class implements.pdfinfo335653
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Treesagar yadav
 

Similar to JavaCreate a java application using the code example in the follo.pdf (20)

Objective Binary Search Tree traversal (2 points)Use traversal.pp.pdf
Objective Binary Search Tree traversal (2 points)Use traversal.pp.pdfObjective Binary Search Tree traversal (2 points)Use traversal.pp.pdf
Objective Binary Search Tree traversal (2 points)Use traversal.pp.pdf
 
1)(JAVA) Extend the Binary Search Tree ADT to include a public metho.pdf
1)(JAVA) Extend the Binary Search Tree ADT to include a public metho.pdf1)(JAVA) Extend the Binary Search Tree ADT to include a public metho.pdf
1)(JAVA) Extend the Binary Search Tree ADT to include a public metho.pdf
 
Help to implement delete_node get_succ get_pred walk and.pdf
Help to implement delete_node get_succ get_pred walk and.pdfHelp to implement delete_node get_succ get_pred walk and.pdf
Help to implement delete_node get_succ get_pred walk and.pdf
 
MAINCPP include ltiostreamgt include ltstringgt u.pdf
MAINCPP include ltiostreamgt include ltstringgt u.pdfMAINCPP include ltiostreamgt include ltstringgt u.pdf
MAINCPP include ltiostreamgt include ltstringgt u.pdf
 
Tree Traversals A tree traversal is the process of visiting.pdf
Tree Traversals A tree traversal is the process of visiting.pdfTree Traversals A tree traversal is the process of visiting.pdf
Tree Traversals A tree traversal is the process of visiting.pdf
 
To create a node for a binary search tree (BTNode, ) and to create a .pdf
To create a node for a binary search tree (BTNode, ) and to create a .pdfTo create a node for a binary search tree (BTNode, ) and to create a .pdf
To create a node for a binary search tree (BTNode, ) and to create a .pdf
 
A perfect left-sided binary tree is a binary tree where every intern.pdf
A perfect left-sided binary tree is a binary tree where every intern.pdfA perfect left-sided binary tree is a binary tree where every intern.pdf
A perfect left-sided binary tree is a binary tree where every intern.pdf
 
Binary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structureBinary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structure
 
Im having trouble implementing a delete function for an AVL tree. .pdf
Im having trouble implementing a delete function for an AVL tree. .pdfIm having trouble implementing a delete function for an AVL tree. .pdf
Im having trouble implementing a delete function for an AVL tree. .pdf
 
There is BinarySearchTree class. When removing a node from a BST, we.pdf
There is BinarySearchTree class. When removing a node from a BST, we.pdfThere is BinarySearchTree class. When removing a node from a BST, we.pdf
There is BinarySearchTree class. When removing a node from a BST, we.pdf
 
Complete code in Java The hashtable you'll be making will use String.pdf
Complete code in Java   The hashtable you'll be making will use String.pdfComplete code in Java   The hashtable you'll be making will use String.pdf
Complete code in Java The hashtable you'll be making will use String.pdf
 
Lecture 7-BinarySearchTrees.ppt
Lecture 7-BinarySearchTrees.pptLecture 7-BinarySearchTrees.ppt
Lecture 7-BinarySearchTrees.ppt
 
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfA)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
I have a .java program that I need to modify so that it1) reads i.pdf
I have a .java program that I need to modify so that it1) reads i.pdfI have a .java program that I need to modify so that it1) reads i.pdf
I have a .java program that I need to modify so that it1) reads i.pdf
 
The hashtable youll be making will use Strings as the keys and Obje.pdf
The hashtable youll be making will use Strings as the keys and Obje.pdfThe hashtable youll be making will use Strings as the keys and Obje.pdf
The hashtable youll be making will use Strings as the keys and Obje.pdf
 
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docxAvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
 
Data Structures and Agorithm: DS 10 Binary Search Tree.pptx
Data Structures and Agorithm: DS 10 Binary Search Tree.pptxData Structures and Agorithm: DS 10 Binary Search Tree.pptx
Data Structures and Agorithm: DS 10 Binary Search Tree.pptx
 
usingpackage util;import java.util.;This class implements.pdf
usingpackage util;import java.util.;This class implements.pdfusingpackage util;import java.util.;This class implements.pdf
usingpackage util;import java.util.;This class implements.pdf
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 

More from ambersushil

Juan Williams is a writer with a best selling novel. Juan wishes to .pdf
Juan Williams is a writer with a best selling novel. Juan wishes to .pdfJuan Williams is a writer with a best selling novel. Juan wishes to .pdf
Juan Williams is a writer with a best selling novel. Juan wishes to .pdfambersushil
 
Juliets Delivery Services complet� las transacciones proporcionadas.pdf
Juliets Delivery Services complet� las transacciones proporcionadas.pdfJuliets Delivery Services complet� las transacciones proporcionadas.pdf
Juliets Delivery Services complet� las transacciones proporcionadas.pdfambersushil
 
Judge Mark Griffiths finds that Moodle is a relentless and predatory.pdf
Judge Mark Griffiths finds that Moodle is a relentless and predatory.pdfJudge Mark Griffiths finds that Moodle is a relentless and predatory.pdf
Judge Mark Griffiths finds that Moodle is a relentless and predatory.pdfambersushil
 
Jones, Inc. uses the equity method of accounting for its investment .pdf
Jones, Inc. uses the equity method of accounting for its investment .pdfJones, Inc. uses the equity method of accounting for its investment .pdf
Jones, Inc. uses the equity method of accounting for its investment .pdfambersushil
 
John y Sharon celebran un contrato de trabajo, que especifica que Jo.pdf
John y Sharon celebran un contrato de trabajo, que especifica que Jo.pdfJohn y Sharon celebran un contrato de trabajo, que especifica que Jo.pdf
John y Sharon celebran un contrato de trabajo, que especifica que Jo.pdfambersushil
 
John, Lesa y Trevor forman una sociedad de responsabilidad limitada..pdf
John, Lesa y Trevor forman una sociedad de responsabilidad limitada..pdfJohn, Lesa y Trevor forman una sociedad de responsabilidad limitada..pdf
John, Lesa y Trevor forman una sociedad de responsabilidad limitada..pdfambersushil
 
John has recently learned about advance directives in a healthcare l.pdf
John has recently learned about advance directives in a healthcare l.pdfJohn has recently learned about advance directives in a healthcare l.pdf
John has recently learned about advance directives in a healthcare l.pdfambersushil
 
Joe�s Ristorant� is a small restaurant near a college campus. It ser.pdf
Joe�s Ristorant� is a small restaurant near a college campus. It ser.pdfJoe�s Ristorant� is a small restaurant near a college campus. It ser.pdf
Joe�s Ristorant� is a small restaurant near a college campus. It ser.pdfambersushil
 
Johanna Murray, una activista clim�tica en The National Footprint Fo.pdf
Johanna Murray, una activista clim�tica en The National Footprint Fo.pdfJohanna Murray, una activista clim�tica en The National Footprint Fo.pdf
Johanna Murray, una activista clim�tica en The National Footprint Fo.pdfambersushil
 
Joannie est� en la categor�a impositiva del 15. Trabaja para una em.pdf
Joannie est� en la categor�a impositiva del 15. Trabaja para una em.pdfJoannie est� en la categor�a impositiva del 15. Trabaja para una em.pdf
Joannie est� en la categor�a impositiva del 15. Trabaja para una em.pdfambersushil
 
Joan accompanies her husband Dan to the clinic and reports to the nu.pdf
Joan accompanies her husband Dan to the clinic and reports to the nu.pdfJoan accompanies her husband Dan to the clinic and reports to the nu.pdf
Joan accompanies her husband Dan to the clinic and reports to the nu.pdfambersushil
 
Jim blindfolds Dwight and gives him a 4lb weight to hold. He then ta.pdf
Jim blindfolds Dwight and gives him a 4lb weight to hold. He then ta.pdfJim blindfolds Dwight and gives him a 4lb weight to hold. He then ta.pdf
Jim blindfolds Dwight and gives him a 4lb weight to hold. He then ta.pdfambersushil
 
Jill and Jim are married and they have 2 children (Josh and Kenny). .pdf
Jill and Jim are married and they have 2 children (Josh and Kenny). .pdfJill and Jim are married and they have 2 children (Josh and Kenny). .pdf
Jill and Jim are married and they have 2 children (Josh and Kenny). .pdfambersushil
 
Jet blue airways, con sede en Nueva York, hab�a comenzado 2007 en ra.pdf
Jet blue airways, con sede en Nueva York, hab�a comenzado 2007 en ra.pdfJet blue airways, con sede en Nueva York, hab�a comenzado 2007 en ra.pdf
Jet blue airways, con sede en Nueva York, hab�a comenzado 2007 en ra.pdfambersushil
 
Jerrold tiene una filosof�a con respecto a la retenci�n de empleados.pdf
Jerrold tiene una filosof�a con respecto a la retenci�n de empleados.pdfJerrold tiene una filosof�a con respecto a la retenci�n de empleados.pdf
Jerrold tiene una filosof�a con respecto a la retenci�n de empleados.pdfambersushil
 
Jes�s Mart�nez es un hombre hispano de 46 a�os de su unidad. Ingres�.pdf
Jes�s Mart�nez es un hombre hispano de 46 a�os de su unidad. Ingres�.pdfJes�s Mart�nez es un hombre hispano de 46 a�os de su unidad. Ingres�.pdf
Jes�s Mart�nez es un hombre hispano de 46 a�os de su unidad. Ingres�.pdfambersushil
 
Jeremiah Restoration Company completed the following selected transa.pdf
Jeremiah Restoration Company completed the following selected transa.pdfJeremiah Restoration Company completed the following selected transa.pdf
Jeremiah Restoration Company completed the following selected transa.pdfambersushil
 
Jeremy est� considerando usar mucho el color blanco en el logotipo p.pdf
Jeremy est� considerando usar mucho el color blanco en el logotipo p.pdfJeremy est� considerando usar mucho el color blanco en el logotipo p.pdf
Jeremy est� considerando usar mucho el color blanco en el logotipo p.pdfambersushil
 
JenkinsWe have two dozen APIs to deploy, and the dev team was able.pdf
JenkinsWe have two dozen APIs to deploy, and the dev team was able.pdfJenkinsWe have two dozen APIs to deploy, and the dev team was able.pdf
JenkinsWe have two dozen APIs to deploy, and the dev team was able.pdfambersushil
 
Jefferson Tutoring had the following payroll information on February.pdf
Jefferson Tutoring had the following payroll information on February.pdfJefferson Tutoring had the following payroll information on February.pdf
Jefferson Tutoring had the following payroll information on February.pdfambersushil
 

More from ambersushil (20)

Juan Williams is a writer with a best selling novel. Juan wishes to .pdf
Juan Williams is a writer with a best selling novel. Juan wishes to .pdfJuan Williams is a writer with a best selling novel. Juan wishes to .pdf
Juan Williams is a writer with a best selling novel. Juan wishes to .pdf
 
Juliets Delivery Services complet� las transacciones proporcionadas.pdf
Juliets Delivery Services complet� las transacciones proporcionadas.pdfJuliets Delivery Services complet� las transacciones proporcionadas.pdf
Juliets Delivery Services complet� las transacciones proporcionadas.pdf
 
Judge Mark Griffiths finds that Moodle is a relentless and predatory.pdf
Judge Mark Griffiths finds that Moodle is a relentless and predatory.pdfJudge Mark Griffiths finds that Moodle is a relentless and predatory.pdf
Judge Mark Griffiths finds that Moodle is a relentless and predatory.pdf
 
Jones, Inc. uses the equity method of accounting for its investment .pdf
Jones, Inc. uses the equity method of accounting for its investment .pdfJones, Inc. uses the equity method of accounting for its investment .pdf
Jones, Inc. uses the equity method of accounting for its investment .pdf
 
John y Sharon celebran un contrato de trabajo, que especifica que Jo.pdf
John y Sharon celebran un contrato de trabajo, que especifica que Jo.pdfJohn y Sharon celebran un contrato de trabajo, que especifica que Jo.pdf
John y Sharon celebran un contrato de trabajo, que especifica que Jo.pdf
 
John, Lesa y Trevor forman una sociedad de responsabilidad limitada..pdf
John, Lesa y Trevor forman una sociedad de responsabilidad limitada..pdfJohn, Lesa y Trevor forman una sociedad de responsabilidad limitada..pdf
John, Lesa y Trevor forman una sociedad de responsabilidad limitada..pdf
 
John has recently learned about advance directives in a healthcare l.pdf
John has recently learned about advance directives in a healthcare l.pdfJohn has recently learned about advance directives in a healthcare l.pdf
John has recently learned about advance directives in a healthcare l.pdf
 
Joe�s Ristorant� is a small restaurant near a college campus. It ser.pdf
Joe�s Ristorant� is a small restaurant near a college campus. It ser.pdfJoe�s Ristorant� is a small restaurant near a college campus. It ser.pdf
Joe�s Ristorant� is a small restaurant near a college campus. It ser.pdf
 
Johanna Murray, una activista clim�tica en The National Footprint Fo.pdf
Johanna Murray, una activista clim�tica en The National Footprint Fo.pdfJohanna Murray, una activista clim�tica en The National Footprint Fo.pdf
Johanna Murray, una activista clim�tica en The National Footprint Fo.pdf
 
Joannie est� en la categor�a impositiva del 15. Trabaja para una em.pdf
Joannie est� en la categor�a impositiva del 15. Trabaja para una em.pdfJoannie est� en la categor�a impositiva del 15. Trabaja para una em.pdf
Joannie est� en la categor�a impositiva del 15. Trabaja para una em.pdf
 
Joan accompanies her husband Dan to the clinic and reports to the nu.pdf
Joan accompanies her husband Dan to the clinic and reports to the nu.pdfJoan accompanies her husband Dan to the clinic and reports to the nu.pdf
Joan accompanies her husband Dan to the clinic and reports to the nu.pdf
 
Jim blindfolds Dwight and gives him a 4lb weight to hold. He then ta.pdf
Jim blindfolds Dwight and gives him a 4lb weight to hold. He then ta.pdfJim blindfolds Dwight and gives him a 4lb weight to hold. He then ta.pdf
Jim blindfolds Dwight and gives him a 4lb weight to hold. He then ta.pdf
 
Jill and Jim are married and they have 2 children (Josh and Kenny). .pdf
Jill and Jim are married and they have 2 children (Josh and Kenny). .pdfJill and Jim are married and they have 2 children (Josh and Kenny). .pdf
Jill and Jim are married and they have 2 children (Josh and Kenny). .pdf
 
Jet blue airways, con sede en Nueva York, hab�a comenzado 2007 en ra.pdf
Jet blue airways, con sede en Nueva York, hab�a comenzado 2007 en ra.pdfJet blue airways, con sede en Nueva York, hab�a comenzado 2007 en ra.pdf
Jet blue airways, con sede en Nueva York, hab�a comenzado 2007 en ra.pdf
 
Jerrold tiene una filosof�a con respecto a la retenci�n de empleados.pdf
Jerrold tiene una filosof�a con respecto a la retenci�n de empleados.pdfJerrold tiene una filosof�a con respecto a la retenci�n de empleados.pdf
Jerrold tiene una filosof�a con respecto a la retenci�n de empleados.pdf
 
Jes�s Mart�nez es un hombre hispano de 46 a�os de su unidad. Ingres�.pdf
Jes�s Mart�nez es un hombre hispano de 46 a�os de su unidad. Ingres�.pdfJes�s Mart�nez es un hombre hispano de 46 a�os de su unidad. Ingres�.pdf
Jes�s Mart�nez es un hombre hispano de 46 a�os de su unidad. Ingres�.pdf
 
Jeremiah Restoration Company completed the following selected transa.pdf
Jeremiah Restoration Company completed the following selected transa.pdfJeremiah Restoration Company completed the following selected transa.pdf
Jeremiah Restoration Company completed the following selected transa.pdf
 
Jeremy est� considerando usar mucho el color blanco en el logotipo p.pdf
Jeremy est� considerando usar mucho el color blanco en el logotipo p.pdfJeremy est� considerando usar mucho el color blanco en el logotipo p.pdf
Jeremy est� considerando usar mucho el color blanco en el logotipo p.pdf
 
JenkinsWe have two dozen APIs to deploy, and the dev team was able.pdf
JenkinsWe have two dozen APIs to deploy, and the dev team was able.pdfJenkinsWe have two dozen APIs to deploy, and the dev team was able.pdf
JenkinsWe have two dozen APIs to deploy, and the dev team was able.pdf
 
Jefferson Tutoring had the following payroll information on February.pdf
Jefferson Tutoring had the following payroll information on February.pdfJefferson Tutoring had the following payroll information on February.pdf
Jefferson Tutoring had the following payroll information on February.pdf
 

Recently uploaded

DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptxVishal Singh
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxMohamed Rizk Khodair
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 

Recently uploaded (20)

DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 

JavaCreate a java application using the code example in the follo.pdf

  • 1. Java: Create a java application using the code example in the following URL regarding a binary search tree structure: CODE EXAMPLE: class BST_class { //node class that defines BST node class Node { int key; Node left, right; public Node(int data){ key = data; left = right = null; } } // BST root node Node root; // Constructor for BST =>initial empty tree BST_class(){ root = null; } //delete a node from BST void deleteKey(int key) { root = delete_Recursive(root, key); } //recursive delete function Node delete_Recursive(Node root, int key) { //tree is empty if (root == null) return root; //traverse the tree if (key < root.key) //traverse left subtree root.left = delete_Recursive(root.left, key);
  • 2. else if (key > root.key) //traverse right subtree root.right = delete_Recursive(root.right, key); else { // node contains only one child if (root.left == null) return root.right; else if (root.right == null) return root.left; // node has two children; //get inorder successor (min value in the right subtree) root.key = minValue(root.right); // Delete the inorder successor root.right = delete_Recursive(root.right, root.key); } return root; } int minValue(Node root) { //initially minval = root int minval = root.key; //find minval while (root.left != null) { minval = root.left.key; root = root.left; } return minval; } // insert a node in BST void insert(int key) { root = insert_Recursive(root, key); } //recursive insert function
  • 3. Node insert_Recursive(Node root, int key) { //tree is empty if (root == null) { root = new Node(key); return root; } //traverse the tree if (key < root.key) //insert in the left subtree root.left = insert_Recursive(root.left, key); else if (key > root.key) //insert in the right subtree root.right = insert_Recursive(root.right, key); // return pointer return root; } // method for inorder traversal of BST void inorder() { inorder_Recursive(root); } // recursively traverse the BST void inorder_Recursive(Node root) { if (root != null) { inorder_Recursive(root.left); System.out.print(root.key + " "); inorder_Recursive(root.right); } } boolean search(int key) { root = search_Recursive(root, key); if (root!= null) return true; else return false; }
  • 4. //recursive insert function Node search_Recursive(Node root, int key) { // Base Cases: root is null or key is present at root if (root==null || root.key==key) return root; // val is greater than root's key if (root.key > key) return search_Recursive(root.left, key); // val is less than root's key return search_Recursive(root.right, key); } } class Main{ public static void main(String[] args) { //create a BST object BST_class bst = new BST_class(); /* BST tree example 45 / 10 90 / / 7 12 50 */ //insert data into BST bst.insert(45); bst.insert(10); bst.insert(7); bst.insert(12); bst.insert(90); bst.insert(50); //print the BST System.out.println("The BST Created with input data(Left-root-right):"); bst.inorder(); //delete leaf node System.out.println("nThe BST after Delete 12(leaf node):");
  • 5. bst.deleteKey(12); bst.inorder(); //delete the node with one child System.out.println("nThe BST after Delete 90 (node with 1 child):"); bst.deleteKey(90); bst.inorder(); //delete node with two children System.out.println("nThe BST after Delete 45 (Node with two children):"); bst.deleteKey(45); bst.inorder(); //search a key in the BST boolean ret_val = bst.search (50); System.out.println("nKey 50 found in BST:" + ret_val ); ret_val = bst.search (12); System.out.println("nKey 12 found in BST:" + ret_val ); } }