miroslavbroz / tree

Probably the simplest implementation of a tree, k-d tree, kd-tree, 2-dimensional tree, or whatever name it has...

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tree implementation in Fortran or Python

A tree is a structure like this:

              [tree%root]                                 
            /              \                              
      [left]                [right]         ---> x, sorted
     /      \              /       \                      
[left]       [right] [left]         [right] ---> y, sorted

It is used to find a nearest neighbor like this:

  p +  [node.p]        
      /        \       
[left]          [right]
                       
            <------>   
              diff     
                       
---------------------->
          axis = x or y

if p in on the left from [node.p], open [left]
only if diff < best, open [right]!
otherwise, it can hardly be closer
because left-node-right are closest, sorted in x (or y)

See test.f90 for a comparison of this nearest-neighbor search and a brute-force.

About

Probably the simplest implementation of a tree, k-d tree, kd-tree, 2-dimensional tree, or whatever name it has...


Languages

Language:Python 79.0%Language:Fortran 20.5%Language:Makefile 0.4%Language:Shell 0.2%