Binary Tree¶
| Spice | |
|---|---|
Node<T> struct¶
Node of a BinaryTree
Constructors¶
ctor¶
| Spice | |
|---|---|
Construct a binary tree node holding the given value and optional children
Parameters
| Name | Type | Description |
|---|---|---|
value |
const T& |
Value to store in the node |
childLeft |
heap Node<T>* |
Left child node, or nil if there is none (default: nil<heap Node<T>*>) |
childRight |
heap Node<T>* |
Right child node, or nil if there is none (default: nil<heap Node<T>*>) |
BinaryTree<T> struct¶
A binary tree is a data structure to fasten up search speeds. Binary trees (when balanced) can be searched in O(log n). Insert operations, on the other hand, are rather slow, because the tree might get re-balanced.
Time complexity:
Insert: O(n * m); n = inserted elements, m = moved elements
Delete: O(n * m); n = deleted elements, m = moved elements
Search: O(log n)
Methods¶
insert¶
| Spice | |
|---|---|
Insert a new value into the binary tree
Parameters
| Name | Type | Description |
|---|---|---|
value |
const T& |
The value to insert |
contains¶
| Spice | |
|---|---|
Search for a value in the binary tree
Parameters
| Name | Type | Description |
|---|---|---|
value |
const T& |
The value to search for |
Returns: bool — True if the value was found, false otherwise
delete¶
| Spice | |
|---|---|
Delete a value from the binary tree
Parameters
| Name | Type | Description |
|---|---|---|
value |
const T& |
The value to delete |