0% found this document useful (0 votes)
67 views2 pages

Exercises On Trees

The document contains exercises about trees: 1. It asks questions about the root, leaves, interior nodes, siblings, subtrees, ancestors, descendants, longest path, height, and depth of a sample tree. 2. It asks if a leaf can be an ancestor of another leaf or have descendants. 3. It asks why a graph consisting of 4 nodes connected in a cycle is not a tree. 4. It defines ordered trees and asks to identify relationships between ordered pairs of nodes in the sample tree. 5. It asks to identify the leftmost child and right sibling of each node in the sample tree. 6. It asks how many bytes are needed to represent the

Uploaded by

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

Exercises On Trees

The document contains exercises about trees: 1. It asks questions about the root, leaves, interior nodes, siblings, subtrees, ancestors, descendants, longest path, height, and depth of a sample tree. 2. It asks if a leaf can be an ancestor of another leaf or have descendants. 3. It asks why a graph consisting of 4 nodes connected in a cycle is not a tree. 4. It defines ordered trees and asks to identify relationships between ordered pairs of nodes in the sample tree. 5. It asks to identify the leftmost child and right sibling of each node in the sample tree. 6. It asks how many bytes are needed to represent the

Uploaded by

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

Some exercises on trees

1. Answer the questions below in relation with this tree

(a) What is the root of the tree


(b) What are the leaves of the tree
(c) What are the interior nodes of the tree
(d) What are the siblings of node 6
(e) List the nodes in the subtree with root 5
(f) What are the ancestors of node 10
(g) What are the descendants of node 10
(h) What is the longest path in the tree
(i) What is the height of node 3
(j) What is the depth of node 13
(k) What is the height of the tree

2. Can a leaf in a tree be the ancestor of another leaf?


3. Can a leaf in a tree have a descendant?
4. Suppose we have a graph consisting of four nodes, r, a, b, and c. Node r is an isolated node and has no
edges connecting it. The remaining three nodes form a cycle; that is, we have an edge connecting a and
b, an edge connecting b and c, and an edge connecting c and a. Give two reasons why this graph is not a
tree.
5. Ordered trees: We can assign a left-to-right order to the children of any node. For example, the order
of the children of 3 in the figure above is 5 leftmost, then 6, then 7. This left-to-right ordering can be
extended to order all the nodes in a tree. If m and n are siblings and m is to the left of n, then all of m’s
descendants are to the left of all of n’s descendants. Further, for any pair of nodes x and y in the tree one
of the following 4 conditions hold:
(a) x is an ancestor of y
(b) x is a descendant of y
(c) x is to the left of y
(d) x is to the right of y
For each of the following pair of nodes, tell which applies to them: (2,3); (2,11); (10,6); (5,14); (15,4)

1
6. For each node in the tree above, indicate the leftmost child and right sibling.

7. Represent the tree above by leftmost-child and right-sibling pointers. How many bytes are needed to
represent this tree assuming a pointer is 4 bytes long and an integer is also 4 bytes long?

You might also like