

Ask HN: Learning Complexity Classes - krat0sprakhar

Hey guys
I have an interview coming up in a few days and I've come to know from my friends that they stress a lot on having a good idea about complexity classes. So is there any resource on the web or book where a newbie can get good answers to what are NP classes and how is NP complete different from NP hard and the likes.<p>Thanks
======
RiderOfGiraffes
You don't really want to know the full complexity zoo (look it up) really you
don't. You want to know the difference in the practical sense between

* logarithmic

* sub-linear

* linear

* quadratic (and other low powers)

* polynomial

* sub-exponential

* exponential

* super-exponential

* NP

* NP-Hard

* The intersection of those last two (NP-complete)

And for each - give examples.

Then you want to say, for a given algorithm, what it's complexity looks like.
What's bubble-sort? Why? What's QuickSort? Best case? Worse case?

What's packing? A*? Travelling Salesman? Factoring?

What about the various database operations?

Skim the wikipedia pages on each of those, concentrating on the feel of the
algorithm and the statement of the complexity. Then ask about other
algorithms, and try to get a sense of how they feel. And why.

Finally - Why can string search be sub-linear?

~~~
bartonfink
I'll bite on the last one. How can string search be sublinear? Boyer-Moore,
the fastest algorithm I know of, is still O(n) regarding the length of the
search string. Since strings are inherently linear, you'd need a
transformation step to leverage the advantages of another data structure (e.g.
suffix tree or a DAWG), and that transformation would need to look at each
token. Am I missing somehting?

~~~
RiderOfGiraffes
Example:

If you're looking for "aaaaaaaaaaaaaaaa" (that's a string of length 16) and
you look in index 15 (counting from 0) and find a non-"a" there, you can leap
forward 15 (or 16 - there's an off-by-one error waiting to bite) places. If
that's also not an "a" then you can do it again.

It's more complex than that, but the complexity can, in some cases, be sub-
linear.

There's another reference I have somewhere to a surprising (and contentious)
sub-linear algorithm for something that's "obviously provably linear". I'll
see if I can dig it up and post it later. No time now.

ADDED IN EDIT (because there's more than one reply saying the same thing)

Yes, it's futzing the constant. The point is that the constant _can_ be less
than one, it's not always necessary to examine every character in the string
being searched, which comes as a surprise. But no, this is not sub-linear,
although many people describe it as such. Knowing why it's not sub-linear,
even when the constant is less than one, is an important milestone in learning
about complexity of functions.

~~~
Epenthesis
That's still O(n). Say you're looking for that string in a string of length n.
You're search time will be n/16+c, which is O(n).

------
techbuddy
check stackoverflow.com for many resources on the subject

