Category : tree

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 ..

Read more

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 ..

Read more

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; ..

Read more

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 ..

Read more

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 ..

Read more