Skip to content

Generic Binary Search Tree (BST) with possible repeated values

Notifications You must be signed in to change notification settings

Gilcemir/BinarySearchTree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BINARY SEARCH TREE (BST)

Simple implementation of a generic Binary Search Tree, which accepts repeated values.

Definition


A binary Search Tree (BST) is a variant of a Binary Tree, which satisfies the following properties:

  • The value in each node must be greater than (in our case strictly) any values stored in its left subtree;
  • The value in each node must be less than (strictly) any values in its right subtree;

Remarks


  • Since a Binary Search Tree has comparison between values, this implementation only accepts objects T where T implements the Interface IComparable and IEquatable.
  • This BST accepts repeated values. It means that for every value T repeated in the tree, the TreeNode itself will store the number of occurrencies of the value T.

Constructors


BinarySearchTree()

Initializes an empty BST.

BinarySearchTree(T)

Initializes a Tree with one element T.

BinarySearchTree(T[])

Initializes a Tree containing every element of an array of T.

BinarySearchTree(IList<T>)

Initializes a Tree containing every element of a collection that implements the Interface IList<T>.

Properties


This Binary Search Tree does not have any public property.

Methods


Length()

Return the number of nodes in the BST.

Parameters

This Method takes no argument.

Returns

int

Number of nodes in the BST

Height()

Return the Height of the BST.

Parameters

This Method takes no argument.

Returns

int

Return the height of the BST

Search(T)

Check if element T is present in the BST.

Parameters

T

Element **T** to be searched.

Returns

bool

Return if either the element T is present in the BST or not.

Insert(T)

Insert element T in the BST.

Parameters

T

Element **T** to be inserted.

Returns

bool

Return true if element is inserted in the BST.

Delete(T)

Deletes an instance of T in the BST.

Parameters

T

Element **T** to be inserted.

Returns

bool

Return true if element is deleted in the BST.

ToList()

Return an ordered List\<T> of the elements present in the BST.

Parameters

Takes no argument.

Returns

List<T> Return an ordered List<T> of the elements present in the BST;


Print()

Prints in the Console the BST by level.

Parameters

Takes no argument.

Returns

This method has no return;

About

Generic Binary Search Tree (BST) with possible repeated values

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages