Sunday, 28 Nov 2021
Category: median-finding

#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, […]

Given an array arr[] consisting of N positive integers, the task is to find an array element X such that sum of its absolute differences with every array element is minimum.Examples:Input: arr[] = {1, 2, 3, 4, 5}Output: 3Explanation:For element arr[0](= 1): |(1 – 1)| + |(2 – 1)| + |(3 – 1)| + |(4 […]

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 […]