Загрузка страницы

Lowest Common Ancestor

Problem:
Given a binary tree and 2 tree nodes A and B(assuming both nodes A and B are present in the tree), find the lowest common ancestor of the nodes.

Solution:
Traverse the tree in bottom up approach. If node ( A or B ) is found, return it to its parent. Parent will check if it was able to get nodes from both of its child.If yes, then Parent is LCA. If no, Parent will return NULL if none of its child returned A or B ELSE will return not NULL node.

Code: http://www.ideserve.co.in/learn/lowest-common-ancestor-binary-tree

Website: http://www.ideserve.co.in

Facebook: https://www.facebook.com/IDeserve.co.in

Видео Lowest Common Ancestor канала IDeserve
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
1 августа 2015 г. 0:00:24
00:06:58
Яндекс.Метрика