Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 1463 of 3366
232 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
274 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
255 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
6K+ 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
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
865 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
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
125 Views
In this tutorial, we are going to learn how to delete the leaf nodes from a tree with the given value.Let's see the steps to solve the problem.Write a struct Node for a binary tree.Write a function to traverse (inorder, preorder, postorder) through the tree and print all data.Initialize the tree by creating nodes with the struct.Initialize the x value.Write a function to delete the leaf nodes with the given value. It accepts two arguments root node and k value.If the root is a null return.Replace the left node of the root with a new root after deletion.Same with the ... Read More
1K+ Views
In this tutorial, we are going to learn how to delete the leaf nodes from a tree with the given value.Let's see the steps to solve the problem.Write a struct Node for a binary tree.Write a function to traverse (inorder, preorder, postorder) through the tree and print all data.Initialize the tree by creating nodes with the struct.Initialize the x value.Write a function to delete the leaf nodes with the given value. It accepts two arguments root node and x value.If the root is a null return.Replace the left node of the root with a new root after deletion.Same with the ... Read More
21K+ Views
In this tutorial, we are going to learn how to delete elements from the given range. Let's see the steps to solve the problem.Initialize the array and range to delete the elements from.Initialize a new index variable.Iterate over the array.If the current index is not in the given range, then update the element in the array with a new index variableIncrement the new index.Return the new index.ExampleLet's see the code. Live Demo#include using namespace std; int deleteElementsInRange(int arr[], int n, int l, int r) { int i, newIndex = 0; for (i = 0; i < n; i++) ... Read More