Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Let S be a set of n points in the plane. A split tree is a special binary tree t

ID: 3784081 • Letter: L

Question

Let S be a set of n points in the plane. A split tree is a special binary tree that stores all the points in S. The root of the split tree stores the point p with the median r-coordinate among all points in S. This splits S into two sets, Sieh and Sight, which consist of the points to the left and right of p, respectively. The left child is a split tree on Sien and the right child is a split tree on Sighr. But there is a twist: their root stores the point with the median y-coordinate and splits the rest of the points based on their y-coordinate, not a-coordinate. The direction of the split alternates with each level. See Figure 2 for an example. are indicated in blue, while horizontal splits (on y-coordinate) are red.

Explanation / Answer

#include #include #include using namespace std; struct BTreeNode { int *data; BTreeNode **child_ptr; bool leaf; int n; }*root = NULL, *np = NULL, *x = NULL; BTreeNode * init() { int i; np = new BTreeNode; np->data = new int[5]; np->child_ptr = new BTreeNode *[6]; np->leaf = true; np->n = 0; for (i = 0; i < 6; i++) { np->child_ptr[i] = NULL; } return np; } void traverse(BTreeNode *p) { coutchild_ptr[i]); } cout child_ptr[i]); } coutdata[2] = 0; x->n--; np1 = init(); np1->leaf = false; x->leaf = true; for (j = 3; j < 5; j++) { np3->data[j - 3] = x->data[j]; np3->child_ptr[j - 3] = x->child_ptr[j]; np3->n++; x->data[j] = 0; x->n--; } for (j = 0; j < 6; j++) { x->child_ptr[j] = NULL; } np1->data[0] = mid; np1->child_ptr[np1->n] = x; np1->child_ptr[np1->n + 1] = np3; np1->n++; root = np1; } else { y = x->child_ptr[i]; mid = y->data[2]; y->data[2] = 0; y->n--; for (j = 3; j < 5; j++) { np3->data[j - 3] = y->data[j]; np3->n++; y->data[j] = 0; y->n--; } x->child_ptr[i + 1] = y; x->child_ptr[i + 1] = np3; } return mid; } void insert(int a) { int i, temp; x = root; if (x == NULL) { root = init(); x = root; } else { if (x->leaf == true && x->n == 5) { temp = split_child(x, -1); x = root; for (i = 0; i < (x->n); i++) { if ((a > x->data[i]) && (a data[i + 1])) { i++; break; } else if (a data[0]) { break; } else { continue; } } x = x->child_ptr[i]; } else { while (x->leaf == false) { for (i = 0; i < (x->n); i++) { if ((a > x->data[i]) && (a data[i + 1])) { i++; break; } else if (a data[0]) { break; } else { continue; } } if ((x->child_ptr[i])->n == 5) { temp = split_child(x, i); x->data[x->n] = temp; x->n++; continue; } else { x = x->child_ptr[i]; } } } } x->data[x->n] = a; sort(x->data, x->n); x->n++; } int main() { int i, n, t; coutn; for(i = 0; i