https://github.com/aliakseis/rb_avl_comparison
Comparing RB and AVL tree implementations. We Need To Go Deeper.
https://github.com/aliakseis/rb_avl_comparison
avl avl-implementations avl-tree avl-tree-implementations avl-tree-node balanced-binary-search-trees binary-search-tree data-structures rb-avl tagged-pointers tree tree-insert
Last synced: 3 months ago
JSON representation
Comparing RB and AVL tree implementations. We Need To Go Deeper.
- Host: GitHub
- URL: https://github.com/aliakseis/rb_avl_comparison
- Owner: aliakseis
- Created: 2016-02-06T15:24:10.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2025-02-04T14:59:33.000Z (5 months ago)
- Last Synced: 2025-02-04T15:44:53.538Z (5 months ago)
- Topics: avl, avl-implementations, avl-tree, avl-tree-implementations, avl-tree-node, balanced-binary-search-trees, binary-search-tree, data-structures, rb-avl, tagged-pointers, tree, tree-insert
- Language: C
- Homepage:
- Size: 35.2 KB
- Stars: 2
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rb_avl_comparison
### Comparing RB and AVL implementations
Make AVL Trees Great Again announcement
"I think I have discovered something that no one else has any idea about, and I’m not sure I can do it justice. Its scope is so broad that I can see only parts of it clearly at one time, and it is exceedingly difficult to set down comprehensibly in writing…" Jordan Peterson
#### RB tree:
"We developed a new red-black tree implementation that has the same low memory overhead (two pointer fields per node), but is approximately 30% faster for insertion/removal."
https://www.facebook.com/notes/facebook-engineering/scalable-memory-allocation-using-jemalloc/480222803919/
https://github.com/jemalloc/jemalloc/blob/dev/include/jemalloc/internal/rb.h
#### AVL tree:
http://neil.brown.name/blog/AVL - after a small modification to reduce memory hits
## [Just one more thing:](https://www.youtube.com/watch?v=QxBnaMGP2aY)
Please note [this function.](https://github.com/aliakseis/rb_avl_comparison/blob/c195ef96ae14f630e1add8688b269785dfd54ebf/rb_avl.cpp#L365)
This is how an item deletion from the tree is accelerated by lowering memory access.
### 10000000 nodes test
CPU E2180 @ 2.00GHz
Target: x86_64-redhat-linux
gcc version 5.3.1 20160406 (Red Hat 5.3.1-6) (GCC)sudo nice -n -20 ./main
tree_insert time: 19.4895 seconds
RB depth: 22.1559
tree_search time: 17.764 seconds
alternative tree_search time: 19.4725 seconds
tree_remove time: 23.3087 secondsavl_insert time: 18.5318 seconds
AVL depth: 21.7497
avl_find time: 17.5718 seconds
alternative avl_find time: 19.446 seconds
avl_delete time: 22.9048 secondsCPU i5-6600 @ 3.30GHz
Target: x86_64-linux-gnu
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.6)sudo nice -n -20 ./main
tree_insert time: 10.375 seconds
RB depth: 22.1559
tree_search time: 9.85938 seconds
alternative tree_search time: 10.9844 seconds
tree_remove time: 12.0156 secondsavl_insert time: 9.89062 seconds
AVL depth: 21.7497
avl_find time: 7.84375 seconds
alternative avl_find time: 7.67188 seconds
avl_delete time: 11.5781 secondsenum { NNODES = 20 * 10000000 };
sudo nice -n -20 ./main
tree_insert time: 388.344 seconds
RB depth: 26.6402
tree_search time: 324.953 seconds
alternative tree_search time: 330.125 seconds
tree_remove time: 397.578 secondsavl_insert time: 298.062 seconds
AVL depth: 26.0732
avl_find time: 264.625 seconds
alternative avl_find time: 267 seconds
avl_delete time: 399.719 secondsclang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
clang++ -Wall -O3 -std=c++11 rb_avl.cpp -o rb_avl
sudo nice -n -20 ./rb_avltree_insert time: 10.7969 seconds
RB depth: 22.1559
tree_search time: 10.125 seconds
alternative tree_search time: 11.0312 seconds
tree_remove time: 12.2969 secondsavl_insert time: 10.6875 seconds
AVL depth: 21.7497
avl_find time: 5.64062 seconds
alternative avl_find time: 6.1875 seconds
avl_delete time: 12.0938 seconds