Monday, January 21, 2019

A graph trick

I have a graph, it has left, right and parent links. Consider he simple case first, mo cycles.

I want to select any node and construct the new directed graph with the selected node as root. I need  recursion to explore each node once, and emit that node to a new transformed graph.

recurs(link) {
emit this node then
if link has a left then recurse node:left
if link has a right then recurse node:right
if link has a parent recurse node:parent
}

In my emit function I can systematically map from [left,right,parent] to any other ordering on the new nodes. My emit unction can also sort them on  different field, but it cannot eliminate dups, it needs an equal or greater than without burping on dups. If the dups are emitted in order, they can be index, and the graph transform should have a reversal.

If the graph has cycles, then the recursion needs to mark nodes as visited, and the exploration should still be complete without duplicate visits.

Th symbol tables are all sorted 64 bit longs.  Consider the case where you had the SP500 corporate set sorted by size, and you wanted a sort by inventory rollover ratio.  To have a corporation is to have a standard balance sheet, so we have the algorithm to extract the ratio.  Create new keys using the 64 bit long ration scaled to units that span the set, 16 significant digits should be more than enough. So you have a emit that computes the ration, set the key value to that and insets the balance sheet back onto the symbol tree with  different root that you hold. The two trees are homomorphic, meaning  a by node transfomation,  but segmented. The key value in every case is a pointer back to the balance sheet, and sheets can be sorted on any standard accounting variable.

OK, let us advance the solution,  Let us say you experimented with different ratios and accounts to sort with until you found the algorithm that sort a balanced tree, all paths from root to branch nearly the same length. Then you have an index, and there should be a formula that takes you from the index to an optimum investment across the whole set. Pretty sure this holds.

No comments: