Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Imagine you've got ten pieces you need to stick end to end

    a b c d e f g h i j
How many ways can you do that with a binary operation? i.e. how many ways can you completely parenthesise that expression. e.g.

    ((a (((b (c d)) e) ((f g) h)) i) j)
I haven't worked it out exactly, but I think it's about a trillion.

On the other hand, suppose your binary operation is associative. How many different ways are there now? Effectively one.

That's a huge reduction in complexity. The notion of associativity is extremely useful in developing composable programs.



Are you sure of that? Isn't the answer to your question the Catalan numbers, for which this case the answer is 4862?


I'm not sure at all! My calculation came out very wrong, and a quick sanity check should have told me it's implausible that it's in the trillions.

Anyway, 4862 times is still a substantial complexity reduction.

Thanks for the correction.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: