Skip to the content.

BinaryTree

Binary Search Tree Stand With Ukraine

C# Binary search tree

This project contains a cross platform Binary Tree implementation

Build AppVeyor GitHub release NuGet package NuGet License contributions welcome

Code Coverage

Coverage Status

How to Install

You can directly install this library from Nuget. There is package:

BinaryTree

PM> Install-Package BinaryTree

How to use

Create a new instanse: var binaryTree = new BinaryTree<int>(); and add elements:

binaryTree.Add(8);
binaryTree.Add(5);
binaryTree.Add(12)

or use collection initializer like : var binaryTree = new BinaryTree<int>() { 8, 5, 12, 3, 7, 10, 15 };

Another way is constructs a BinaryTree, copying the contents of the given collection

IList<int> numbers = new List<int>();
var binaryTree = new BinaryTree<int>(numbers);

Also you can initialize a new instance of the BinaryTree class that is empty and has the specified initial capacity: var binaryTree = new BinaryTree<int>(10);

By default traversal is set to In-order

You can set the type of traversal in constructor var binaryTree = new BinaryTree<int>(new PostOrderTraversal<int>()); or use property TraversalStrategy:

var inOrder = new InOrderTraversal<int>();
var preOrder = new PreOrderTraversal<int>();
var postOrder = new PostOrderTraversal<int>();

binaryTree.TraversalStrategy = preOrder;

Available operations:

To display all elements of tree, use:

foreach (var item in binaryTree)
{
    Console.Write(item + " ");
}

or use extension method:

binaryTree.PrintToConsole();

or binaryTree.PrintAsTree();

      8
     /  \
    5    12
   / \   / \
  3   7 10  15

Operations complexity

Time Complexity Space Complexity
Avarage Worst Worst
Access Search Insertion Deletion Access Search Insertion Deletion
O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n) O(n) O(n) O(n) O(n)

Build

On Windows:

build.ps1

On Linux/Mac:

build.sh

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

License

This project is licensed under the MIT License - see the LICENSE.md file for details