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
Server Side Programming Articles - Page 1321 of 2646
270 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
881 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
146 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
436 Views
In this tutorial, we are going to learn how to delete an element with two loops and on loop. We don't need to delete the element. We will just replace the deleting element with the next elements.Two TraversalsLet's see the steps to delete an element from the array using two loops.Initialize the array and delete the element.Write a function to delete the element.Iterate over the array and search for the element.If the element found, break the loop.If the element is found, decrease the size of the array.Move all the elements to their previous index.Return the new size of the array.ExampleLet's ... Read More
730 Views
In this problem, we are given two integer values n and k. Our task is to find the Maximum number possible by doing at-most K swaps. Problem description: Here, we need to calculate the number which is maximum and created after swapping at-most k digits of the number.Let’s take an example to understand the problem, Input: n = 538 k = 1Output: 835Explanation: We will swap 8 and 5.Solution ApproachTo solve the problem, we need to swap digits of the number k times and check if the number from is maximum. We need to find the maximum digit of the number and then swap the ... Read More