Wednesday, October 26, 2016

Traversing the tree

g.(a.((x,y),(e,c.(i,j),d)),z,y,(q,r))

The syntax is complete, and is a spanning tree with the root at g.  It is therefore, a nested block structure, except you have to count parenthesis, left plus and right minus, to mark block bounds.  This is really python or javascript like script.

If  all tokens are stored in a linear array, with no empty spaces, then  what is the index of c, right in the middle?  As it is written, we start at the top, and follow the dots first, commas second. and count tokens on the way.  You will find c and the accumulated token count is its position in the array.

Make it easier, dump the parenthesis pairs and keep the count of elements within a bloc.  Now we have additional clues when hunting for c, we know its block count. c can never exist in any enclosing element that has a smaller block count, we can shorten the search for c, as long as we maintain block counts.

Does this pay off?  Yes if, a big if, if c is a big sub graph, its count, which is maintained, will be larger than most sub-graphs in the tree. No, if not, the cost of the extra check does not pay.

Their is a related trade off.  Why not maintain the index in the individual graph nodes.  Might work, except the indices have to be updated down the chain whenever a move is made up the chain.  But, if you are not doing a lot of moves, maintaining indices works, its cheap.  Another choice is the just scan the whole array.  But you are often interested in c because you need its path or path length which is mostly not its linear index, you want yo follow itys path.e

Choices on tree traversal depend on the application.  It matters in a fast moving market, if the bot see major market moves,the bot will be shifting around the blocks close to the root, large blocks, as it maintains a liquid tree.  But, the normal day trades will always skip down to the bottom before they effect liquidity. The last thing we want is for the server bot get caught in a spiral of restructuring as big players manipulate.  The central banker bot, the Yellen spreadsheet function, is a costly trip on the graph, remember, the sitre owner picks up nickels for trips on the graph.  It the site bot is stuck on the graph constantly, trader bots never get cycles,and t=your fees drop.

No comments: