Finding the level of a certain node in a tree fast
I recently received a task at my university, which was to construct a tree
from a certain input, find a certain node within the tree, then return the
level at which the node was found.
That was not really a problem, but it's a very competitive scene, and I
saw a lot of other students managing to get the time down to around 70 ms
(mine took around 1400 ms to run) in Python, and some got the time down to
0 with other languages I didn't code in, like D, C and C++ (rounding
errors aside, are these designed to be better at this kind of problem?).
My question is basically a general one, about how to improve the
efficiency of scripts solving this, and similar types of problems. Thanks
in advance for any and all answers!
No comments:
Post a Comment