Hey everyone! I've been struggling with figuring out when to use specific algorithms and data structures while coding. It's definitely been one of the toughest parts of my programming journey. Are there any tips you can share? Also, do you have any recommended resources for learning about this?
5 Answers
It really comes down to practice. I can give you some general principles, but don't treat them as hard rules. Most of the time, you can get by with just arrays or lists. If you're looking to optimize things, prefer non-resizable arrays over linked lists or vectors. For searches, maps or sets are your friends. And remember, if you see a data structure mentioned somewhere, check out its Wikipedia page to see if it's useful for what you’re doing. For algorithms, your programming language likely has built-in options that are more efficient than anything you'd code from scratch. So, if it works, optimize it if necessary!
Practice is key! In most real-world scenarios, you'll mainly use hash tables and arrays. You don’t need to memorize every data structure; just have a rough idea of what they're used for. It's enough to classify your code by performance and know the basics of common structures.
You’ll figure it out as you gain more experience. At first, it’s a learning curve, similar to when you learned to write. Just remember the basics: first, make it work; then, make it pretty; finally, make it fast if needed. An imperfect solution you understand is way better than a perfect one you copied without grasping it.
There’s no shortcut to knowing which algorithm or structure to use; it’s all about weighing the pros and cons. In most cases, just use the built-in functions for things like sorting. For data structures in different languages, you're mostly looking at lists and maps. If you really want to dive deeper, I recommend checking out 'Grokking Algorithms'—it’s all about understanding more than just memorizing.
Honestly, this becomes easier with experience. The more projects you work on, the better you'll get. Looking back at my past code, I can always see how I could've improved things. It's a continuous learning curve throughout your programming career.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String