Confused by the definition of "median" when building a kd-tree

I am trying to build a kd tree to search for multiple points, but I am confused about using the "median" in the wikipedia article. For ease of use, the wikipedia article indicates the pseudo-code of the kd-tree structure as:

function kdtree (list of points pointList, int depth)
{
    if pointList is empty
        return nil;
    else
    {
        // Select axis based on depth so that axis cycles through all valid values
        var int axis := depth mod k;

        // Sort point list and choose median as pivot element
        select median by axis from pointList;

        // Create node and construct subtrees
        var tree_node node;
        node.location := median;
        node.leftChild := kdtree(points in pointList before median, depth+1);
        node.rightChild := kdtree(points in pointList after median, depth+1);
        return node;
    }
}

I got confused in the line "select median ...", simply because I'm not quite sure what the "correct" way to use the median is here.

, () (, 5 , 3 2 ), - "" , (, 6 , 3 4 - 2 3, - 2.).

, , , ? , 2?

, !

-Stephen

+3
2

, , - . ?

, Wikipedia, . , node . - , , split () , , . node, . :

First step (root node):
Original set: 1 2 3 4 5 6 7 8 9 10
Split value (median): 5.5

Second step - left subtree:
Set: 1 2 3 4 5
Split value (median): 3

Second step - right subtree:
Set: 6 7 8 9 10
Split value (median): 8

Third step - left subtree of left subtree:
Set: 1 2
Split value (median): 1.5

Third step - right subtree of left subtree:
Set: 3 4 5
Split value (median): 4

Etc.

, node (, ), . , .

+2

, . , , , .

0

Source: https://habr.com/ru/post/1747496/


All Articles