Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 61 lines (42 sloc) 2.724 kb
96267d6 @peterhil Initial commit.
authored
1 # Leftrb/LLRB
2
fba4066 @peterhil Changed license from MIT to LGPLv3 to comply with the original Java code...
authored
3 Leftrb is a Left-Leaning Red-Black (LLRB) implementation of 2–3 balanced binary
4 search trees in Python.
5
6 This is a straightforward port of the Java code presented by Robert Sedgewick in
a3d4b10 @peterhil Remove extra parenthesis.
authored
7 [his paper]((http://www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf) and in the
f796a27 @peterhil Make the language more clear.
authored
8 book [Algorithms, 4th Edition](http://algs4.cs.princeton.edu/home/), which is written
9 by Robert Sedgewick and Kevin Wayne. By their permission, the [original GPL v3 licensed Java
fba4066 @peterhil Changed license from MIT to LGPLv3 to comply with the original Java code...
authored
10 code](http://www.cs.princeton.edu/~rs/talks/LLRB/Java/RedBlackBST.java)
f796a27 @peterhil Make the language more clear.
authored
11 is licensed as LGPL v3, and ported to Python.
96267d6 @peterhil Initial commit.
authored
12
13 ## Overview
14
15 A balanced binary search tree (BBST) maintains elements in sorted order under dynamic
16 updates (inserts and deletes) and can support various order-specific queries.
17
18 Red-black trees are the de facto standard BBST algorithms, and are the underlying
19 data structure for symbol-table implementations within C++, Java, Python, BSD Unix,
20 Linux and many other modern systems.
21
22 All red–black trees are based on implementing 2-3 or 2-3-4 trees within a binary tree,
23 using red links to bind together internal nodes into 3-nodes or 4-nodes. Search, insert
24 and delete operations are O(log n) and space requirements are O(n).
25
26 However, many traditional implementations have lots of repetitive code on the symmetric
27 branches of rotation and deletion operations. So they are not easy to reason about and
28 augment with other properties, which is what BBST's are often used for: They are used
29 to implement other common data structures like Priority Queues and Interval Trees.
30
31 The LLRB method of implementing 2-3 trees is a recent improvement over the traditional
32 implementation — it maintains an additional invariant that all red links must lean left
33 except during inserts and deletes. Because of this, they can be implemented by adding
34 just a few lines of code to standard BST algorithms.
35
36 The LLRB tree is based on combining three ideas:
37
38 - Use a recursive implementation.
39 - Require that all 3-nodes lean left.
40 - Perform rotations on the way up the tree (after the recursive calls).
41
42 The LLRB approach was discovered relatively recently (in 2008) by Robert Sedgewick
43 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](http://www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf)
44
45 ## Installation
46
47 From Python package index:
48
49 pip install leftrb
50
51 or from Github source:
52
fb60e99 @dpsanders Two (rather crucial!) typos in the instructions to clone the repo.
dpsanders authored
53 git clone https://github.com/peterhil/leftrb.git
96267d6 @peterhil Initial commit.
authored
54 cd leftrb
fb60e99 @dpsanders Two (rather crucial!) typos in the instructions to clone the repo.
dpsanders authored
55 python setup.py install
96267d6 @peterhil Initial commit.
authored
56
57 ## About
58
59 Leftrb/LLRB was written by [Peter Hillerström](http://composed.nu/peterhil/).
fba4066 @peterhil Changed license from MIT to LGPLv3 to comply with the original Java code...
authored
60 Follow me on Twitter [@peterhil](http://www.twitter.com/peterhil)!
Something went wrong with that request. Please try again.