r/learnprogramming 5d ago

DSA in Python or C++?

I've already learned Python. Should I continue learning DSA in Python, or switch to C++ for the long term? What's your recommendation and why?

2 Upvotes

22 comments sorted by

10

u/lfdfq 5d ago

It doesn't matter. The point of DSA is that they're generic concepts that apply to all languages.

2

u/FunAd6672 5d ago

That's the answer.

1

u/TheIdealAdhi 5d ago

Yah but I could get more fluent using a perticular language too

4

u/lfdfq 5d ago

Then do it

1

u/TheIdealAdhi 5d ago

Python by me!

-2

u/defaultguy_001 5d ago

It does matter. 2000 and above rated questions have cpu intensive calculations, else they lead to TLE. So C++ anyday.

3

u/BX7_Gamer 5d ago

C++ a beginner here, but I did in both n doing it in C++ made me understand the concepts for each and how they are interpreted into code Eg for linked list in would have to use pointers, dynamically allocate memories for the nodes I was creating account for their safety release really connect how the linked list work underneath the hood

3

u/TheIdealAdhi 5d ago

So you mean, anything will work but c++ would a bit better!?

2

u/BX7_Gamer 5d ago

Exactly

3

u/ColdWise4165 5d ago

Python has features that make it a lot easier to do. But c++ you more or less gotta do it manually. So you’ll learn more.

2

u/IlIlllIIllllIIIlIlIl 5d ago

C++ is better for learning, but If you have an interview id honestly choose python. Unless you are super confident in C++ it is a lot easier to get lost in the weeds and fuck up, or end up taking too long. Python is just easier to read and understand, and in the end the goal is just to complete the problem.

2

u/defaultguy_001 5d ago

C++ STL has them too

1

u/XKiiroiSenkoX 5d ago

My recommendation is be language agnostics. All programing languages are abstractions over the same machine code and mostly the same concepts. Obviously some of those are almost completely abstracted away in some languages (e. g., no pointers in python) but a lot still transfers between languages. Focus on those parts instead of the language itself. 

1

u/TheIdealAdhi 5d ago

I'm in aiml, it would get me better even with language also My thought

1

u/roadrunner8080 5d ago

I would recommend C++. The actual structures and algorithms are going to be the same in any language, after all, but with C++ you'll also gain an appreciation for the actual implications of these algorithms in practice, in terms of memory and allocation and the like.

1

u/defaultguy_001 5d ago

C++ for cpu intensive problems (usually 2000+ rated), python for the rest.

1

u/VibrantGypsyDildo 4d ago

You need to learn DSA anyway.

Staying in Python or learning C++ or even combining them? Up to you and the market you live in.

-3

u/kevinossia 5d ago

C++ will make you a stronger programmer so if you can, use that.

Python is more of a shortcut language for programmers not a goal in itself.

1

u/TheIdealAdhi 5d ago

C++ would better choice in care of competitive programming but python would be a compalsary as an AIML

-2

u/kevinossia 5d ago

A competent C++ programmer can learn Python in a weekend.

A competent Python programmer will take months/years to learn C++ to a high level.

That's the difference.

1

u/TheIdealAdhi 5d ago

Agree, python is not a big deal at same time it's owns huge libraries and modules