4 ms·
I often come across developers who only think to use data structures that are native to their language (a Sapir-Whorf trap, if you will). For example, in JavaS
by joubert 13y ago
I often come across developers who only think to use data structures that are native to their language (a Sapir-Whorf trap, if you will).
For example, in JavaScript, we essentially have arrays (great for tracking order, O(n) lookup) and objects (great for O(1) lookup, no order), but that doesn't mean you can't:
a) implement other data structures such as doubly linked lists, heaps, red black trees, etc.
b) combine the strengths of two different data structures in a new object
I think it was Bill Gates who emphasized the importance of picking good data structures up front.
A book I recommend for learning how to implement data structures (and concomitant algorithms) is: Introduction to Algorithms (http://mitpress.mit.edu/books/introduction-algorithms http://mitpress.mit.edu/books/introduction-algorithms)
It is also useful to have some heuristic for picking data structures, and I have found the recipe proposed by Gayle Laakmann in her book, Cracking the Coding Interview, useful in most non-esoteric cases.
- kmfrk 13y agoThe Algorithm Design Manual is basically an algorithm cookbook, which makes for a nice companion book.
- kibwen 13y agoI don't know about Bill Gates, but this quote from Linus Torvalds sprang to mind: "I will, in fact, claim that the difference between a bad programmer and a good one is whether he considers his code or his data structures more important. Bad programmers worry about the code. Good programmers worry about data structures and their relationships." http://lwn.net/Articles/193245/ http://lwn.net/Articles/193245/