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
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
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
Programming Interview Question: How to print all diagonal's sums for a given binary tree?Level Order TraversalReverse a Linked List - IterativeProgramming Interview Question: Searching a 2D Sorted MatrixImplement a fair coin given an unfair coinBuying and selling stocksBinary SearchMinimum length subarray of an unsorted array sorting which results in complete sorted arrayFind an element in a sorted rotated array without finding pivot (minimum element)Maximum size square sub-matrix with all 1sBuilding Bridges Dynamic ProgrammingLeaders in an arrayFind intersection of two Linked Lists - O(A + B) Time Complexity and O(1) Space ComplexityCreate a balanced Binary Search Tree (BST) from a sorted arrayNext greater element in an arraySpiral level order traversal of a binary treeProgramming Interview Question: Recover Binary Search TreeDetect a loop in a linked listProgramming Interview Question: Find intersection of two Linked ListsLowest Common AncestorFind an element in a sorted rotated array