0% found this document useful (0 votes)
29 views

Discrete Structures

Trees are hierarchical data structures made up of nodes connected by edges. A tree has a root node with zero or more subtrees. Binary trees restrict nodes to have at most two child nodes. Binary trees can be strictly binary, complete, or skewed depending on how nodes are structured. Binary search trees (BSTs) organize nodes so that all left descendants are less than the parent and all right descendants are greater than the parent, enabling efficient searching. Common tree operations include insertion, deletion, searching, and sorting via inorder traversal.

Uploaded by

saira
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Discrete Structures

Trees are hierarchical data structures made up of nodes connected by edges. A tree has a root node with zero or more subtrees. Binary trees restrict nodes to have at most two child nodes. Binary trees can be strictly binary, complete, or skewed depending on how nodes are structured. Binary search trees (BSTs) organize nodes so that all left descendants are less than the parent and all right descendants are greater than the parent, enabling efficient searching. Common tree operations include insertion, deletion, searching, and sorting via inorder traversal.

Uploaded by

saira
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

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

Types of binary tree:


• Strictly binary tree
• Complete binary tree
• Skewed binary tree
Strictly Binary Tree

• If each node of binary tree has either two children or no


child at all, is said to be a Strictly binary tree.
• Strictly binary tree is also called Full binary tree.
• It is used to represent mathematical expressions.
Complete Binary Tree
• If all levels of tree are completely filled except the last level and
the last level has all keys as left as possible, it is said to be a
Complete binary Tree.
• Complete binary tree is also called as Perfect Binary Tree.

• In a complete binary tree, every internal node has exactly two


children and all leaf nodes are at same level.
Skewed Binary Tree
• In a skewed binary tree, all nodes except one have only one child
node. The remaining node has no child.
• In a left skewed tree, most of the nodes have the left child without
corresponding right child.
• In a right skewed tree, most of the nodes have the right child
without corresponding left child.
Formula to find total number of
nodes

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.

BST are commonly used for searching purpose.


Basic operations for BST
• Inserting a element
• Deletion of element
• Searching
• Sorting

Sorting:
Can be traversing a BST in Inorder manner.

You might also like