Trees: Difference between revisions

Jump to navigation Jump to search
62 bytes added ,  13 May 2023
(Created page with "== Introduction == A '''tree''' is a hierarchical data structure that consists of nodes connected by edges. It is a non-linear data structure with a unique root node, and each node in the tree can have zero or more child nodes. The tree data structure is commonly used for representing hierarchies and searching efficiently in databases, file systems, and more. == Terminology == Here are some common terms used in the context of trees: * '''Node''': A basic unit in a tree...")
 
 
Line 79: Line 79:


int main() {
int main() {
BinaryTree tree;
    BinaryTree tree;
tree.insert(5);
    tree.insert(5);
tree.insert(3);
    tree.insert(3);
tree.insert(7);
    tree.insert(7);
tree.insert(2);
    tree.insert(2);
tree.insert(4);
    tree.insert(4);
tree.insert(6);
    tree.insert(6);
tree.insert(8);
    tree.insert(8);


// The tree now looks like this:
    // The tree now looks like this:
//      5
    //      5
//      / \
    //      / \
//    3  7
    //    3  7
//    / \ / \
    //    / \ / \
//  2  4 6  8
    //  2  4 6  8


return 0;
    return 0;
}


</pre>
</pre>

Navigation menu