This is a good question, and an insight that is hard to pass on to people who don't "get it" yet.
You need to understand a collection of basic algorithms for searching, sorting, and graph traversal. You need to know how they work well enough that you can recreate them from memory. You need to know which ones are fastest in O(x) terms. You need to know why they work, because a lot of problems require parts of common algorithms, but not necessarily all. You need to know which algorithms can work on arrays, and which work on linked data structures.
For instance, you may remember how a heap works, and you may have seen a heap represented as a tree. But if you try to implement a heap as a binary tree, you discover that it doesn't work unless you keep a link to the parent node, while if you implement a heap in an array, there is a simple computation that gives you the index of the left child, right child, or parent node as an array index, and doesn't require extra space for links.
You don't have time to rediscover facts about data structures from first principles in the context of a coding test question. That's why you memorize this information.
Having your algorithms and data structures down cold summarizes the experience of getting a CS degree. It's proof you know what you said you know. That is why employers test you with coding problems. It tests what it means to have a CS education. There are other questions for testing experience.
No comments:
Post a Comment