Found 7347 Articles for C++

Deserium Number with examples in C++ Program

Hafeezul Kareem
Updated on 27-Jan-2021 12:26:05

79 Views

In this tutorial, we are going to learn about the deserium numbers with examples.The number whose sum of pow(digit, digitsCount) is equal to the given number is called Deserium number.Let's see the steps to find whether the given number is deserium number or not.Initialize the number.Find the digits count of the number.Initialize a variable to store the sum.Iterate until the number is less than 0.Get the last digit by diving the number with 10.Add the pow(digit, digitsCount) to the sum.If the sum is equal to the number, then it is deserium number else it is not.ExampleLet's see the code. Live Demo#include ... Read More

Depth of the deepest odd level node in Binary Tree in C++ Program

Hafeezul Kareem
Updated on 27-Jan-2021 12:24:53

71 Views

In this tutorial, we are going to learn how to find the deepest odd level node in a binary tree.This is similar to finding the depth of the binary tree. Here, we have to one more condition i.e.., whether the current level is odd or not.Let's see the steps to solve the problem.Initialize the binary tree with dummy data.Write a recursive function to find the deepest odd level node in a binary tree.If the current node is a leaf node and the level is odd, then return the current level.Else return the max of left node and right node with ... Read More

Depth of an N-Ary tree in C++ Program

Hafeezul Kareem
Updated on 27-Jan-2021 12:22:15

849 Views

In this tutorial, we are going to learn how to find the depth of the n-ary tree.An n-ary tree is a tree in which each node of the tree has no more than n child nodes.We have to find the depth of the n-ary tree. We will be using the vector to store the children of each node in the tree.Let's see the steps to solve the problem.Initialize the tree with dummy data.Write a recursive function to find the depth of the n-ary tree.Initialize a variable to store the max depth of the tree.Iterate over the children of each node.The ... Read More

Demlo number, Square of 11...1 in C++ Program

Hafeezul Kareem
Updated on 27-Jan-2021 12:19:32

128 Views

In this tutorial, we are going to learn about the demlo number.The demlo numbers are the squares of the number 1, 11, 111, 1111, etc.., We can easily find the demlo number as it is in the form 1 2 3 4 5 ... n-2 n-1 n n-1 n-2 ... 5 4 3 2 1.Here, we are given a number which has only ones. And we need to find the demlo number of that number. Let's see an example.Input − 1111111Output − 1234567654321Let's see the steps to solve the problem.Initialize the number in a string format.Initialize an empty string to ... Read More

Density of Binary Tree in One Traversal in C++ Program

Hafeezul Kareem
Updated on 27-Jan-2021 12:20:55

213 Views

In this tutorial, we are going to learn how to find the density of the binary tree in a single traversal.The density of the binary tree is obtained by dividing the size of the tree by the height of the tree.The size of the binary tree is the total number of nodes present in the given binary tree.The height of the binary tree is the max depth of the leaf node from the root node.Let's see the steps to solve the problem.Initialize the binary tree dummy data.Find the size and height of the tree.Recursively count the height of the tree.Return ... Read More

Deletions of “01” or “10” in binary string to make it free from “01” or “10” in C++ Program

Hafeezul Kareem
Updated on 27-Jan-2021 12:15:32

173 Views

In this tutorial, we are going to write a program that finds the total number of pairs (01 or 10) to free the binary string from the pairs (01 and 10). Let's see an example.Input − 101010001Output − 4In the above example, we have to delete a total of 4 pairs to free the binary string from the pairs (01 and 10).The resultant string after deleting all the pairs is 0.We have to delete all the 01 and 10 pairs from the binary string. So, the total number of pairs to be deleted is the minimum of count(1) and count(0).Let's ... Read More

Deletion in a Binary Tree in C++ Program

Hafeezul Kareem
Updated on 27-Jan-2021 12:14:23

5K+ Views

In this tutorial, we are going to learn how to delete a node in a binary tree.The nodes in a binary tree don't follow any order like binary search trees. So, how to arrange the nodes after deleting a node in a binary tree?Well, we will replace the deepest node of the tree with the deleting node. And then we will delete the deepest node from the node.Let's see the steps to solve the problem.Initialize the tree with binary node struct.Write a function (preorder, in order, and postorder) to print the nodes of the tree.Write a function to delete the ... Read More

Deleting a binary tree using the delete keyword in C++ program

Hafeezul Kareem
Updated on 27-Jan-2021 12:11:35

2K+ Views

In this tutorial, we are going to learn how to delete a binary tree using the delete keyword.We are going to use a destructor member function to delete the binary. The destructor member function is invoked automatically when the object goes out of the scope or it is destroyed by calling delete.The destructor member function has the name as a class with tilde (~) before it.Let's see the steps to solve the problem.Write a class called Node.Write a constructor function that accepts data for the node.Write a destructor function.Delete the left node.Delete the right node.Print the current node data.Initialize the ... Read More

Delete N nodes after M nodes of a linked list in C++ program

Hafeezul Kareem
Updated on 27-Jan-2021 12:08:51

745 Views

In this tutorial, we are going to learn how to delete N nodes after M nodes in a linked list.Let's see the steps to solve the problem.Write a struct Node for the linked list node.Initialize the linked list with the dummy data.Write a function to delete N nodes after M nodes.Initialize a pointer with the head pointer.Iterate till the end of the linked list.Move the pointer to the next node until M nodes.Delete the N nodesMove the pointer to the next nodePrint the linked listExampleLet's see the code. Live Demo#include using namespace std; struct Node {    int data;   ... Read More

Delete middle of linked list in C++ program

Hafeezul Kareem
Updated on 27-Jan-2021 12:06:58

3K+ Views

In this tutorial, we are going to learn how to delete the middle node in a linked list.The solution to the problem is straightforward. We will have two pointers one moves one node at a time and the other one moves two nodes at a time. By the time the second pointer reaches the final node, the first will be in the middle of the linked list.Let's see the steps to solve the problem.Write a struct Node for the linked list node.Initialize the linked list with the dummy data.Write a function to delete the linked list.Initialize two-pointers (slow and fast) ... Read More

Advertisements