DEV Community

Cover image for Why C++ is the best language to learn Algorithms and Data Structures?

Why C++ is the best language to learn Algorithms and Data Structures?

iamdeb25 profile image Dave Amiana ・2 min read

I am a big fan of high-level languages. I love how they present themselves without the unnecessary implementation logic. I love how we can neatly express a data structure in languages like Python. And from a conceptual level of understanding, they are good enough. But this is only half of the story. The main intention for writing algorithms and data structures in practice is efficiency, we want to make our process streamlined.

Here are a couple of good reasons why you should rewrite your algorithms in C++:

  • C++ is a compiled language that outputs high-performing code
  • C++ also supports high-level concepts with the zero-overhead principle. This is the C++ design principle which says that you don't pay what you don't use as well as what you do use is just as efficient as what you could reasonably write by hand.
  • C++ has a rigorous type system that ensures type safety and enforces the programmer to explicate their intentions with their programs
  • since C++11, the modern standards of C++ have become more elegant, simpler, and safer The C++ language is more flexible than any other language as you can express the highest level of abstraction down at the level of the silicon. That range of capabilities supported by the language gives you so much control with designing your algorithms or optimizing the memory management of your data structure.

The Python courses I have encountered rarely discussed how Python shares resources with another object, I believe, a feature baked into the language. And you can't do anything about it because you are not in control of these lower-level implementations. The implementation of memory sharing and garbage collection in Python are intricate areas of the language optimized for performance and safety. On the surface, the code we write in such languages does not tell you the whole story.

On one hand, you receive a cleaner interface, and you have lesser constructs to worry about. On the other, you are not in control, the language you are operating on are abstractions of a lower level implementation written in C -- a subset of C++.

Articles worthwhile reading

Discussion (1)

Editor guide
filatovv profile image
Yuri Filatov

Hmm, there is something to think about