Trees PPT Computer Club
Trees PPT Computer Club
Presented by:
Murtaza Ali
Computer Club
What is a Tree?
Define Tree!!
class Node {
int data, depth;
Node left, right;
}
Diameter of a Binary Tree
• The diameter of a tree is the number of nodes on the longest path between
two leaves in the tree.
Diameter of a Binary Tree
• The diameter of a tree T is the largest of the following quantities:
• the diameter of T’s left subtree.
• the diameter of T’s right subtree.
• the longest path between leaves that goes through the root of T (this can be
computed from the heights of the subtrees of T).
Diameter of a Binary Tree
• The algorithm for a recursive method looks like:
• Find the diameter of the left sub-tree.
• Find the diameter of the right sub-tree.
• The diameter may pass through the root, so their combined height.
• The greatest value among these 3 values would be the diameter of the binary tree.
Diameter of a Binary Tree
References
• https://www.geeksforgeeks.org/binary-tree-data-structure/
• https://www.mygreatlearning.com/blog/understanding-trees-in-data-struct
ures/
• https://www.javatpoint.com/tree
• https://www.andrew.cmu.edu/course/15-121/lectures/Trees/trees.html
• https://www.baeldung.com/cs/binary-tree-height
• https://studyalgorithms.com/tree/diameter-of-a-binary-tree/
Thank You
LinkedIn: linkedin.com/in/murtaza-ali-62494118b
Computer Club: linktr.ee/computerclubgs