Given a Binary Node and a node. The task is to search and check if the given node exits in the binary tree or not. If it exists, print YES otherwise print NO.
Given Binary Tree:
Input : Node = 4 Output : YES Input : Node = 40 Output : NO
The idea is to use any of the tree traversals to traverse the tree and while traversing check if the current node matches with the given node. Print YES if any node matches with the given node and stop traversing further and if the tree is completely traversed and none of the node matches with the given node then print NO.
Below is the implementation of the above approach:
- Postorder predecessor of a Node in Binary Search Tree
- Insert a node in Binary Search Tree Iteratively
- Find the node with maximum value in a Binary Search Tree
- Find the node with minimum value in a Binary Search Tree
- Find the node with minimum value in a Binary Search Tree using recursion
- Find the node with maximum value in a Binary Search Tree using recursion
- Minimum swap required to convert binary tree to binary search tree
- Complexity of different operations in Binary tree, Binary Search Tree and AVL tree
- Count the Number of Binary Search Trees present in a Binary Tree
- Difference between Binary Tree and Binary Search Tree
- Binary Tree to Binary Search Tree Conversion using STL set
- Binary Tree to Binary Search Tree Conversion
- Iterative Search for a key 'x' in Binary Tree
- Sum of cousins of a given node in a Binary Tree
- Get Level of a node in a Binary Tree
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.