📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    When building a Huffman tree, the two nodes with the

    smallest frequencies are combined. Which line correctly creates a new parent node newNode with left and right children and its data (frequency)? // Assume Node class has data, left, right members // Node* l and Node* r are the two lowest frequency nodes Node* newNode = new Node(__________); // Line to complete newNode->left = l; newNode->right = r;
    A l->data + r->data Correct Answer Incorrect Answer
    B max(l->data, r->data) Correct Answer Incorrect Answer
    C min(l->data, r->data) Correct Answer Incorrect Answer
    D l->data * r->data Correct Answer Incorrect Answer
    E l->data - r->data Correct Answer Incorrect Answer

    Solution

    Correct Answer: A • Code Analysis: o l and r are pointers to the two nodes with the smallest frequencies. o newNode is being created, and its data member needs to store the combined frequency. • Explanation of Correct Answer (A): l->data + r->data o The fundamental principle of Huffman tree construction is that the frequency (or weight) of a parent node is the sum of the frequencies of its left and right children. This ensures that the total frequency of the subtree is correctly represented.

    Practice Next
    ask-question