I wanted to know what algorithms do
they internally use and how do
intelligently decide a specific
algorithm for a specific task? For
example if sort gets a huge input
file, will it use different algorithms
for different data sizes?
That is an interesting question (+1 for that). I have no clue as to what the answer is, but if I were you, I'd look at the source code of typical GNU utilities to get an idea of their algorithms.
Does grep intelligently switch algorithms while searching different data sets?
I don't think so. Don't quote me since I cannot really tell you with 100% certainty, but I really don't think so. The UNIX philosophy of things is that one thing does one thing and one thing only. That's why we have several versions of grep (
Also, the idea is to do one thing and only one thing at run-time. Different behavior and algorithms can be configured as command-line arguments, so that the same program can act slightly differently (and possibly slightly more optimized) between runs. Good examples are the
However, the behavioral adaptation is configuration-based (via cmd line arguments); they don't change/adapt behavior at run-time. It is typically an unnecessary complexity for the type of artifacts the UNIX tools aim to be.
Such complexity is more appropriate of more complex, less general purpose tools IMO.