real time applications of AVL trees - avl-tree

I am aware of some of the advantages of using AVL trees such as getting better time complexity to search an element log(number of nodes in tree) since the tree has self-balancing capabilities.
I am curious - what are some of the real time applications of AVL trees? Like in real world, for what applications/use-cases have the AVL trees been used?

Related

What are the advantages of B plus tree over skip list?

So recently I am learning database system on Youtube published by CMU. The professor said skip list is like the rotated B+ tree. And it seems that the time complexity of operations on b+ tree and skip list is nearly the same. Plus, skip list does not need to store intermediate nodes like B+ tree does. However, rare DBMS uses skip list to store indexes of tables. So what are the advantages of B+ tree over skip list?

What is the Difference between Bottom-up and Top down methods in splay tree?

I have read about Splay tree and I found,there are two methods for constructing the splay tree. They are
Bottom-up
Top-down
So I need to know What is the difference between the two methods and their working ?
A top-down splay tree: performs rotations on the initial access path. Thus a top-down splay tree node does not need a parent link. The splay operation finishes as soon as the search does. That means the overhead for operations of a top-down splay tree is of a relatively small amount.
Bottom-up splay tree: requires a traversal from the root down the tree and then a bottom-up traversal to implement the splaying step, so a bottom-up splay tree implementation looks similar to that of an AVL tree. Besides, it needs a parent link or a stack to store the search path.
An implementation of a top-down splay tree can be found in the data structure book (Chapter 12) written by Weiss.
The methods define how you use splaying when searching:
Bottom-up: you search the tree and rotate at the same iteration
Top-down: you first search and at another iteration you rotate
you can read Splay tree
This ideas hold to the creation also, when using the top down you insert the key as if it was a binary serach tree and than move it to the head in another iteration.

Easiest to implement online sorted data structure in C

I'm scanning a large data source, currently about 8 million entries, extracting on string per entry, which I want in alphabetical order.
Currenlty I put them in an array then sort an index to them using qsort() which works fine.
But out of curiosity I'm thinking of instead inserting each string into a data structure that maintains them in alphabetical order as I scan them from the data source, partly for the experience of emlplementing one, partly because it will feel faster without the wait for the sort to complete after the scan has completed (-:
What data structure would be the most straightforward to implement in C?
UPDATE
To clarify, the only operations I need to perform are inserting an item and dumping the index when it's done, by which I mean for each item in the original order dump an integer representing the order it is in after sorting.
SUMMARY
The easiest to implement are binary search trees.
Self balancing binary trees are much better but nontrivial to implement.
Insertion can be done iteratively but in-order traversal for dumping the results and post-order traversal for deleting the tree when done both require either recursion or an explicit stack.
Without implementing balancing, runs of ordered input will result in the degenerate worst case which is a linked list. This means deep trees which severely impact the speed of the insert operation.
Shuffling the input slightly can break up ordered input significantly and is easier to implement that balancing.
Binary search trees. Or self-balancing search trees. But don't expect those to be faster than a properly implemented dynamic array, since arrays have much better locality of reference than pointer structures. Also, unbalanced BSTs may "go linear", so your entire algorithm becomes O(n²), just like quicksort.
You are already using the optimal approach. Sort at the end will be much cheaper than maintaining an online sorted data structure. You can get the same O(logN) with a rb-tree but the constant will be much worse, not to mention significant space overhead.
That said, AVL trees and rb-trees are much simpler to implement if you don't need to support deletion. Left-leaning rb tree can fit in 50 or so lines of code. See http://www.cs.princeton.edu/~rs/talks/LLRB/ (by Sedgewick)
You could implement a faster sorting algorithm such us Timsort or other sorting algorithms with a nlog(n) worst case and just search it using Binary search since its faster if the list is sorted.
you should take a look at Trie datastructure wikilink
i think this will serve what you want

how do I balance my binary tree

I already have a working binary tree database. Unfortunately, it needs to have the ability to balance itself. I don't want to rewrite the whole thing, I just want to include a function that will balance the tree. Any algorithms or ideas?
AVL and RedBlack trees are self balancing trees.
You can traverse your original tree and insert the nodes in these trees.
Afterwards you can keep the new tree and discard your original tree.
I have found the Stanford libavl tutorial quite helpful.
Check out the examples in AVL tree wiki.
Also, try to play with the AVL tree animations available in the web, such as
http://www.cs.jhu.edu/~goodrich/dsa/trees/avltree.html or
http://www.strille.net/works/media_technology_projects/avl-tree_2001/ or
http://www.site.uottawa.ca/~stan/csi2514/applets/avl/BT.html
AVL and Red-Black trees are balanced binary trees. I have an implementation of AVL trees. Look here. It supports insertion and search. Deletion is not implemented yet.
look for balanced trees like avl red black

How to turn Prim's algorithm into Kruskal's algorithm?

I've implemented Prim's algorithm in C (www.bubblellicious.es/prim.tar.gz) but I was just wondering how to transform this into Kruskal's algorithm.
It seems they're quite similar, but I can't imagine how can I modify my old code into that new one. It'd be delicious if you give some advices or something. I know that's easy, but I'm still a n00b in C programming ...
Why not just write Kruskal's from scratch and see how they compare in your own solutions? Best way to learn.
To convert you need a forest (i.e. a set of trees where initially each node is a tree) as your temporary output structure rather than a single tree. Then on each step, rather than finding the cheapest vertex that adds a currently unconnected node to your tree, you find the cheapest edge in the graph and, if it creates a new tree (i.e. connects two previously unconnected nodes) add that tree to the forest and remove the source trees. Otherwise discard the edge.
A proper implementation of Kruskal is more memory intensive but less time intensive than a proper Prim implementation.
But the differences between the two are quite large. Probably all you can keep between are some helper functions and some data structures. Not a conversion, more a rewrite using more high level building blocks.
Why dont you consider switching to C++ and using the boost graph library
(http://www.boost.org/)?
It contains very well implementations for both algorithms. Type-safe and highly performant.
See kruskal_minimum_spanning_tree and prim_minimum_spanning_tree

Resources