Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choice of programming language for learning data structures and algorithms [closed]

Which programming language would you recommend to learn about data structures and algorithms in?

Considering the following:

  • Personal experience
  • Language features (pointers, OO, etc)
  • Suitability for learning DS & A concepts

I ask because there are some books out there that are programming language-agnostic (written from a Mathematical perspective, and use pseudocode). If I learn from one of these, I would like to choose a programming language to code and run the algorithms in.

Then, there are other books which introduce DS & A concepts with examples written in a particular programming laguage - and I would like to code these algorithms as well - thus, to a certain extent, the language picks the book too.

Either way, I have to pick a language, and I would prefer to stick to one throughout. Setting aside personal language preferences, which one is best for this purpose?

like image 873
bguiz Avatar asked Apr 17 '10 06:04

bguiz


People also ask

Which language is best to learn data structures and algorithms?

C++ is the best language for not only competitive but also using to solve the algorithm and data structure problems . C++ use increases the computational level of thinking in memory , time complexity and data flow level.

Should I learn data structures and algorithms in C++ or Python?

You can learn data structure in any language you want. But for practicals it will be more beneficial if you go with “C language”. Python supports many inbuilt features which will make your programming easy. but if you start practicing in C then it will improve your logic.

Can I learn data structures and algorithms without any programming language?

It will give you a clear idea and it would be easier for you to understand the algorithms in terms of Programming. Not required though . But you can .

Which programming language is best for data structures and algorithms Quora?

Java is one of the awesome programming language and to implement data structure by using not only java one can implement any data structure using any language such as, C, Java, PHP, Python etc. So as per my point of view C is the best programming language for Data structure.


1 Answers

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

Python and Ruby

High-level languages like Python and Ruby are often suggested because they are high level and the syntax is quite readable. However, these languages all have abstractions for the common data structures. There's nothing stopping you implementing your own versions as a learning exercise but you may find that you're building high-level data structures on top of other high-level data structures, which isn't necessarily useful.

Also, Ruby and Python are dynamically-typed languages. This can be good but it can also be confusing for the beginner and it can be harder (initially) to catch errors since they typically won't be apparent until runtime.

C

C is at the other extreme. It's good if you want to learn really low-level details like how the memory is managed but memory management is suddenly an important consideration, as in, correct usage of malloc()/free(). That can be distracting. Also, C isn't object-oriented. That's not a bad thing but simply worth noting.

C++

C++ has been mentioned. As I said in the comment, I think this is a terrible choice. C++ is hideously complicated even in simple usage and has a ridiculous amount of "gotchas". Also, C++ has no common base class. This is important because data structures like hash tables rely on there being a common base class. You could implement a version for a nominal base class but it's a little less useful.

Java

Java has also been mentioned. Many people like to hate Java and it's true that the language is extremely verbose and lacking in some of the more modern language features (eg closures) but none of that really matters. Java is statically typed and has garbage collection. This means the Java compiler will catch many errors that dynamically typed languages won't (until runtime) and there's no dealing with segmentation faults (which isn't to say you can't leak memory in Java; obviously you can). I think Java is a fine choice.

C#

C# the language is like a more modern version of Java. Like Java, it is a managed (garbage collected) intermediate compiled language that runs on a virtual machine. Every other language listed here apart from C/C++ also run on a virtual machine but Python, Ruby, etc are interpreted directly rather than compiled to bytecode.

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

Haskell (etc)

Lastly, you have functional languages: Haskell, OCaml, Scheme/Lisp, Clojure, F#, etc. These think about all problems in a very different way and are worth learning at some point but again it comes down to what you want to learn: functional programming or data structures? I'd stick to learning one thing at a time rather than confusing the issue. If you do learn a functional language at some point (which I would recommend), Haskell is a safe and fine choice.

My Advice

Pick Java or C#. Both have free, excellent IDEs (Eclipse, Netbeans and IntelliJ Community Edition for Java, Visual Studio Express for C#, Visual studio community edition) that make writing and running code a snap. If you use no native data structure more complex than an array and any object you yourself write you'll learn basically the same thing as you would in C/C++ but without having to actually manage memory.

Let me explain: an extensible hash table needs to be resized if sufficient elements are added. In any implementation that will mean doing something like doubling the size of the backing data structure (typically an array) and copying in the existing elements. The implementation is basically the same in all imperative languages but in C/C++ you have to deal with segmentation faults when you don't allocate or deallocate something correctly.

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

like image 95
cletus Avatar answered Oct 12 '22 23:10

cletus