Binary Tree - 60: Get Parent of a given value in Binary Tree

preview_player
Показать описание
Solution:
- To find paren of a given value, our main is to find the given value.
- We'll traverse tree in pre order manner.
- If value is null or equal to root value, then parent will be null
- While traversing, when we're at particular node, we'll check if given value exists either with left or right, if this is the case, we return current node as parent of given value.
- If we can't find the value in tree, it'll return null

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

Do Watch video for more info

This Problem is synonym of following problems:
binary tree get parent of given value,
get parent of a value in binary tree,
coding simplified,

CHECK OUT CODING SIMPLIFIED

★☆★ VIEW THE BLOG POST: ★☆★

I started my YouTube channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 200+ videos.

★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★

★☆★ Send us mail at: ★☆★
Рекомендации по теме
Комментарии
Автор

can u do this please
Convert Ternary Expression to Binary Tree

chodingninjas
Автор

You can also use your previous program of printing ancestor, just replace 'return true' to 'return false' after court<<node->data; at line no 8 .

MohitMaroliyaBCS