recategorized by
56 views
0 0 votes

IIT Bombay | MS/PhD Admission Test Dec. 2024 | Question-27

Below is a partially implemented C code for searching within a $\mathrm{B}+$ tree in a database. The function search_bplus_tree() is responsible for finding a key within the tree.

Some parts of the code are missing. Your task is to choose the correct option to fill in the blanks.

Note that when the search key is equal to the key at index i in the current node, the search continues by following the right child pointer, which is children [ $i+1$ ]. This ensures that the search navigates into the correct subtree, as the actual data is stored in the leaf nodes.
 

typedef struct BPlusTreeNode {
        int keys[order];
        struct BPlusTreeNode* children[order + 1];
        int is_leaf;
        int num_keys;
} BPlusTreeNode;
int search_bplus_tree(BPlusTreeNode* root, int key) {
    BPlusTreeNode* current_node = root;
    while (!current_node->is_leaf) {
        int i = 0;
    // Traverse the node's keys to find the correct child node
        while (_________1_________ && _________2_________) {
            i++;
    }
    // Move to the appropriate child node
__-_-_-__3__-_-_-__-_;
}
// Perform search on the leaf node to find the key
    for (int i = 0; i < current_node->num_keys; i++) {
        if (current_node->keys[i] == key) {
              return 1; // Key found
        }
    }
    return 0; // Key not found
}


What condition should be the corner condition to break out of the loop? [2 marks]

  1. $\mathrm{i}<$ order
  2. $\mathrm{i}$ $<=$ order
  3. $\mathrm{i}$ $<$ current_node → num_keys $-1$
  4. $\mathrm{i}$ $<=$ current_node → num_keys $-1$

     

Please log in or register to answer this question.

Position:
Show:

Related questions

0 0 votes
0 0 answers
119
119 views
Shubham Sharma 2 asked Dec 8, 2025
119 views
Consider the following lex script%% a(b|cd)*b {printf("%s#",yytext); } a(b|cd)*cd {printf("%s#",yytext); } a+b*d {printf("%s#",yytext); }Tokenize the given input strings ...
0 0 votes
0 0 answers
119
119 views
Shubham Sharma 2 asked Dec 8, 2025
119 views
Consider the following augmented grammar:$\text{S'} \rightarrow \text{S}$$\text{S} \rightarrow \text{A a}$$\text{A} \rightarrow \text{B C}$$\text{A} \rightarrow \text{B C...
0 0 votes
0 0 answers
122
122 views
Shubham Sharma 2 asked Dec 8, 2025
122 views
Consider the syntax-directed translation (SDT) scheme, in the form of the rules listed below, to generate three-address code for a simple expression grammar. The attribut...
0 0 votes
0 0 answers
82
82 views
Shubham Sharma 2 asked Dec 8, 2025
82 views
Consider the following C program. Assume the presence of necessary header files.int Sub(int i, int j) { return i - j; } int Mul(int i, int j) { return i * j; } int Delta(...