I want to learn data structures and algorithms, but Python has so many built-in tools that I'm worried I'll miss how things work. Would C or C++ be a better choice?
Is Python a good choice for learning algorithms, or should I use C?
Answers
Python is a good place to start. Its syntax lets you focus on the steps of an algorithm rather than spending as much time on language mechanics. You can still implement a linked list, a stack, or a sorting algorithm yourself instead of reaching for a built-in.
Try working out the time complexity first, then test your implementation on increasingly large inputs. The built-ins are useful afterward for comparing your version with a practical alternative.
Reply to this answer
Go with C if part of your goal is to understand memory management and how structures are laid out. Building a linked list there makes you deal with pointers, allocation, and freeing memory, which Python largely handles for you.
That does add work that isn't really about the algorithm itself. Whether it's a distraction or the whole point depends on what you want to learn.
Reply to this answer
C++ isn't necessarily an escape from convenient libraries. It has plenty of ready-made containers and algorithms too. Whichever language you pick, the learning comes from deciding when to build a structure yourself and when to use the library version.
Reply to this answer
Python is handy for experimenting. You can try small expressions interactively, inspect values, and change an implementation without much ceremony. That makes it easier to test an idea or check what happens at the edges.
8s!torkavi_937:
That sounds useful for getting started. I can leave the lower-level memory details for a later pass.
Reply to this answer
Separate learning the algorithm from getting the fastest implementation. Python can teach you the logic, even though a Python implementation may run slower than one written in a compiled language. For real projects, a well-tested library implementation can be a better choice than your learning exercise.
Reply to this answer
Add your answer
Answers are reviewed before publication.
8j!fablemortar_263:
Just keep in mind that timing Python code also reflects interpreter and implementation costs. It's useful for exploring growth, but not a pure measurement of the algorithm.