Since trees are special kind of graphs or we can categorize trees in DAG(Directed Acyclic Graphs) but how can we differentiate between Threaded Binary Trees and Graphs? Can we categorize threaded binary tree in DAG?
A threaded binary tree is not a DAG, since it has cycles, but it is easy to treat it as one in any algorithm by not following threads (think treating them as NULL pointers).
It is also easy to convert any Threaded Binary Tree into a Binary Tree by removing all the threads.
Related
A classical tree has one root node. Example:
Is there a tree with multiple initial roots like in the picture?:
As #Joe Sewell noted in the comments, a collection of independent trees is called a forest. This term applies both to collections of directed rooted trees like the one you showed above, plus collections of undirected, unrooted trees as well.
Many data structures and algorithms make use of forests. The binomial and Fibonacci heap data structures store their items in a collection of smaller independent trees. Link/cut trees, which are used in some maximum flow algorithms, work with independent collections of trees as well.
I've got a generic c++ AVL tree and I'd like to know if it's possible (and not too complicated) to convert my AVL into a Splay tree or is it more efficient to program a Splay tree from zero
There is no such thing as a "splay tree", in the sense that the splay algorithm does not depend on any additional metadata nor does it impose any constraint on the tree structure. Any arbitrary binary tree can be used with the splay algorithm.
So you can "convert" an AVL tree simply by dropping or ignoring the AVL-specific per-node metadata.
I am reading Data Structure and Algorithm Analysis in Java Chapter 4 - Trees.
I am quoting:
A tree can be defined in several ways. One natural way to define a
tree is recursively
What are other ways to define trees, other than natural way ?
Here several ways contrasts against recursion, not natural - meaning that there are other ways than recursion to generate a tree instance. You could use loops, for example. Recursion is natural because it's an obvious and elegant strategy for this task, as every subtree is itself a tree. Here, recursive code will be much cleaner and easier to understand (assuming you understand recursion) than a loop implementation.
You could define a tree using the terminology of graph theory:
A tree is a connected, acyclic, undirected graph.
Or you could describe it by the elements of which it consists:
A tree is a (possibly non-linear) data structure made up of nodes or vertices and edges without having any cycle. The tree with no nodes is called the null or empty tree. (Wikipedia)
Your quote refers to the fact that for a node of a tree all of its children are individual trees, hence the simple (recursive) definition.
I have a basic understanding of both red black trees and 2-3-4 trees and how they maintain the height balance to make sure that the worst case operations are O(n logn).
But, I am not able to understand this text from Wikipedia
2-3-4 trees are an isometry of red-black trees, meaning that they are equivalent data structures. In other words, for every 2-3-4 tree, there exists at least one red-black tree with data elements in the same order. Moreover, insertion and deletion operations on 2-3-4 trees that cause node expansions, splits and merges are equivalent to the color-flipping and rotations in red-black trees.
I don't see how the operations are equivalent. Is this quote on Wikipedia accurate? How can one see that the operations are equivalent?
rb-tree(red-black-tree) is not isomorphic to 2-3-4-tree. Because the 3-node in 2-3-4-tree can be lean left or right if we try to map this 3-node to a rb-tree. But llrb-tree(Left-leaning red-black tree) does.
Words from Robert Sedgewick(In Introduction section):
In particular, the paper describes a way to maintain
a correspondence between red-black trees and 2-3-4 trees,
by interpreting red links as internal links in 3-nodes and
4-nodes. Since red links can lean either way in 3-nodes
(and, for some implementations in 4-nodes), the correspondence is not necessarily 1-1
Also Page29 and Page30 of presentation from Robert Sedgewick. This a presentation about LLRB tree.
And "Analogy to B-trees of order 4" section of "Red-black Tree" in the wikipedia, it contains a good graph.
What are the applications of 2-3-4 trees? Are they widely used in applications for providing better performance of the applications ?
Edit : Which algorithms make the best use of 2-3-4 trees ?
2-3-4 trees are self-balancing and usually are usually very efficient for finding, adding and deleting elements, so like all trees they can be used for storing and retrieving elements in non-linear order. Unfortunately they tend to use more memory than other trees, because even nodes with only 2 data items still need to have enough memory to possibly store 4 of them.
This is why 2-3-4 trees are used as models for red-black trees, which are like standard BSTs except that nodes can be either red or black, and various rules exist about how to choose which colour a node is.
The key is that algorithms for searching/adding/deleting in a 2-3-4 tree are VERY similar to the ones for a red-black tree, so usually 2-3-4 trees are studied as a way of understanding red-black trees. The red-black trees themselves are quite widely used - I believe the standard Java Collections Framework tree is a red-black tree.
Answer to the applications of 2-3-4 Trees are:
• Linux Kernel.
• Completely Fair Scheduler
• To keep track of Virtual Memory Segments of a Process.
Because it is similar of Red Black Trees and as #Adam said we use it in Java Collections Framework itself.