Coder Social home page Coder Social logo

shaikhanas1993 / leftrb Goto Github PK

View Code? Open in Web Editor NEW

This project forked from arshadansari27/leftrb

0.0 2.0 0.0 233 KB

Leftrb is a Left-Leaning Red-Black (LLRB) implementation of 2–3 balanced binary search trees in Python. Port of the code presented by Robert Sedgewick in his paper.

License: GNU Lesser General Public License v3.0

leftrb's Introduction

Leftrb/LLRB

Leftrb is a Left-Leaning Red-Black (LLRB) implementation of 2–3 balanced binary search trees in Python.

This is a straightforward port of the Java code presented by Robert Sedgewick in [his paper]((http://www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf) and in the book Algorithms, 4th Edition, which is written by Robert Sedgewick and Kevin Wayne. By their permission, the original GPL v3 licensed Java code is licensed as LGPL v3, and ported to Python.

Overview

A balanced binary search tree (BBST) maintains elements in sorted order under dynamic updates (inserts and deletes) and can support various order-specific queries.

Red-black trees are the de facto standard BBST algorithms, and are the underlying data structure for symbol-table implementations within C++, Java, Python, BSD Unix, Linux and many other modern systems.

All red–black trees are based on implementing 2-3 or 2-3-4 trees within a binary tree, using red links to bind together internal nodes into 3-nodes or 4-nodes. Search, insert and delete operations are O(log n) and space requirements are O(n).

However, many traditional implementations have lots of repetitive code on the symmetric branches of rotation and deletion operations. So they are not easy to reason about and augment with other properties, which is what BBST's are often used for: They are used to implement other common data structures like Priority Queues and Interval Trees.

The LLRB method of implementing 2-3 trees is a recent improvement over the traditional implementation — it maintains an additional invariant that all red links must lean left except during inserts and deletes. Because of this, they can be implemented by adding just a few lines of code to standard BST algorithms.

The LLRB tree is based on combining three ideas:

  • Use a recursive implementation.
  • Require that all 3-nodes lean left.
  • Perform rotations on the way up the tree (after the recursive calls).

The LLRB approach was discovered relatively recently (in 2008) by Robert Sedgewick of Princeton University. For original code and more information read the paper "Left-leaning Red-Black Trees" at http://www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf

Installation

From Python package index:

pip install leftrb

or from Github source:

git clone https://github.com/peterhil/leftb.git
cd leftrb 
python setyp.py install

About

Leftrb/LLRB was written by Peter Hillerström.
Follow me on Twitter @peterhil!

leftrb's People

Contributors

peterhil avatar

Watchers

James Cloos avatar  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.