# Tree

### Kth largest element in an N-array Tree

#include using namespace std;  class Node {public:    int data;    vector childs;};  int largestELe = INT_MIN;  void largestEleUnderRange(    Node* root, int data){            if (root->data < data) {        largestELe =…

### Construct a Binary Tree from String with bracket representation | Set 2

#include using namespace std;  struct Node {    Node* left;    Node* right;    int data;              Node(int element)    {        data = element;        this->left = nullptr;        this->right = nullptr;    }};  void preorder(Node* root){    if (!root)        return;      cout data…

### Minimum time required to color all edges of a Tree

#include using namespace std;  int ans = 0;  vector edges[100000];  void Add_edge(int u, int v){    edges[u].push_back(v);    edges[v].push_back(u);}  void minTimeToColor(int node, int parent,                    int arrival_time){            int current_time = 0;      for…

### Test Case Generation | Set 6 (Random Unweighted Binary Tree)

#include using namespace std;    vector generateBinaryTree(int n){                        vector options = { 0, 1, 2 };                        map mp;                queue q;            q.push(1);            vector v;                int count = 1;                mp[1] =…

### Print greater elements present on the left side of each array element

Print greater elements present on the left side of each array elementGiven an array arr[] consisting of N distinct integers,…

### Count substrings having frequency of a character exceeding that of another character in a string

#include using namespace std;void update(int ind, vector& segTree,            int n){        ind += n;        segTree[ind]++;    for (; ind > 1; ind >>= 1) {                segTree[ind >>…

### Queries to find the sum of weights of all nodes with vertical width from given range in a Binary Tree

#include using namespace std;  struct Node {    int data;    Node* left;    Node* right;};  Node* newNode(int d){    Node* n = new Node;    n->data = d;    n->left = NULL;    n->right =…

### Median of all nodes from a given range in a Binary Search Tree ( BST )

#include using namespace std;  struct Node {    struct Node *left, *right;    int key;};  Node* newNode(int key){    Node* temp = new Node;    temp->key = key;    temp->left = temp->right…