C++ Articles - Page 470 of 719

Print all even nodes of Binary Search Tree in C++

Farhan Muhamed
Updated on 12-Aug-2025 17:00:45

411 Views

A Binary Search Tree is a data structure that stores data in a sorted order such that for every node, the left subtree contains values less than the node's value, and the right subtree contains values greater than the node's value. In this article, we will find all even nodes of a binary search tree using C++. Find Even-Valued Nodes in BST You are given a binary search tree (BST) as input, and your task is to write a program that finds all the nodes with even values and returns them as output. To understand better, let's consider the ... Read More

Print all full nodes in a Binary Tree in C++

sudhir sharma
Updated on 22-Jan-2020 11:42:51

646 Views

In this problem, we are given a binary tree. Our task is to print all nodes of the tree that are full nodes.The binary tree is a tree in which a node can have a maximum of 2 child nodes. Node or vertex can have no nodes, one child or two child nodes.Example −A full node is a node that has both its left and right child available. In other words, a node with the left and right child is a full node. In the above binary tree, 4 and 9 are full nodes.Let’s take an example to understand the ... Read More

Print all funny words in a string in C++

sudhir sharma
Updated on 22-Jan-2020 11:38:09

234 Views

In this problem, we are given a sentence. Our task is to print all strings from the sentence that are funny words.Funny word is a word that follows the condition - The absolute difference between adjacent characters of the string and its reverse string is equal.|string[0] - string[1]| = |revstring[0]-revstring[1]|Let’s take an example to understand the problem −Input: string = ‘ABRS’ Output: Yes Explanation: Reverse string = SRBA |A-B| = 1 = |S-R| |B-R| = 16 = |R-B| |B-A| = 1 = |R-S|To solve this problem, we have to extract each string from the given sentence. And print if the ... Read More

Print all Good numbers in given range in C++

sudhir sharma
Updated on 22-Jan-2020 11:34:48

844 Views

In this problem, we are given three values L, R, and d. Our task is to print all good numbers within the range L to R that do not contain the d as its digit.A good number is a number in which every digit is larger than the sum of digits of its right (all less significant bits than it). For example, 732 is a good number, 7> 3+2 and 3>2.Now, let’s take an example to understand the problem, Input: L = 400 , R = 500 , k = 3 Output: 410, 420, 421Explanation − good numbers between 400 ... Read More

Print all increasing sequences of length k from first n natural numbers in C++

sudhir sharma
Updated on 22-Jan-2020 11:31:31

581 Views

In this problem, we are given two integers K and n. Our task is to print all increasing sequences of length K using first n natural numbers.The increasing sequence is a sequence of numbers in which the value of the next element is greater than the previous one.Let’s take an example to understand the problem −Input: n = 4, K = 2 Output: 1 2 1 3 1 4 2 3 2 4 3 4To solve this problem, we will create a k length array that stores the current sequence of the array. And for every position in the array, ... Read More

Print all integers that are sum of powers of two given numbers in C++

sudhir sharma
Updated on 22-Jan-2020 11:28:46

230 Views

In this problem, we are given two numbers a and b and an integer bound and we have to print all values less than binding which is the sum of squares of a and b.Bound >= ai + bjLet’s take an example to understand the problem −Input: a=2, b=3, bound=8 Output: 2 3 4 5 7To solve this problem, we will use nested loops using two variables i and j from 0. The outer loop will have ending condition xi = bound and the inner loop will have ending condition xi + yj > bound. For each iteration of the ... Read More

Print all interleavings of given two strings in C++

sudhir sharma
Updated on 22-Jan-2020 11:25:19

492 Views

In this problem, we are given two string str1 and str2 and we have to print all interleaving strings from both the string.Interleaving string created using two given strings such that the order of characters of each string.Let’s take an example to understand the problem −Input: str1 = “XY” str2= “NS” Output: XYNS, XNYS, XNSY, NXYS, NXSY, NSXYTo solve this problem, we will take all the characters in the strings. Length of str1 = m and length of str2 = n so we will create all interleaved strings from these strings.For printing all interleaving strings, we will fix characters of ... Read More

Print all internal nodes of a Binary tree in C++

sudhir sharma
Updated on 22-Jan-2020 11:22:32

2K+ Views

In this problem, we are given a binary tree and we have to print all internal nodes of the binary tree.The binary tree is a tree in which a node can have a maximum of 2 child nodes. Node or vertex can have no nodes, one child or two child nodes.Example −Internal Node is a node that can have at least one child i.e. non-leaf node is an internal node.Let’s take an example to understand the problem −Output − 7 4 9To solve this problem, we will traverse the binary tree using BFS(breadth-first search) traversal.While traversal we will push nodes ... Read More

Print all Jumping Numbers smaller than or equal to a given value in C++

sudhir sharma
Updated on 22-Jan-2020 11:18:45

888 Views

In this problem, we are given a number n and we have to print all jumping numbers that are smaller than or equal to n.Jumping Numbers are the number whose adjacent digits differ by one only. Some jumping numbers are 4565, 98, 7. All single-digit numbers are considered as jumping numbers. 235 is not a jumping number.Now, let’ take an example to understand the problemInput: N = 32 Output: 0 1 2 3 4 5 6 7 8 9 10 12 21 23 32To solve this problem, we will assume a graph where 0 is the starting node and traverse ... Read More

Print all k-sum paths in a binary tree in C++

sudhir sharma
Updated on 22-Jan-2020 11:16:03

545 Views

In this problem, we are given a binary tree and a number K and we have to print all paths in the tree which have the sum of nodes in the path equal k.Here, the path of the tree can start from any node of the tree and end at any node. The path should always direct from the root node to the leaf node. The values of the nodes of the tree can be positive, negative, or zero.Let’s take an example to understand the problem −K = 5Output −1 3 1 3 2 1 4To solve this problem, we ... Read More

Advertisements