I want to code a class named tree for creating the Data Type Tree . I want a function inside class tree which will automatically create nodes and insert values in nodes level-wise( row-wise ). For this I have also created Queue Data Type to store addresses of the left and right of a node ..

#### Category : tree

I need to traverse a tree in my C++ code for a large number of times, the depth of the tree can vary from one iteration to another. I might also conditionally early break from the tree traversal. While profiling my code (using Visual studio compiler), I noticed that the tree traversal part was the ..

I make a program to create binary tree, but i got Process returned -1073741819 (0xC0000005) i take -1 to indicate no child here is my code #include<bits/stdc++.h> using namespace std; class node { public: int data; node*lchild; node*rchild; }; class tree { public: node*root; tree() { root=nullptr; } void createTree() { int x;node*p,*tmp; p=tmp=nullptr; deque<node*>s; ..

Please help me out with this problem: https://cses.fi/problemset/task/1131/ I’m getting the wrong output for large values. The algorithm is: computing the height of the left subtree and the right subtree by using an arbitrary node. Thank you ðŸ™‚ #include <bits/stdc++.h> #define int long long int using namespace std; bool visited[200005] = {false}; vector<vector<int>> vect(200005); int ..

I want to insert an object of created type (Fruit) in BST, but at the point of code to be inserted when (fruit==null) i think there is a problem i cant solve, because after inserting objects the root still null(no any children) . Fruit* insert(Fruit* fruit,Fruit f){ if(fruit == NULL){ Fruit ftemp = *new Fruit() ..

I was upsolving this question after the contest on codechef.After reading and watching solution, and referring to tester’s solution, i implemented my solution bit different from solutions i have seen(believing that it will work as far as i understand it should). Trying to keep solution simple and minimal compared to solutions i came across. Let ..

Please read the problem statement here what i have done is, i am trying to find deepest vertex among given nodes in query. after that i am finding distance between deepest vertex and given nodes(of subtree) in the query way i am finding distance between nodes is, depth[deepest_v] + depth[v] – 2 * depth[LCA(deepest_v, v)] ..

I am trying to solve this program.The solution requires a traversal of the tree. The important things to check are to make sure that all corner cases are handled. The corner cases include an empty tree, single-node tree, a node with only the left child and a node with the only right child. In tree ..

I have to implement a general tree en C++ for one of my class, and I come across a problem I don’t understand. I have two classes, EmployeeNode and EmpoyeeTree. EmployeeNode contains the data elements needed for the work : a string name, an EmployeeNode parent and a List<EmployeeNode> children which is a linked list ..

In the below code root contains the root of our tree and sum contains our result. This code seems fine to me but when i submitted it on the GFG :- Largest Bst in a binary tree it is giving error please help. int po(Node *root,int &sum){ if(root==NULL) return 0; int p=po(root->left,sum); int q=po(root->right,sum); int ..

## Recent Comments