Ayush Gupta

Ayush Gupta

433 Articles Published

Articles by Ayush Gupta

Page 33 of 44

Convert a Binary Tree such that every node stores the sum of all nodes in its right subtree in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 196 Views

In this tutorial, we will be discussing a program to convert a binary tree such that every node stores the sum of all nodes in its right subtree.For this, we will be provided with a binary tree. Our task is to return another tree where every node must be equal to the sum of the node and its right subtree.Example#include using namespace std; //node structure of tree struct Node {    int data;    Node *left, *right; }; //creation of a new node struct Node* createNode(int item){    Node* temp = new Node;    temp->data = item;    temp->left ...

Read More

Convert a Binary Tree to a Circular Doubly Link List in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 188 Views

In this tutorial, we will be discussing a program to convert a binary tree to a circular doubly linked list.For this, we will be provided with a binary tree. Our task will be to convert the left and right nodes to the left and right elements respectively. And take the inorder of the binary tree to be the sequence order of the circular linked listExample#include using namespace std; //node structure of the binary tree struct Node{    struct Node *left, *right;    int data; }; //appending rightlist to the end of leftlist Node *concatenate(Node *leftList, Node *rightList){    //if one ...

Read More

Convert a Binary Tree to Threaded binary tree | Set 1 (Using Queue) in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 542 Views

In this tutorial, we will be discussing a program to convert a binary tree to a threaded binary tree using a queue data structure.For this, we will be provided with a binary tree. Our task is to convert that particular binary tree into a threaded binary tree by adding additional routes for quicker inorder traversal with the help of a queue data structure.Example#include #include using namespace std; //node structure for threaded tree struct Node {    int key;    Node *left, *right;    bool isThreaded; }; //putting the inorder pattern into a queue void convert_queue(Node* root, std::queue* q){ ...

Read More

Convert a BST to a Binary Tree such that sum of all greater keys is added to every key in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 153 Views

In this tutorial, we will be discussing a program to convert a BST to a binary tree such that the sum of all greater keys is added to every key.For this, we will be provided with a Binary Search tree. Our task is to convert that tree into a binary tree with the sum of all greater keys added to the current key. This will be done by the reverse in order of the given BST along with having the sum of all the previous elements and finally adding it to the current element.Example#include using namespace std; //node structure ...

Read More

Convert a given Binary tree to a tree that holds Logical AND property on C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 199 Views

In this tutorial, we will be discussing a program to convert a given Binary tree to a tree that holds Logical AND property.For this we will be provided with a binary tree. Our task is to convert it into a tree that holds the logical AND property means that a node has a value of the AND operation of its children nodes. Note that every node can have a value either zero or one.Example#include using namespace std; //node structure of binary tree struct Node{    int data;    struct Node* left;    struct Node* right; }; //creation of a new ...

Read More

Convert a given Binary Tree to Doubly Linked List (Set 1) in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 270 Views

In this tutorial, we will be discussing a program to convert a binary tree to a doubly linked list.For this we will be provided with a binary tree. Our task is to convert it into a doubly linked list such that the left and right pointers become the previous and next pointers. Also the sequential order of the doubly linked list must be equal to the inorder traversal of the binary tree.For this we are having a very straight forward approach. We will be traversing the binary tree in in order way making the nodes of the doubly linked list ...

Read More

Convert a given Binary Tree to Doubly Linked List (Set 2) in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 203 Views

In this tutorial, we will be discussing a program to convert a binary tree to a doubly linked list.For this we will be provided with a binary tree. Our task is to convert it into a doubly linked list such that the left and right pointers become the previous and next pointers. Also the sequential order of the doubly linked list must be equal to the inorder traversal of the binary tree.For this we are having a different approach. We will be traversing the binary tree in reverse inorder way. Along with we will be creating new nodes and moving ...

Read More

Convert a normal BST to Balanced BST in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 285 Views

In this tutorial, we will be discussing a program to convert a normal binary search tree to balanced binary search tree.For this we will be provided with a skewed binary search tree either left or right. Our task is to convert it into a balanced binary search tree following a certain set of rules.Example#include using namespace std; //node structure of tree struct Node{    int data;    Node* left, *right; }; //traversing tree and storing node pointers //in vector nodes void store_nodes(Node* root, vector &nodes){    if (root==NULL)       return;    store_nodes(root->left, nodes);    nodes.push_back(root);    store_nodes(root->right, ...

Read More

Convert a number into negative base representation in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 357 Views

In this tutorial, we will be discussing a program to convert a number into its negative base representation.For this we will be provided with a number and the corresponding negative base. Our task is to convert the given number into its negative base equivalent. We are allowing only values between -2 and -10 for negative base values.Example#include using namespace std; //converting integer into string string convert_str(int n){    string str;    stringstream ss;    ss > str;    return str; } //converting n to negative base string convert_nb(int n, int negBase){    //negative base equivalent for zero is zero ...

Read More

Convert a number m to n using minimum number of given operations in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 857 Views

In this tutorial, we will be discussing a program to convert a number m to n using minimum number of given operations.For this we will be provided with two integers m and n. Our task is to convert the integer m to n using the given operations least times.Allowed operations −Multiply the given number by 2Subtract one from the given numberExample#include using namespace std; //finding minimum number of operations required int convert(int m, int n){    if (m == n)       return 0;    if (m > n)    return m - n;    //can't convert in ...

Read More
Showing 321–330 of 433 articles
« Prev 1 31 32 33 34 35 44 Next »
Advertisements