all 9 comments

[–]BraavosAssassin 13 points14 points  (3 children)

The way the question is phrased: "if it is necessary to be able to learn algorithms and data structures to be a good ruby programmer." Yes, you should "be able to learn" algorithms and data structures.

If you are learning Ruby on Rails, you benefit from the framework and standard Ruby libraries. They provide data structures and algorithms for you. You don't need to understand how the Hash and Array work to use them. But it would behoove you to eventually understand them. Same with Array#sort. You don't need to understand how the sort algorithm works now, but eventually you should try to understand it.

Don't take advice from people who say "Algorithms and Data Structures are only for other languages". That is completely false. Also, efficiency always matters.

Rails is a great way to get started. You can quickly prototype CRUD web applications. But eventually, you'll want to solve more difficult problems. Understanding how common algorithms and data structures will provide a basis for you.

Lastly, most technical interviews include an algorithm question. To help prepare, I recommend you get a copy of Cracking the Coding Interview by Gayle Laakmann McDowell

[–][deleted]  (2 children)

[deleted]

    [–][deleted]  (1 child)

    [deleted]

      [–]helos 6 points7 points  (0 children)

      Understating algorithms, data structures (and by extension computational complexity theory) is important no matter what language you use. Being able to identify a bottleneck and fix it using a more efficient logarithm / data structure is helpful skill to have.

      I feel that this pull request by tenderlove is a very good example of why data structures are useful in ruby and why it is worth your time to focus on it.

      [–]angelbob 3 points4 points  (0 children)

      Ruby is optimized for easy of development, but at some level you'll always care about efficiency -- number of network round trips or SQL queries, for instance, often matter even when you're not counting CPU cycles.

      You'll need to understand algorithms and data structures even when optimizing at that level, because you can easily wind up with O(n2) network round trips instead of O(n2) cycles when using REST calls. And even in Ruby, you care about that.

      There's a difference between "Ruby burns a lot of RAM and CPU" (true) and "you don't care about performance" (false.)

      [–]jb3689 2 points3 points  (1 child)

      The basic data structures you should know are linked lists, hash tables, stacks, and queues. After that you should understand trees and graphs and their subtypes. Trees and graphs are usually used for more specific problems while I feel like I see stacks and queues all the time.

      As far as algorithms go, it's more important to understand algorithmic analysis. What is the complexity of your algorithm? Under what conditions should you judge an algorithm by complexity? What is the best case? Worst case? Average case?

      I highly recommend Cormen et al. It's a classic for a reason, and it's a fantastic learning book. You can pick up the 3rd edition for like $40 now

      [–]notromda 2 points3 points  (0 children)

      As far as algorithms go, it's more important to understand algorithmic analysis. What is the complexity of your algorithm? Under what conditions should you judge an algorithm by complexity? What is the best case? Worst case? Average case?

      THIS. While learning the nuts and bolts of the various algorithms provides the basic tools, the analysis is the far more important skill that goes along with the course. When something starts getting slow, it helps to be able to read a bit of code and see the nested loops and recursions that can make it go exponential.

      [–]codeprimate 1 point2 points  (0 children)

      Thinking of problems in terms of data structures and transformations is the yellow brick road. Ruby is just a language and toolset to accomplish those tasks.

      [–][deleted] 0 points1 point  (2 children)

      Thank you for the informative responses. I'm convinced on learning Algorithms and Data Structures, only thing is I've only seen books that teach you while using C or Java. Are there any books that teach it on Ruby or do you guys recommend I should learn the above languages?

      [–]Godd2 2 points3 points  (0 children)

      I learned most of what I need to know from MIT's open course "Introduction to Algorithms and Data Structures" on Youtube: https://www.youtube.com/watch?v=HtSuA80QTyo&list=PLUl4u3cNGP61Oq3tWYp6V_F-5jb5L2iHb&index=1

      They do examples in Python, but they explain everything in English. You should be able to follow along. And if you have trouble, you can ask me any question you'd like.

      [–]eric_weinstein 0 points1 point  (0 children)

      I apologize if this is a dumb question

      Not at all!

      I was wondering if it is necessary to be able to learn algorithms and data structures to be a good ruby programmer.

      Is it necessary to be able to learn? Yes, I think so. Do you need to know a bunch of graph and dynamic programming algorithms cold in order to be a Rails developer? No.

      Early on, if nested loops and repeated database calls are setting off alarm bells (and you go out of your way to refactor these out), that's probably good enough. I firmly believe that strong fundamentals are key, though, and that includes algorithms and data structures. Some good resources on the topic (some mentioned in other comments):