Say i want to go over a linked list and just count the nodes that satisfy a particular condition. Later i would print value of some field in those nodes. I could go over the list again but the bigger the list the more time it would take.
I think i read before that one option is to store the pointers of the nodes of interest in an array of pointers. Is that a good solution? Are there better solutions?
I imagine there will always be comprimise between time and space. Would like to know what is the best solution for this problem.