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:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find the node with maximum value in a Binary Search Tree
- Postorder predecessor of a Node in Binary Search Tree
- Find the node with minimum value in a Binary Search Tree
- Insert a node in Binary Search Tree Iteratively
- Find the node with maximum value in a Binary Search Tree using recursion
- Find the node with minimum 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
- Convert a Binary Search Tree into a Skewed tree in increasing or decreasing order
- Count the Number of Binary Search Trees present in a Binary Tree
- Binary Tree to Binary Search Tree Conversion
- Difference between Binary Tree and Binary Search Tree
- Binary Tree to Binary Search Tree Conversion using STL set
- Iterative Search for a key 'x' in Binary Tree
- Print Binary Search Tree in Min Max Fashion
- Construct a Binary Search Tree from given postorder
- Double Threaded Binary Search Tree
- Print all even nodes of Binary Search Tree
- Number of pairs with a given sum in a Binary Search 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.