Finding the farthest point in one set from another set

前端 未结 6 1721
旧巷少年郎
旧巷少年郎 2021-02-06 12:05

My goal is a more efficient implementation of the algorithm posed in this question.

Consider two sets of points (in N-space. 3-space for the example case of RGB colorsp

6条回答
  •  误落风尘
    2021-02-06 12:22

    EDIT: I meant nlog(n) where n is the sum of the sizes of both sets.

    In the 1-Space set I you could do something like this (pseudocode)

    Use a structure like this

    Struct Item {
        int value
        int setid
    }
    

    (1) Max Distance = 0
    (2) Read all the sets into Item structures
    (3) Create an Array of pointers to all the Items
    (4) Sort the array of pointers by Item->value field of the structure
    (5) Walk the array from beginning to end, checking if the Item->setid is different from the previous Item->setid if (SetIDs are different)
    check if this distance is greater than Max Distance if so set MaxDistance to this distance

    Return the max distance.

提交回复
热议问题