Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choice of programming language in book on algorithms? [closed]

Following up on my previous question on the enduring properties of a book on algorithms, see here, now I would like to ask the community what language would you use to write the examples of such a reference book.

I will probably not use MMIX (!) to write the examples of the book, but at the same time, I think just pseudo-code would be less interesting than examples in a real language.

Still, I'd also like the book to be a resource for researchers as well. What could be the choice of the community? Why?

Answer: I knew this was a tough question and that there would be several different answers. Notice that answers cover the whole range from Assembly/MMIX(!!) to Python and pseudo-code. The votes and the arguments compel me to choose Uri's sensible answer, with one caveat: my pseudo-code will be as close to C as I possibly can (without going into platform specific issues, of course), and I will possibly discuss better implementations in side notes (As all of us know, mathematically proving the algorithm works is far, far from the problems of implementing it).

The book is on algorithms in a particular domain, not on the mathematics of algorithms in general (much smarter people have done and will do much better than me on general algorithms). As such, one thing I consider would add value to such a book is the repository of the algorithms, which I will definitely put online in a companion website (maybe in a couple of languages, if I find the time).

Thanks for all the answers. I sometimes feel I should put everybody who answers as co-authors. :)

like image 665
Dervin Thunk Avatar asked Mar 11 '09 23:03

Dervin Thunk


People also ask

Which programming language is best for algorithms?

Python is a great language to learn algorithms and data structures because it has a very clean, simplistic syntax that looks very similar to pseudocode. The simplicity of the language helps you to focus on writing the algorithm and less on the syntax necessary to do so.

What language is used for algorithms?

While algorithms are generally written in a natural language or plain English language, pseudocode is written in a format that is similar to the structure of a high-level programming language.

Can we use any programming language to write an algorithm?

Data structures and algorithms are not language specific and hence you can use any language be it JavaScript, C, C++, Java or Python.

Which language should I choose for DSA?

In my opinion, C would be the best language to learn data structures and algorithms because it will force you to write your own. It will force you to understand pointers, dynamic memory allocation, and the implementations behind the popular data structures like linked lists, hash tables, etc.


1 Answers

A good book on algorithms should be written in psueod-code a-la-CLR...

In my experience, most books that go into language-specific examplse end up looking more like undergraduate textbook than like a serious reference or learning books. In addition, most languages are fairly clunky when dealing with collections (esp. C++ and Java, even with generics). Between all the details, too much is lost. You're also immediately eliminating a lot of your potential audience.

The only advantage to language specific books is that if you were writing a textbook, the publisher could attach a CD and add 50$ to the MSRP.

It's easier for me to understand an algorithm from (readable) pseudocode. If I can't figure out how to implement it in my language with my own collections, I'm in trouble anyway.

You could add to every pseudocode listing a note about implementation details for specific languages (e.g., use a TreeSet in Java for best performance, etc.)

You could also maintain a separate website for the book (good idea anyway) where you'll have actual implementations in different languages. No need to kill trees with long printouts.

like image 135
Uri Avatar answered Oct 11 '22 05:10

Uri