Skip to content

Here you will find the implementation and explanation of the following trees: Binary Tree, AVL Binary Tree, Red Black Tree, Splay Tree in C++

Notifications You must be signed in to change notification settings

zpnst/different-trees

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Implementation of various trees in C++

image

The following trees are implemented in this repository:

  1. Binary Tree
  2. AVL Binary Tree
  3. Red Black Tree
  4. Splay Tree

Each tree has its own characteristics, which I will not describe in detail, since countless Internet resources have done it for me.

How to draw a tree based on the output in the terminal

You need to use the level_order_print() function. But do not confuse it with the order_print() function, it outputs the elements of the tree in order(from smaller to larger).

image

Next, simply restore the tree according to the simplest rules of a binary tree(>= - to the right, < - to the left), abstracting from the type of tree.

Our example

In our example, we insert an array of numbers {100, 50, 150, 25, 55, 175, 125, 300, 1000}, and then we delete the values 150, 50 and 1000.

What will happen to a simple search tree after all the above actions: image

Navigation

To learn more about the implementation of each of the trees and their brief description, follow these paths (I recommend in this order):

trees/binary-tree
trees/avl-binary-tree
trees/red-black-tree
trees/splay-tree

Each folder will show the trees before and after deleting the items and briefly describe their properties

Assembling

From the root folder "different-trees" type the following commands:

cmake -S . -B build
make --build build
cd build/
./comparison

If you did everything right, then you will get this result:

image

About

Here you will find the implementation and explanation of the following trees: Binary Tree, AVL Binary Tree, Red Black Tree, Splay Tree in C++

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published