Discrete Structures
Discrete Structures
Trees
Tree
• Definition :
A tree data structure can be defined locally as a collection of
nodes where each node is a data structure consisting of a
value, together with a list of references to nodes, with the
constraints that no reference is duplicated, and none points
to the root.
• Basic terms:
I. Root : first node
II. Node : each data item
III. Degree of nodes : no. of sub trees of a node
Example of tree
Tree
Degree of tree:
Maximum degree of node in a given tree.
Terminal node:
Node with zero degree.
Tree
Edge:
line that connects node.
Depth(Height):
It is the no. of levels from root node to terminal node.
Binary Tree
• Tree with the finite number of elements.
• In Binary tree, node contain following info:
i. Data
ii. Left pointer
iii. Right pointer
T=2^(d+1)-1
Where d=depth
Binary Search Tree
In BST, node’s left child must have values less than its parent value
and nodes right child must have greater value than its parent value.
Sorting:
Can be traversing a BST in Inorder manner.