UPD: I moved original question to https://codereview.stackexchange.com/questions/127055/building-tree-graph-from-dictionary-performance-issues
Here is a short version, without codes.
I'm trying to build a prefix tree from dictionary. So, using the following dictionary 'and','anna','ape','apple'
, graph should look like this:
I've tried 2 approaches: using associative array and using self-written tree/node classes.
Note: original dictionary is something about 8 MB and contains >600000 words.
Question: is there any good(fast/efficient) way to do it?
I've tried so far:
php associative arrays (they are not very flexible for future work with this graph).
self-written Tree/Node classes (performance issues - execution time rises by up to 7x, memory usage rises by 2x even without implementing anything except just
inserting
function).
Sample codes are available on codereview (the very first link in question)
array
or simple OOP implementation in sense of time of execution and memory usage on a large dictionary. – Alphard