What is the difference between ordered tree and rooted tree? - An example - data-structures

I know the definition of these two types of trees. However, I cannot understand their structures. Could you give me an example ?

A rooted Tree has only ONE Element which is considerd as root element.
In the examples below the root element is green and the data structure is represented in form of a binary tree with two child elements.
An Ordered Binary Tree is a form of rooted tree with a specific order.
Started from the root element the smaller number is on the left side and the higher number on the right side.
Ordered Binary Tree
An Unordered Binary Tree on the other side has no specific order of the elements.
Unordered Root Tree

The structure of an unordered tree looks like follows,
As can be seen in the above figure, the root of the tree is node A, but its children are not ordered from left to right or in any particular order. However, we can re-draw the tree as follows, in order to make it an ordered rooted tree.
An ordered tree can be either a binary tree or else a general tree. The binary nature of a tree and the ordered nature are two separate concepts. The overall idea is, a rooted tree is not an ordered rooted tree unless it is depicted according to a particular order or some additional textual information is given to notify the order.

Related

In binary trees, are sibling nodes necessarily ordered?

Just been learning about binary trees in school, and two rules of binary trees is that
every node has at most 2 child nodes
there exists linear ordering defined for the children of each node (ordered pair)
Now, all types of binary trees (full, complete, etc.) are binary trees so they must satisfy these 2 conditions.
However, I saw on GeeksForGeeks this example:
How is 'linear ordering', ordered pair, defined here?
It seems that for the sibling nodes in this picture, some left ones are larger than the right one, some right nodes are larger than the left one.
If asked to check if a given tree is a binary tree, how do I make sure of the second property, that the children of each node have to be ordered?
Thanks
This is one of the complicated ways to introduce a binary tree.
two rules of binary trees is that
every node has at most 2 child nodes
there exists linear ordering defined for the children of each node (ordered pair)
Simple ways of introducing binary trees I could think of are "at most two children and no cycles" or "at most two children and unique path between any pair of vertices".
But fine. You bring up the point of linear order. Lets discuss that.
Here
A linear ordering on a finite collection of objects may be described
as follows: each object has exactly one immediate predecessor object
and one immediate successor object with two exceptions: A first object
has no predecessor and a last object has no successor.
If you have learnt about traversal so far, with the above definition, I would take binary tree traversals as linear order - preorder, postorder, inorder, level order. This applies to all types of binary trees (full, complete, etc.) which includes the complete binary tree you posted as an image.

difference between m way tree and m way search tree

I tried finding the difference between m way tree and the m way search tree. Most resources only tells about m way search tree and end up being on B tree or B+ trees.
My doubts are:-
Is it analogous to the binary tree and binary search tree?
I read somewhere that m way trees don't have any particular order and
every node has to be filled fully before moving to the new node.(complete
tree)
Is it analogous to the binary tree and binary search tree?
Yes
m way trees don't have any particular order
This is true
and every node has to be filled fully before moving to the new node.(complete tree)
Something like this describes a step in an algorithm, and has little to do with the data structure itself: nothing is "moving" in a data structure.
Definitions
In short: an m-way tree puts no conditions on the values stored in the nodes, while an m-way search tree does.
Reva Freedman, associate professor at Northern Illinois University has notes on Multiway Trees where four terms are defined in succession, each time indicating which additional requirements apply for the next term:
multi way tree,
m-way tree
m-way search tree
B-tree of order m
Multiway Trees
A multiway tree is a tree that can have more than two children. A
multiway tree of order m (or an m-way tree) is one in which a tree can
have m children.
As with the other trees that have been studied, the nodes in an m-way
tree will be made up of key fields, in this case m-1 key fields, and
pointers to children.
To make the processing of m-way trees easier, some type of order will
be imposed on the keys within each node, resulting in a multiway
search tree of order m ( or an m-way search tree). By definition an
m-way search tree is a m-way tree in which:
Each node has m children and m-1 key fields
The keys in each node are in ascending order.
The keys in the first i children are smaller than the ith key
The keys in the last m-i children are larger than the ith key
M-way search trees give the same advantages to m-way trees that binary
search trees gave to binary trees - they provide fast information
retrieval and update. However, they also have the same problems that
binary search trees had - they can become unbalanced, which means that
the construction of the tree becomes of vital importance.
B-Trees
An extension of a multiway search tree of order m is a B-tree of
order m. This type of tree will be used when the data to be
accessed/stored is located on secondary storage devices because they
allow for large amounts of data to be stored in a node.
A B-tree of order m is a multiway search tree in which:
The root has at least two subtrees unless it is the only node in the tree.
Each nonroot and each nonleaf node have at most m nonempty children and at least m/2 nonempty children.
The number of keys in each nonroot and each nonleaf node is one less than the number of its nonempty children.
All leaves are on the same level.

