GithubHelp home page GithubHelp logo

anupam-io / avl_tree Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 130 KB

AVL tree: height-balanced trees in C supporting add, remove, search, update features. A comparison of AVL trees with red-black trees is also done(std::set).

C 82.47% C++ 10.36% Makefile 3.20% Python 3.97%
avl-tree avl-tree-implementations avl-tree-code c data-structures bst height-balanced-trees red-black-trees rotations std

avl_tree's Introduction

AVL Trees: perfectly balanced, as all things should be

Introduction

AVL trees(named after inventors Adelson-Velsky and Landis), also known as height-balanced trees are a widely-used data structure when it comes to efficient read, write and search operations.

Similar to a BST(binary search tree), an AVL tree also has basic operations:

  • add()
  • remove()
  • search()

But what makes an AVL tree efficient and fast

  • always height balanced
    • balance factor on any node is 0 or 1
  • always achieves minimum height

How is it perfect balanced

At the time of insertions and deletions:

  • it finds the first node where one side becomes more heavy than the other
  • fix this by RR, RL, LR, LL rotations
  • the whole tree is balanced

Comparision with RB trees

I have compared my implementation with the std::set(implemented with red-black trees) for different workloads. Here are the results:

comparison

How to use ?

  • defining an instance of avl tree:
    • tree* my_tree = new_tree();
  • adding an element:
    • add_t(my_tree, 77);
  • removing an element:
    • remove_t(my_tree, 67);
  • searching for an element:
    • find_t(my_tree, 57);
  • deleting the instance of tree:
    • delete_tree(my_tree);

Contributors

anupam
Anupam Kumar

avl_tree's People

Contributors

anupam-io avatar

Stargazers

 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.