• Lowest Common Ancestor (LCA):

    • The LCA of two nodes is the deepest node that is an ancestor of both.
    • Binary lifting can be used to efficiently compute LCA.
  • Diameter of a Tree:

    • The longest path between any two nodes in a tree.
    • Solved by performing two BFS or DFS:
      1. Find the farthest node from any node.
      2. From that node, find the farthest node again, which gives the diameter.
  • Binary Search Tree (BST) Operations:

    • Insertion, Deletion, and Search:
    struct Node {
        int key;
        Node *left, *right;
    
        Node(int k) : key(k), left(NULL), right(NULL) {}
    };
    
    Node* insert(Node* root, int key) {
        if (!root) return new Node(key);
    
        if (key < root->key)
            root->left = insert(root->left, key);
        else if (key > root->key)
            root->right = insert(root->right, key);
    
        return root;
    }