DFS

- Binary Search Tree, Binary Search Trees, DFS, Mathematical, Recursion, Tree

Sum of all nodes with smaller values at a distance K from a given node in a BST

  #include using namespace std;  struct TreeNode {      int data;    TreeNode* left;    TreeNode* right;          TreeNode(int data)    {        this->data = data;        this->left = NULL;        this->right = NULL;    }};  void kDistanceDownSum(TreeNode* root,                      int k, int&…

Read More

- Algorithms-Graph Traversals, BFS, DFS, Graph

Find all the Mother Vertices of a graph

  #include using namespace std;  void dfs_helper(int u,                vector& adj,                bool visited[]){    if (visited[u])        return;      visited[u] = true;      for (auto v : adj[u]) {        if (!visited[v])            dfs_helper(v, adj, visited);    }}  void getTransposeGraph(    vector&…

Read More