Choosing a programming language for studying data structures and algorithms

What programming language would you recommend learning about data structures and algorithms in?

Given the following:

  • Personal experience
  • Language functions (pointers, OO, etc.)
  • Suitability for teaching DS and A concepts

I ask because there are some books that are agnostic programming language (written from a mathematical point of view and using pseudocode). If I learn from one of them, I would like to choose a programming language for encoding and running algorithms.

Then there are other books that introduce the concepts of DS and A with examples written in certain laguage programming - and I would also like to code these algorithms - therefore, to a certain extent, the language also selects the book.

In any case, I must choose a language, and I would prefer to stick to it in everything. Rejecting the preferences of the personal language that is best suited for this purpose?

+69
language-agnostic algorithm data-structures
Apr 17 '10 at 6:30
source share
14 answers

The answer to this question depends on what exactly you want to know.

Python and Ruby

Higher-level languages ​​such as Python and Ruby are often offered because they are higher-level and the syntax is quite readable. However, all of these languages ​​have abstractions for common data structures. Nothing prevents you from implementing your own versions as a training exercise, but you may find that you are building high-level data structures on top of other high-level data structures, which is not necessarily useful.

In addition, Ruby and Python are dynamically typed languages. This may be good, but it can also confuse the novice, and it can be harder (at the initial stage) to catch errors, because they usually will not be visible until runtime.

FROM

On the other end. It would be nice if you want to learn really low-level details, such as how to manage memory, but memory management suddenly becomes an important factor, for example, using malloc () / free () correctly. It can be distracting. In addition, C is not object oriented. This is not bad, but just worth noting.

C ++

C ++ has been mentioned. As I said in a comment, I think this is a terrible choice. C ++ is terribly complicated even with simple use and has a ridiculous amount of "errors". In addition, C ++ does not have a common base class. This is important because data structures, such as hash tables, rely on a common base class. You could implement a version for a nominal base class, but this is a little less useful.

Java

Java has also been mentioned. Many people love to hate Java, and it’s true that the language is extremely verbose and lacks some of the more modern language features (such as closures), but none of this matters. Java is statically typed and has a garbage collector. This means that the Java compiler will catch many errors that will not be dynamically typed languages ​​(until runtime), and will not deal with segmentation errors (which does not mean that you cannot lose memory in Java; obviously, you can). I think Java is a good choice.

FROM#

C # language is similar to a more modern version of Java. Like Java, it is a managed (garbage collector) intermediate compiled language that runs on a virtual machine. Any other language specified here, except for C / C ++, also works in a virtual machine, but Python, Ruby, etc. Interpreted directly, not compiled into bytecode.

C # has the same pros and cons as Java, in principle.

Haskell (etc.)

Finally, you have functional languages: Haskell, OCaml, Scheme / Lisp, Clojure, F #, etc. They think about all the problems in a completely different way and at some point are worth studying, but again it all comes down to what you want to learn: functional programming or data structures? I stick to learning one thing at a time, and not confuse the problem. If at some point you learn a functional language (which I would recommend), Haskell is a safe and good choice.

My advice

Choose Java or C #. Both have excellent, free, integrated development environments (Eclipse, Netbeans, and IntelliJ Community Edition for Java, Visual Studio Express for C #, Visual Studio Community Edition) that make writing and running code easier. If you do not use your own data structure, which is more complex than an array and any object that you write yourself, you will learn basically the same thing as in C / C ++, but without the need to actually manage the memory.

Let me explain: the size of the extensible hash table needs to be changed if enough elements are added. In any implementation, this will mean doing something like doubling the size of the backup data structure (usually an array) and copying it into existing elements. The implementation is basically the same in all imperative languages, but in C / C ++ you have to deal with segmentation errors when you don't distribute or release something correctly.

