Presentation is loading. Please wait.

Presentation is loading. Please wait.

TREES– Interesting problems

Similar presentations


Presentation on theme: "TREES– Interesting problems"— Presentation transcript:

1 TREES– Interesting problems
Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and Mount (Wiley 2004) and slides from Nancy M. Amato AND Jory Denny

2 Question 1 Given a binary tree, design an algorithm which creates a linked list of all the nodes at each depth (e.g. , if you have a tree with height D, you'll have D linked lists).

3 Question 2 Given a forest of balanced binary trees and two nodes, n1 and n2, find the closest common parent of n1 and n2. Nodes have parameters "parent", "left" and "right", and you cannot access the values of the nodes. If n1 and n2 are not on the same tree, return NULL.  Try to do this in O(log(n)) time and O(1) space. Note: A balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ by more than one.

4 Question 3 Find the diameter of a binary tree.
Diameter is the longest path between two leaves in the tree.


Download ppt "TREES– Interesting problems"

Similar presentations


Ads by Google