資料結構›Ch9 進階樹
第 39 題/共 88 題
◀ DS 39/88
39. B-Tree、Node Definition
#DS-09-039易B-TreeNode Definition
題組題幹(本題:(D)(E),共 2 小題)點擊展開

There are 5 questions. The following contains two functions for traversing a binary tree:

struct Node
{
    char key;
    Node * left, * right;
};

void trv1(Node* root)
{
    std::queue<Node*> Q;
    Q.push(root);
    while (!Q.empty()) {
        Node* cur = Q.front();
        Q.pop();
        printf("%c", cur->key);
        if (cur->left) Q.push(cur->left);
        if (cur->right) Q.push(cur->right);
    }
}

void trv2(Node* root)
{
    std::stack<Node*> Q;
    Q.push(root);
    while (!Q.empty()) {
        Node* cur = Q.top();
        Q.pop();
        printf("%c", cur->key);
        if (cur->right) Q.push(cur->right);
        if (cur->left) Q.push(cur->left);
    }
}

(D) [3%] A node of a B-tree is modified from the tree node definition above such that a node can hold up to M distinct keys (in an array named key) and M+1 pointers to child nodes (in an array named child), where M is a positive integer. For a B-tree node with all its keys and child node pointers being valid, list the requirements of the key values in the subtrees rooted at the nodes pointed to by child with respect to the key values in key.

(E) [2%] In B-trees, to minimize the tree depth, each non-leaf node (except for the root) is required to keep at least K valid keys. Specify K with respect to M.

📄 交大113
跳轉到第題
▤完整推導請見《WH 資工筆記 · 資料結構》Ch9 進階樹
本章題號 · 21–40 / 88