Given a binary search tree. The task is to print all odd nodes of the binary search tree.
Input : 5 / \ 3 7 / \ / \ 2 4 6 8 Output : 3 5 7 Input : 14 / \ 12 17 / \ / \ 8 13 16 19 Output : 13 17 19
Approach: Traverse the Binary Search tree using any of the tree traversals and check if current node’s value is odd. If yes then print it otherwise skip that node.
Below is the implementation of the above Approach:
3 5 7
Time Complexity : O(n) where n is no. Of nodes
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.
- Print all even nodes of Binary Search Tree
- Print Common Nodes in Two Binary Search Trees
- Pre-Order Successor of all nodes in Binary Search Tree
- Remove all leaf nodes from the binary search tree
- Leaf nodes from Preorder of a Binary Search Tree
- Find maximum count of duplicate nodes in a Binary Search Tree
- Print Binary Search Tree in Min Max Fashion
- Print all nodes between two given levels in Binary Tree
- Print all internal nodes of a Binary tree
- Print all leaf nodes of a binary tree from right to left
- Print the nodes of binary tree as they become the leaf node
- Print Sum and Product of all Non-Leaf nodes in Binary Tree
- Print path from root to all nodes in a Complete Binary Tree
- Print leaf nodes in binary tree from left to right using one stack
- Print All Leaf Nodes of a Binary Tree from left to right | Set-2 ( Iterative Approach )
- Recursive Program to Print extreme nodes of each level of Binary Tree in alternate order
- Binary Search Tree | Set 1 (Search and Insertion)
- 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
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.