GithubHelp home page GithubHelp logo

avlmini's People

Contributors

liuziangexit avatar skywind3000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

avlmini's Issues

avl_tree_replace如果修改key值会出问题

您好,最近我在阅读您avltree的源代码, 并编译通过。不过我发现一个小问题就是使用

void avl_tree_replace(struct avl_tree *tree, void *victim, void *newdata);

这个函数时,如果newdata的key与victim的key相同,两个节点也会交换,但是树不会重构,这里是不是会有小问题呢?谢谢。

Some small arguments

所谓说 avl 树每次重平衡需要回溯回根节点的纯粹胡扯

I am so glad to see this. Thanks for providing the clean code and clear comparison. However, I am little bit concerned about the argument you are making here. The following are just some of my simple ideas:

I did some similar benchmarks years ago (https://github.com/SchrodingerZhu/data_structure_for_love/blob/master/report.md, I was not so good at programming at that time as I am today, the code may contain some flaws but I think it can already provide some reasonable comparisons). As you can see, it was really a draw between Rb-Tree (a left-leaning version) and the AVL tree; one performance better in some workloads, the other wins a little in different situations.

I do agree that re-balancing of an AVL tree requires visiting back until the root each time is an exaggeration; yet I do believe there is a reason behind such argument.

In fact, in the summary section of ODS (https://opendatastructures.org/ods-python/9_3_Summary.html), the book spent a full section to prove why red-black trees can have a better re-balancing performance theoretically. In the later chapter, it also argues:

Adersson's variant of red-black trees, Sedgewick's variant of red-black trees, and AVL trees are all simpler to implement than
the RedBlackTree structure defined here. Unfortunately, none of them can guarantee that the amortized time spent rebalancing is
O(1) per update. In particular, there is no analogue of Theorem 9.2 for those structures.

Again, this is only something theoretically, not practically. We cannot rely fully on the analysis: for example, Fibonacci heap performances great in paper but it is troubled with its large constant time per operation; binary structures should be optimal for in memory operations but b-tree can do better in some projects due to its friendliness to the architecture. And, this exact project also suggests this idea.

Anyway, I wrote this just to leave a room for theory. Sometime, people do need "paperwork" to guarantee some critical properties. and I think that is why rb-tree is widely chosen. However, as the theory also suggest, AVL tree can have a lower height, so it is also widely accepted in many situations to provide faster in-memory lookup. So maybe the problem is to decide which one to use in the particular case.

Just some personal views. Thanks again for this project!

avl has higher insert time than rbtree

sizeof=32/32
linux rbtree with 2500000 nodes:
insert time: 1694ms, height=28
total: 1694ms

avlmini with 2500000 nodes:
insert time: 1880ms, height=25
total: 1880ms

linux rbtree with 1000000 nodes:
insert time: 583ms, height=26
total: 583ms

avlmini with 1000000 nodes:
insert time: 722ms, height=24
total: 722ms

linux rbtree with 100000 nodes:
insert time: 23ms, height=20
total: 23ms

avlmini with 100000 nodes:
insert time: 32ms, height=20
total: 32ms

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.