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: 3784079 • 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

Because the search and moving is combined in the first case and the search is just extra work in the second case.

Comparing integers is cheap, compared to moving integers around. Account for divisions, loop overhead, taken conditional jumps in every loop iteration vs. non-taken cond jumps, etc ...

PS. Indeed, in the linear search version, the inner loop is typical to look like:

where the jge .L3 is executed only once and one can reasonably expect that branch to be predicted non-taken and not have a detrimental effect on the pipeline.

As for the inner loop in the other version, I don't want to look at it :)

PS. BTW, the linear search has also somewhat better locality, whereas the binary search jumps all over the place.

4down vote

Because the search and moving is combined in the first case and the search is just extra work in the second case.

Comparing integers is cheap, compared to moving integers around. Account for divisions, loop overhead, taken conditional jumps in every loop iteration vs. non-taken cond jumps, etc ...

PS. Indeed, in the linear search version, the inner loop is typical to look like:

      .L5:      leaq    -1(%rcx), %rsi      movl    4(%rdi,%rsi,4), %eax      cmpl    %eax, %r9d      jge .L3      movq    %rcx, %r8      movq    %rsi, %rcx      subl    $1, %edx      movl    %eax, 4(%rdi,%r8,4)      cmpl    $-1, %edx      jne .L5      movq    $-1, %rcx  .L3:    

where the jge .L3 is executed only once and one can reasonably expect that branch to be predicted non-taken and not have a detrimental effect on the pipeline.

As for the inner loop in the other version, I don't want to look at it :)

PS. BTW, the linear search has also somewhat better locality, whereas the binary search jumps all over the place.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote