开发者

Efficiently implement a very large list, arrays? SPL linked list? anything else?

I have to create an really huge tree to solve the game of peg solitaire.

It has to be in PHP.

Although I have experience in PHP, it's mostly doing web dev, 开发者_运维技巧so I have no experience with memory management and large data structures, which I would normally handle in C++, but this is a test for a job.

I will solve it with some kind of backtracking with depth first search, so the tree doesn't get so huge, but at any point in time, I have to have a list of all the open nodes, which I plan to achieve with a simple array of references.

Is this efficient? should I do it with a SPL linked list or something else rather?

I already tested that an array can grow only limited by the RAM.


It seems to me that php handles array and object very efficiently, see here Does PHP take RAM when defining variable from variable and taking instance of object to another variable?. So maybe a binary tree would be good? You can also make your own extension if you are good in C++.


HAKMEM item 75 or Ins & Outs of Peg Solitaire (ISBN: 0-19-286145-X).

And don't use arrays.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