###Correctness:
Correctness:
One thing many BST's need to define is the behavior when an item already exists and you attempt to add it again. Usually this means that you will locate the position of the existing item and then do nothing; I personally recommend replacing it (more useful with generics; doesn't make sense with integers). In your case, I think you add it again - this is probably not what is desired.
###Performance:
Performance:
Like most simple BSTs, your class ends up being a limited linked list if the input data is already sorted. Consider learning about AVL or Red-Black trees to find a way to auto-balance your BST.
###Usefulness:
Usefulness:
Currently you only have methods to add to the structure but it doesn't have helpful methods like contains
or traverse
/visit
.
Consider moving your constructor CreateBinarySearchTree(int[] a)
to a more general add(int[] a)
; this would allow you to add an array of values at some other point besides construction (such as adding two arrays to the tree to use it as a way to identify unique values). Some people would also argue that such methods are inherently useless. I suggest evaluating if adding an array is more helpful than just iterating across the array in the calling code.
###Correctness:
One thing many BST's need to define is the behavior when an item already exists and you attempt to add it again. Usually this means that you will locate the position of the existing item and then do nothing; I personally recommend replacing it (more useful with generics; doesn't make sense with integers). In your case, I think you add it again - this is probably not what is desired.
###Performance:
Like most simple BSTs, your class ends up being a limited linked list if the input data is already sorted. Consider learning about AVL or Red-Black trees to find a way to auto-balance your BST.
###Usefulness:
Currently you only have methods to add to the structure but it doesn't have helpful methods like contains
or traverse
/visit
.
Consider moving your constructor CreateBinarySearchTree(int[] a)
to a more general add(int[] a)
; this would allow you to add an array of values at some other point besides construction (such as adding two arrays to the tree to use it as a way to identify unique values). Some people would also argue that such methods are inherently useless. I suggest evaluating if adding an array is more helpful than just iterating across the array in the calling code.
Correctness:
One thing many BST's need to define is the behavior when an item already exists and you attempt to add it again. Usually this means that you will locate the position of the existing item and then do nothing; I personally recommend replacing it (more useful with generics; doesn't make sense with integers). In your case, I think you add it again - this is probably not what is desired.
Performance:
Like most simple BSTs, your class ends up being a limited linked list if the input data is already sorted. Consider learning about AVL or Red-Black trees to find a way to auto-balance your BST.
Usefulness:
Currently you only have methods to add to the structure but it doesn't have helpful methods like contains
or traverse
/visit
.
Consider moving your constructor CreateBinarySearchTree(int[] a)
to a more general add(int[] a)
; this would allow you to add an array of values at some other point besides construction (such as adding two arrays to the tree to use it as a way to identify unique values). Some people would also argue that such methods are inherently useless. I suggest evaluating if adding an array is more helpful than just iterating across the array in the calling code.
###Correctness:
One thing many BST's need to define is the behavior when an item already exists and you attempt to add it again. Usually this means that you will locate the position of the existing item and then do nothing; I personally recommend replacing it (more useful with generics; doesn't make sense with integers). In your case, I think you add it again - this is probably not what is desired.
###Performance:
Like most simple BSTs, your class ends up being a limited linked list if the input data is already sorted. Consider learning about AVL or Red-Black trees to find a way to auto-balance your BST.
###Usefulness:
Currently you only have methods to add to the structure but it doesn't have helpful methods like contains
or traverse
/visit
.
Consider moving your constructor CreateBinarySearchTree(int[] a)
to a more general add(int[] a)
; this would allow you to add an array of values at some other point besides construction (such as adding two arrays to the tree to use it as a way to identify unique values). Some people would also argue that such methods are inherently useless. I suggest evaluating if adding an array is more helpful than just iterating across the array in the calling code.