0% found this document useful (0 votes)
15 views3 pages

Chapter 11 Notes

This document defines and describes various tree data structures including rooted trees, ordered rooted trees, m-ary trees, balanced m-ary trees, binary search trees, and tree traversals. Key points covered include that a rooted tree designates one vertex as the root with all edges directed away, m-ary trees restrict the number of children per internal vertex, and binary search trees organize keys in a way that left subtree keys are less than the parent and right subtree keys are greater.

Uploaded by

fawad-occulus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Chapter 11 Notes

This document defines and describes various tree data structures including rooted trees, ordered rooted trees, m-ary trees, balanced m-ary trees, binary search trees, and tree traversals. Key points covered include that a rooted tree designates one vertex as the root with all edges directed away, m-ary trees restrict the number of children per internal vertex, and binary search trees organize keys in a way that left subtree keys are less than the parent and right subtree keys are greater.

Uploaded by

fawad-occulus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

11.

1
A tree is a connected undirected graph with no simple circuits. Because a tree cannot have a simple
circuit, a tree cannot contain multiple edges or loops. Therefore any tree must be a simple graph.

11.1.1
A rooted tree is a tree in which one vertex has been designated as the root and every edge is directed
away from the root.

If v is a vertex in T other than the root, the parent of v is the unique vertex u such that there is a directed
edge from u to v (the reader should show that such a vertex is unique). When u is the parent of v, v is
called a child of u.

Vertices with the same parent are called siblings.

The ancestors of a vertex other than the root are the vertices in the path from the root to this vertex,
excluding the vertex itself and including the root (that is, its parent, its parent’s parent, and so on, until
the root is reached).

The descendants of a vertex v are those vertices that have v as an ancestor.

A vertex of a rooted tree is called a leaf if it has no children. Vertices that have children are called
internal vertices. The root is an internal vertex unless it is the only vertex in the graph, in which case it
is a leaf.

A rooted tree is called an m-ary tree if every internal vertex has no more than m children. The tree is
called a full m-ary tree if every internal vertex has exactly m children. An m-ary tree with m = 2 is called a
binary tree.

ORDERED ROOTED TREE


An ordered rooted tree is a rooted tree where the children of each internal vertex are ordered. Ordered
rooted trees are drawn so that the children of each internal vertex are shown in order from left to right.

In an ordered binary tree (usually called just a binary tree), if an internal vertex has two children, the
first child is called the left child and the second child is called the right child.

The tree rooted at the left child of a vertex is called the left subtree of this vertex, and the tree rooted at
the right child of a vertex is called the right subtree of the vertex.

11.1.3
A tree with n vertices has n − 1 edges.
 This theorem tells us that the two conditions (i) G is connected and (ii) G has no simple circuits,
imply (iii) G has n − 1 edges.

COUNTING VERTICES IN FULL m-ARY TREES


A full m-ary tree with i internal vertices contains n = mi + 1 vertices

Proof: Every vertex, except the root, is the child of an internal vertex. Because each of the i internal
vertices has m children, there are mi vertices in the tree other than the root. Therefore, the tree
contains n = mi + 1 vertices.
A full m-ary tree with

(i) n vertices has i = (n − 1)∕m internal vertices and l = [(m − 1)n + 1]∕m leaves,
(ii) i internal vertices has n = mi + 1 vertices and l = (m − 1)i + 1 leaves,
(iii) l leaves has n = (ml − 1)∕(m − 1) vertices and i = (l − 1)∕(m − 1) internal vertices

BALANCED m-ARY TREES


In a balanced m-ary tree, the subtrees at each vertex contain paths of approximately the same length.

The level of a vertex v in a rooted tree is the length of the unique path from the root to this vertex. The
level of the root is defined to be zero. The height of a rooted tree is the maximum of the levels of
vertices. In other words, the height of a rooted tree is the length of the longest path from the root to
any vertex.

A rooted m-ary tree of height h is balanced if all leaves are at levels h or h − 1.

AN UPPER BOUND FOR THE NUMBER OF LEAVES IN AN m-ARY TREE


There are at most mh leaves in an m-ary tree of height h.

11.2.2
Binary Search Tree: a binary tree in which each child of a vertex is designated as a right or left child, no
vertex has more than one right child or left child, and each vertex is labeled with a key, which is one of
the items. Furthermore, vertices are assigned keys so that the key of a vertex is both larger than the
keys of all vertices in its left subtree and smaller than the keys of all vertices in its right subtree.

1. Start with a tree containing just one vertex, namely, the root. The first item in the list is
assigned as the key of the root.
2. To add a new item, first compare it with the keys of vertices already in the tree, starting at
the root and moving to the left if the item is less than the key of the respective vertex if this
vertex has a left child, or moving to the right if the item is greater than the key of the
respective vertex if this vertex has a right child.
a. When the item is less than the respective vertex and this vertex has no left child, then a
new vertex with this item as its key is inserted as a new left child.
b. Similarly, when the item is greater than the respective vertex and this vertex has no
right child, then a new vertex with this item as its key is inserted as a new right child.

Preorder traversal: Visit root, visit subtrees left to right


Postorder traversal: Visit subtrees left to right; visit root
Infix notation:

(A − B) − ((A - C) ∪ (B ∩ (A ∪ C)))

AUC ∩ B U A-C – A-B

Prefix notation:

− (− A, B), (∪ (- A, C), (∩ B, (∪A, C)))

-∪∩∪ACB-AC-AB

+↑+xy2 /-x43

Postfix notation:

AC∪ B∩ AC-∪ AB--

You might also like