Why the tree is not a binary tree?

I am a beginner in the field of data structures, I am studying binary trees and in my textbook there's a tree which is not a binary tree but I am not able to make out why the tree is not a binary tree because every node in the tree has atmost two children.
According to Wikipedia definition of binary tree is "In computer science, a binary tree is a treedata structure in which each node has at most two children, which are referred to as the left child and the right child."
The tree in the picture seems to satisfy the condition as mentioned in the definition of binary tree.
I want an explanation for why the tree is not a binary tree?
This is not even a tree, let alone binary tree. Node I has two parents which violates the tree property.
I got the answer, This not even a tree because a tree is connected acyclic graph also a binary tree is a finite set of elements that is either empty or is partitioned into three disjoint subsets. The first subset contains a single element called the root of the tree. The other two subsets are themselves binary trees called the left and right subtrees of the original tree.
Here the word disjoint answers the problem.
It's not a binary tree because of node I
This can be ABEI or ACFI
This would mean the node can be represented by 2 binary numbers which is incorrect
Each node has either 0 or 1 parents. 0 in the case of the root node. 1 otherwise. I has 2 parents E and F

Difference between ordered and unordered (rooted) trees

I am reading algorithms by Robert Sedwick. Some definitions from the book are shown below.
A tree (also an ordered tree) is a node (called the root) connected to
a sequence of disjoint trees. Such a sequence is called a forest.
A rooted tree (or unordered tree) is a node (called the root)
connected to a multiset of rooted trees. (such a multiset is called an
unordered forest.
My questions on the above text are
I am having difficutlty in understanding above defintions. Can any one please explain with examples.
What does author mean by disjoint trees?
What does author mean by multiset rooted trees?
Thanks for your time and help
A tree by this definition is more or less what we normally understand by tree: a node connected to an ordered sequence of (sub)trees. It's a recursive definition: if the sequence is empty, the node is called leaf, and if not, each of the tree in the sequence is also "a node connected to an ordered sequence of (sub)trees."
By disjoint the author means that the subtrees don't have nodes in common.
The definition means that the subtrees of a rooted tree are not in a particular order and that they may be repeated. A multiset is kind of like a set that allows multiples.
An ordered tree (a "tree" of the first definition) has the subtrees in a particular order, and the subtree sequence cannot contain the same tree twice, because the subtrees must be disjoint. A rooted tree does not have these restrictions; by this definition a root might have a subtree twice, in a structure that resembles a cycle.
I don't have Sedwick's book to check if or why this definition makes sense; a more common definition or rooted tree would use a normal set for subtrees, rather than a multiset. Perhaps the intention is to allow multiple links between a node and its children while disallowing other kinds of cycles, such as links between siblings and cousins.

Complete binary tree definitions

I have some questions on binary trees:
Wikipedia states that a binary tree is complete when "A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible." What does the last "as far left as possible" passage mean?
A well-formed binary tree is said to be "height-balanced" if (1) it is empty, or (2) its left and right children are height-balanced and the height of the left tree is within 1 of the height of the right tree, taken from How to determine if binary tree is balanced?, is this correct or there's "jitter" on the 1-value? I read on the answer I linked that there could be also a difference factor of 4 between the height of the right and the left tree
Do the complete and height-balanced definitions just apply to binary tree or just any other tree?
Following the reference of the definition in wikipedia, I got to
this page. The definition was taken from there but modified:
Definition: A binary tree in which every level, except possibly the deepest, is completely filled. At depth n, the height of the
tree, all nodes must be as far left as possible.
It continues with a note below though,
A complete binary tree has 2k nodes at every depth k < n and between 2n and 2^(n+1) - 1 nodes altogether.
Sometimes, definitions vary according to convenience (be useful for something). That passage might be a variation which, as I understand, requires leaf nodes to fill first the left side of the deepest level (that is, fill from left to right). The definition that I usually found is exactly as described above but without that
passage.
Usually the definition taken for height-balanced tree is the one you
described. In other words:
A tree is balanced if and only if for every node the heights of its two subtrees differ by at most 1.
That definition was taken from here. Again, sometimes definitions are made more flexible to serve specific purposes. For example, the definition of an AVL tree says that
In an AVL tree, the heights of the two child subtrees of any node
differ by at most one
Still, I remember once I had to rewrite an algorithm so that the tree
would be considered height-balanced if the two child subtrees of any
node differed by at most 2. Note that the definition you gave is recursive, this is very common for binary trees.
In a tree whose number of children is variable, you wouldn't be able to say that it is complete (any parent could have the number of children that you want). Still, it can apply to n-ary trees (with a fixed amount of n children).
Do the complete and height-balanced definitions just apply to binary
tree or just any other tree?
Short answer: Yes, it can be extended to any n-ary tree.

Resources