Code Monkey home page Code Monkey logo

khaledashrafh / avl-tree Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 0.0 192 KB

This is a C++ implementation of an AVL tree, which is a self-balancing binary search tree. An AVL tree maintains the balance factor of each node, which is the difference between the heights of its left and right subtrees. Whenever a node becomes unbalanced (its balance factor is either -2 or 2), the tree performs a rotation to restore the balance.

License: MIT License

CMake 1.13% C++ 98.87%
avl-tree balanced-binary-search-trees cpp scratch-implementation tree-traversal avl-tree-implementation avl-tree-implementations

avl-tree's Introduction

C++ AVL Tree Implementation

This is a C++ implementation of an AVL tree, which is a self-balancing binary search tree. An AVL tree maintains the balance factor of each node, which is the difference between the heights of its left and right subtrees. Whenever a node becomes unbalanced (its balance factor is either -2 or 2), the tree performs a rotation to restore the balance.

Features

This project provides the following features:

  • Insertion: You can insert a new node with a given key and value into the AVL tree. The tree will automatically balance itself after the insertion.
  • Deletion: You can delete an existing node with a given key from the AVL tree. The tree will automatically balance itself after the deletion.
  • Search: You can search for a node with a given key in the AVL tree. The tree will return the value of the node if it exists, or null otherwise.
  • Traversal: You can traverse the AVL tree in different orders, such as pre-order, in-order, post-order, or level-order. The tree will print the keys and values of each node during the traversal.
  • Display: You can display the AVL tree in a graphical way, using parentheses to indicate the structure of the tree and the balance factors of each node.

Usage

This project contains one file: main.cpp, which includes all the code and test cases for the AVL tree implementation. To compile and run the project, you can use the following commands:

g++ main.cpp -o avl_tree
./avl_tree

The output will show the results of each test case, such as the insertion, deletion, search, traversal, and display operations on the AVL tree.

License

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

avl-tree's People

Contributors

khaledashrafh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.