Ask YC: Data structure or Algorithm selection for a problem?
data structure or algorithm which one is more important in solving a problem
and how selection of both is important in solving a problem
and how selection of both is important in solving a problem
9 comments
[ 1.9 ms ] story [ 30.1 ms ] threadParticular algorithms operate on particular data structures; a binary search on a sorted list makes sense, while a binary search on an unsorted list is meaningless. It doesn't make any sense to have one of "a good algorithm" or "a good data structure" without the other.
I usually visualize the data structure that exists, or that I want, and work "backwards" from there. But whichever direction you use, always always remember that the idea is to make the design simpler and more clear.
Use the data structure that makes the design more efficient. Clarity might be nice, but an O(n) solution is not acceptable when a reasonable O(log n) or O(1) solution exists.
http://www.amazon.com/Introduction-Algorithms-Thomas-H-Corme...
Good advanced text: Jon Kleinberg/Eva Tardos: Algorithm Design
http://www.amazon.com/Algorithm-Design-Jon-Kleinberg/dp/0321...