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

Minimum Depth of Binary Tree

Given a binary tree, find the minimum depth of the tree.
Minimum depth of a binary tree is the length of the shortest path of all paths from root to any leaf.

Algorithm:
1: If root is null, return 0.
2: If root is a leaf, return 1.
3: If left node of root is not null, recursively call getMinDepth to get leftDepth,
else set leftDepth to MAX_VALUE
4: If right node of root is not null, recursively call getMinDepth to get rightDepth,
else set rightDepth to MAX_VALUE
5: Return 1 + min of leftDepth or rightDepth

Time Complexity: O(n)
Space Complexity: O(1)

Code and Algorithm Visualization: http://www.ideserve.co.in/learn/minimum-depth-of-a-binary-tree

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

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

Видео Minimum Depth of Binary Tree канала IDeserve
Показать
Комментарии отсутствуют
Введите заголовок:

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

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

Зарегистрируйтесь или войдите с
Информация о видео
23 декабря 2015 г. 14:18:12
00:05:36
Яндекс.Метрика