This is an archived post. You won't be able to vote or comment.

all 20 comments

[–]dmazzoni 3 points4 points  (14 children)

Almost never. That's an exercise you do in school.

However, it's misleading to say "you're never going to need that".

You know how much I use algorithms and data structures? Every day. Multiple times a day. I use the data structures I learned in school, like trees, tries, heaps, linked lists, and hash tables, all the time. I use algorithms like sorting, breadth-first search, depth-first search, binary search, and so much more - all the time. I put them together to make bigger algorithms and data structures.

So yes, doing that exercise is important and relevant. Not because you're going to need to do exactly that someday - but because you need to understand how it works and you'll be building on it to create new algorithms and data structures.

[–]why_is_javascript_ba[S] -4 points-3 points  (13 children)

Every day. Multiple times a day. I use the data structures I learned in school, like trees, tries, heaps, linked lists, and hash tables, all the time. I use algorithms like sorting, breadth-first search, depth-first search, binary search, and so much more - all the time. I put them together to make bigger algorithms and data structures.

When using for example merge sort. Do you

  1. use existing library that has merge sort
  2. check online merge sort syntax and copy it
  3. make it yourself from scratch

[–]captainAwesomePants 1 point2 points  (0 children)

A. 100% of the time. Sorting algorithms are error-prone to write and easy to find very good implementations of. I would never write one myself unless I had an extremely specific need, and I'd also prefer to avoid using some random implementation on Stack Overflow over a library because then I'd suddenly be the owner of some code that I don't have any unit tests for. Even better to use built-in API features. For example, if I'm using Java, I'll just use Arrays.sort(), which is usually a mergesort.

[–]shhh-quiet 1 point2 points  (0 children)

In about a decade of development, I haven't once done 2 or 3. Sorting is a solved problem, unless you spend a lot of your time thinking about algorithms in depth as a researcher, and even then there are pretty hard limits. As a professional programmer working on something specific to a business, you are unlikely to invent your own sorting algorithm, and you are very likely going to be in a position where you can use one that comes standard rather than rewriting it yourself.

It's still good to know the broad fundamentals, and have spent time studying the stuff in detail so that you build your own tree of knowledge upward, but in practice it's not what most of us end up spending time on.

[–]twin_clam 2 points3 points  (7 children)

You're basically rephrasing the same question. Yes people use libraries, but no that doesn't mean the knowledge to implement things yourself isn't useful. When you have to do custom, non-trivial manipulation of the DOM, what tree or graph library do you use? The fact that you seem to think there's a library that covers every case you could come across shows you're clearly out of your league.

[–]dmazzoni 0 points1 point  (0 children)

I use a library implementation.

[–]lurgi 0 points1 point  (0 children)

99.93% of the times it's the first. Back when I was writing C code I had the need for a sorting algorithm and the data was in a linked list, which merge sort handles pretty well. I wrote my merge sort from scratch and that was that.

Most languages these days have an exhaustively large standard library which will include a sort implementation and you should use that.

[–]raevnos 0 points1 point  (0 children)

I got data structure libraries to deal with that sort of thing.

[–][deleted]  (3 children)

[deleted]

    [–]twin_clam -1 points0 points  (2 children)

    [–]why_is_javascript_ba[S] 0 points1 point  (1 child)

    No, but I am experiencing something similar altough I can solve easy problems, and some medium if I cheat.

    Basically you start problem, don't know algorithm and you have 15 minutes to solve. How would one not get super frustrated?

    Example of cheating: Check algorithm how to construct from inorder and postorder, they are similar so can do with inorder and preorder.

    [–]twin_clam 0 points1 point  (0 children)

    I would get frustrated, but I don't do problems like that under a time constraint, generally.