Python or Ruby (it doesn't matter which) will be my next choice (and very close to the other two) just because dynamic typing can be problematic at first.

+79
Apr 17 '10 at 6:58
source share
— -

I would recommend Java mainly because:

  • garbage collection
  • links
  • rich collections

EDIT: Down voters, please explain.

+39
Apr 17 2018-10-17T00:
source share

In my opinion, C will be the best language for learning data structures and algorithms, because it will force you to write your own. This will make you understand pointers, dynamic memory allocation, and implementations of popular data structures such as linked lists, hash tables, etc. Many of them are what you can take for granted in higher-level languages ​​(Java, C #, etc.).

+27
Apr 17 '10 at 6:42
source share

Python great. Easy to read, fully functional. If you intend to work with pseudo-code, Python will look pretty familiar.

Python is already the language of UC Irvine's selection algorithms, where it is described like this:
"Python is an algorithm-oriented language that is essential in education. Python's benefits include its tutorial-like syntax and interactivity that encourage experimentation."

Python also works as a beginner friendly with Gato , a charting tool. Learning algorithms and data structures are one vertex that can help by visualizing something that Gato does easily (without learning any complex graphics libraries).

+14
Apr 17 '10 at 6:35
source share

If the goal is to learn only about data structures and algorithms , I would say JavaScript. You can run your code in a browser. You have very flexible object handling, and you can focus entirely on data structures and algorithms, rather than memory management, language constructs, or other materials that distract attention from the actual computer science that you are studying.

The bonus also is that you can easily visualize various data structures using a browser to render graphs and trees using the DOM and Canvas.

CS courses over the years tend to change the language in which the subject is taught, simply because newer and better implementations of languages ​​that make learning easier have appeared, making it easier to focus on a real problem.

+11
Apr 17 '10 at 7:44
source share

Oberon-2 or Component Pascal . The latter is a superset of the former.

Einstein once said: "Make it as simple as possible, but not easier." This phrase was chosen by Professor Nicklaus Wirth as an epigraph to the original message in the language of Oberon. And this is true for the descendants of Oberon mentioned above.

When it comes to programming language excellence, I would like to quote Antoine de Saint-Exupery: “The designer knows that he achieved perfection not when there is nothing more to add, but when there is already nothing that can be taken away.” Wirth, even if this is not achieved, is on the right track. In the "Virtue line of programming languages" (Algol → Pascal → Modula-2 → Oberon → Oberon-2), each subsequent language is simpler and at the same time more powerful than the previous one.

Powerful but simple languages based on the principle of least surprise. Strict static typing, convenient object-oriented tools, garbage collection. The list of opportunities is small, but it is enough to be productive and not complicate the situation, especially in the initial stages.

When you want to learn algorithms and data structures, you mean that. But if your language is "powerful" (it has many functions, such as C ++, C #, Java, Python, ...), you will spend a lot of time learning the language, not the algorithms and data structures. You will not see the forest behind the trees. =) You can consider trees as syntax elements (and any other functions), and the forest as an important concept (any algorithm, data structure, OOP, whatever). The more functions (trees) you have in your language, the more difficult it becomes to step back and understand the concepts (see the forest).

But if the language is really powerful (it has a small set of well-proven features), then the language itself comes in second place. There are not many trees there, so you can take a couple of steps back and ... Well, I think there are enough analogies. =

Many books on algorithms and data structures also use pseudo-code similar to Algol / Pascal, and examples in these languages ​​will be easy to convert. And you can directly use examples from the book "Algorithms and Data Structures". Oberon Edition (2004), PDF (1.2 MB).

Some sitelinks include:

+8
Apr 17 2018-10-17T00:
source share

I would suggest Ada. It has functions for data constructs not found in other languages, such as range checks type Day is range 1 .. 31; It also has a very strict check on runtime and runtime (unless you decide to disable it), which makes it easier to find errors in your implementation.

+7
Apr 17 '10 at 7:55
source share

If you want to go the path of least resistance, then Python. It will have a minimum amount of unnecessary boiler plate, etc.

Ideally, I would like to learn C algorithms so that you can find out what happens at the memory level; I would also like to learn algorithms in a functional language so that you can see how similar algorithms work with persistent data structures.

Knut’s famous books contain a large number of (invented platform) assembler code. This is recommended if you want to be super hardcore. Personally, however, I worked in C when I was working on a class of algorithms (disclosure: this was only a couple of years ago). Sometimes I work on some issues in Knut, but I don’t know if I will go with MMIX as my language for learning algorithms. I will survive a little, I would feel.

EDIT : It also depends on what you are familiar with. If you want to start working with text algorithms right now, and you've never worked a lot with C, then Python is the right answer. You want the language not to be a huge obstacle to overcome, because you want to enjoy it. I know that I know.

Last point: at least when I studied algorithms, I worked a lot on paper. I think this is important - I mean what you want to know about asymptotics, etc. Spend all your time introducing algorithms in any language, this is not what you need to do.

+5
Apr 17 '10 at 6:36
source share

"If your only tool is a hammer, then all your problems will look like nails."

Learn at least several languages.

In addition, your choice depends on your goal.

Hobby? Work in the Windows world? Linux / UNIX family?

Type of application: business and scientific; hardware drivers or applications?

Desktop or web apps?

I have some tips for you.

(a) definitely get to know J (free from jsoftware.com, the successor to APL, and J and APL are from the work of Ken Iverson, the winner of Turing ... the Turing Prize is like the Nobel Prize in Computing).

(b) if you are in the Windows world, start with C #, because so much in .NET works in C #. If possible, get a copy of Tom Archer "Inside C #" from Microsoft Press. You can get the free C # development system by downloading the version of Microsoft express.

(c) learn how to use TDD / BDD ... regardless of the language, first you write a small test called unit test; then you write production code to pass unit test; one small step at a time ... it's not only the language you use, but also the methodology.

(d) learn assembly language ... assembler is a low level, almost machine language, it will give you a good idea of ​​what is going on behind the scenes.

(e) outside the Windows world, I would recommend C ++.

There is no better language.

If it was only a language, programming would be easier.

Not only do you want to learn algorithms that are very specific, but you also want to learn more general models that will help you choose an approach to solving this problem.

One thing is certain: you will probably never run out of everything to find out if you are going to become a programmer.

+4
Apr 17 '10 at 7:10
source share

I think Lisp is worth exploring.

My first university programming course was at Lisp. Before that, I have been writing programs in several languages ​​for ten years. I thought the first programming course would be boring, but I was wrong.

Lisp is a very interesting language because it has a very simple syntax. Focus shifts from syntax to functionality. A functional programming style is also extremely useful for learning. After my Lisp course, I found that I was writing C ++ programs in a completely new, better way, thanks to the new concepts that Lisp taught me.

Lisp also uses the same representation for code and data, which opens up an interesting algorithm with code generated on the fly and then executed.

+4
Jun 05 '10 at 19:56
source share

You can evaluate a language with algebraic data types and a template such as Standard ML, OCaml, F # or Haskell. For example, here is a function to rebalance a red black binary data tree written in OCaml / F #:

 let balance = function | R(R(a, x, b), y, c), z, d | R(a, x, R(b, y, c)), z, d | a, x, R(R(b, y, c), z, d) | a, x, R(b, y, R(c, z, d)) -> R(B(a, x, b), y, B(c, z, d)) | a, x, b -> B(a, x, b) 
+3
May 12 '10 at 20:41
source share

Maybe I'm wrong, but are data structures and algorithms independent of programming languages?

After all, data structures are just a way of organizing data; any high-level language will support this. Of course, some languages ​​will create mechanisms that implement the basic data structures (such as the Collections Framework in Java or C ++ STL), but this does not prevent you from programming the data structure in your chosen programming language. Moreover, the algorithms are written in pseudo-code, making them independent of the language.

I understand that this does not answer your question, but I have problems understanding what you are looking for; learn data structures / algorithms or learn a new language.

+2
Apr 17 '10 at 7:29
source share

Any language other than Fugly C ++ should do well.

+2
Jun 05 '10 at 19:49
source share

I prefer C ++ :)

-2
Apr 17 '10 at 6:32
source share



All Articles