CS6301 Programming and Data Structures II: Part-A
CS6301 Programming and Data Structures II: Part-A
CS6301 Programming and Data Structures II: Part-A
PART-A
1) Define a tree
A tree is a collection of nodes. The collection can be empty; otherwise, a tree consists of
a distinguished node r, called the root, and zero or more nonempty (sub) trees T1, T2,
,Tk, each of whose roots are connected by a directed edge from r.
2) Define root
This is the unique node in the tree to which further sub-trees are attached.
4) Define leaves
These are the terminal nodes of the tree. The nodes with degree 0 are always the
leaves.
9) Define forest
A tree may be defined as a forest in which only a single node (root) has no
predecessors. Any forest consists of a collection of trees.
10) Define a binary tree
A binary tree is a finite set of nodes which is either empty or consists of a root and
two disjoint binary trees called the left sub-tree and right sub-tree.
25) Traverse the given tree using Inorder, Preorder and Postorder traversals.
Inorder : D H B E A F C I G J
Preorder: A B D H E C F G I J
Postorder: H D E B F I J G C A
26) In the given binary tree, using array you can store the node 4 at which location?
At location 6
1 2 3 - - 4 - - 5
where LCn means Left Child of node n and RCn means Right Child of node n
A red-black tree is a binary search tree which has the following red-black properties:
a) Zig: If p is the root and v is the left child of p, then left-left rotation at p would
suffice. This case always terminates the splay as v reaches the root after this
rotation.
b) Zig-Zig: If p is not the root, p is the left child and v is also a left child, then a left-
left rotation at g followed by a left-left rotation at p, brings v as an ancestor of g
as well as p.
c) Zig-Zag: If p is not the root, p is the left child and v is a right child, perform a
left-right rotation at g and bring v as an ancestor of p as well as g.
------------------------------------------------------------------------------------------------