Category: median-finding

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 = NULL;    return temp;}  Node* insertNode(Node* node, int key){            if (node == NULL)        return newNode(key);          if (key < node->key)        node->left = insertNode(            node->left, key);      else if (key > node->key)        node->right = insertNode(            node->right, key);          return node;}  void getIntermediateNodes(    Node* root, vector& interNodes,    int node1, int node2){        if (root == NULL)        return;          getIntermediateNodes(root->left,                         interNodes,                         node1, […]

Continue Reading

Calculate Median from given values of Mean and Mode

Given two integers mean and mode, representing the Mean and Mode of a random group of data, the task is to calculate the median of that group of data.Input: mean = 3, mode = 6Output: 4Input: mean = 1, mode = 1Output : 1Approach: The given problem can be solved by using the mathematical relationship […]

Continue Reading