4 ms·
sometimes its useful for optimisation or understanding programmer motivation. (as well as interviews and tests, which are easily the most common use cases) TL;
by jheriko 13y ago
sometimes its useful for optimisation or understanding programmer motivation. (as well as interviews and tests, which are easily the most common use cases)
TL;DR - having this kind of knowledge is a double edged sword
one case that sticks in my mind was optimising come code by swapping a list for an array - the original author was perplexed because insertion and deletion were the common operations on that data structure which should be 'O(1)' (constant time) operations on a linked list and 'O(n)' (time scales based on number of elements) on an array.
my reasoning was that the list implementation stored the nodes in an array and the corresponding inserts and deletes did those same array operations underneath - hence rendering that particular list data structure useless - it had all of the worst case characteristics of both the list and the array, and none of the benefits of either.
i might have been able to work all that out without knowledge, but knowing the ideal performance characteristics of arrays and lists made it trivial to debug and optimise.
its worth noting that the same kind of knowledge is what motivated the original author of the code to use the list data structure.
also worth noting that a lack of such knowledge is what allowed such a useless implementation of a list to begin with.