Presentation#1 Design and Analysis of Algorithms Presented To Sir Ahmed Bilal Presented by Rabia Waseem (005) Mohammad Zakriya (003) Eman Malik
Presentation#1 Design and Analysis of Algorithms Presented To Sir Ahmed Bilal Presented by Rabia Waseem (005) Mohammad Zakriya (003) Eman Malik
Presented to
Sir Ahmed Bilal
Presented by
Rabia Waseem (005)
Mohammad Zakriya (003)
Eman Malik (024)
TOPIC
TREE DATA STRCUTURE AND ITS TYPES
DEFINITION
If in a graph, there is one and only one path between every pair of
vertices, then graph is called as a tree.
Example
Why Tree Data Structure?
Data structures such as arrays, linked list, stack, and queue are
linear data structures that store data sequentially.
Tree data structures allow quicker and easier access to the data as it
is a non-linear data structure.
Tree Applications
5. Router algorithms
6. Most popular databases use B-Trees and T-Trees, which are variants of the tree
The node which does not have any child is called as a leaf node.
The node which has at least one child is called as an internal node.
Level
In a tree, each step from top to bottom is called as level of a tree.
The level count starts with 0 and increments by 1 at each level or
step.
Height
Total number of edges that lies on the longest path from any leaf
node to a particular node is called as height of that node.
Height of a tree is the height of root node.
Height of all leaf nodes = 0
Depth
Total number of edges from root node to a particular node is called as depth of
that node.
Depth of a tree is the total number of edges from root node to a leaf node in the
longest path.
Depth of the root node = 0
Types of tree
Binary Tree
AVL Tree
Spanning tree
Binary Tree
A binary tree is a hierarchical data structure in which each node has at most two
Data element
Representation Of Binary Tree
Properties
Maximum node at any level will be 2^I
Maximum node at any level will be Height of root node = height of the tree
Degenarate tree
Full Binary Tree
A full binary tree is a unique binary tree where every node except the
external node has two children.
Complete Binary Tree
A complete binary tree is another specific type of binary tree where
all the tree levels are filled entirely with nodes, except the lowest
level of the tree.
Perfect Binary Tree
Binary tree is said to be ‘perfect’ if all the internal nodes have strictly two children,
and every external or leaf node is at the same level or same depth within a tree.
A perfect binary tree having height ‘h.’
Degenerate Binary Tree
tree...
Search
Insertion
Deletion
Search Operation
Step 1 - Read the search element from the user.
Step 3 - If both are matched, then display "Given node is found!!!"
Step 8 - if it is also not matched with the search element, then display "Element is not found"
Step 3 - If the tree is Not Empty, then check whether the value of new node
Step 4 - If new node is smaller than or equal to the node then move to its left child. If new node
Step 6 - After reaching the leaf node, insert the new Node as left child if the new Node is smaller
cases...
the heights of the two child sub trees of any node differ by at most
one; therefore, it is also said to be height-balanced.
Lookup, insertion, and deletion all take O(log n) time in both the
average and worst cases, where n is the number of nodes in the tree.
Explaination
Balance factor = height of left search tree – height of right search
tree
In worst case, the height of tree is O(n) then the time complexity is
O(n)
Applications
AVL trees are mostly used for in-memory sorts of sets and
dictionaries.
AVL trees are also used extensively in database applications in
which insertions and deletions are fewer but there are frequent
lookups for data required.
It is used in applications that require improved searching apart from
the database applications.
Example#1
Example#2
Example#3
Spanning Tree