How imperative are algorithms?

How imperative are algorithms?
0

I never do a BFS or recursion in my day to day. How valuable are algorithms and what is the best site to study? Will they actually make me a better programmer?

Some algorithms are certainly more useful to know than others, but it’s the general concepts that are important to learn.

For example, knowing the technical implementation details between BFS and DFS isn’t really the important part. What’s more important is knowing how they differ in general and how that difference can drastically affect how quickly the search is completed (or potentially, if it completes).

Basic searching and sorting algorithms are likely to be the most useful - linear vs binary searching, and merge sort, quick sort, and insertion sort are the most common.

And again, it’s the high-level concepts that are important, not really the specific implementations (or even the actual algorithms themselves). You should basically know the ramifications of writing potentially extremely inefficient code that could either take forever to run (time complexity), or could run out of system resources (space complexity).

In actual code scenarios, this means things like trying to avoid writing nested loops, because nested loops have atrocious time complexity (it’s literally exponential, and drastically suffers as more nesting is added). And sometimes you might run into unsorted data that you want to sort. A lot of modern languages have built-in efficient sorting functions for convenience, but there’s always the chance that you’ll have to write your own sorting function. And you definitely want to avoid writing an inefficient sorting function. Other times you might run into very large data sets that you need to search through, and then you need to decide whether it might make sense to sort that data first, or just search through it without sorting. These are all scenarios where it helps to know the general concepts behind algorithms.

2 Likes

It depends on what you mean by “algorithms”. Knowing the most efficient way to do a BFS by heart? Not going to come up (except in crappy interviews). Being able to to assess the time and/or space complexity of an algorithm? Pretty important.

3 Likes

I depends how you count those. One re-render in React will use those couple times. How many times a day do you call React.render? :wink:

1 Like

I am failing to get my second software job. Doing leetcode should help, though, right?

I never do a BFS or recursion in my day to day.

No one should be writing BFS or recursion or any other well known algorithm in their day to day. It would be a waste of time because it’s a well understood problem.

For interviews, they are used because it’s easy enough to compare one developer to the next. It’s considered well known enough that you can write it out - then have an interesting conversation about it. That said, some interviewers are bad at interviewing. They’re human, get nervous, and don’t know how to pull out interesting information from candidates. So they fall back to “uhh… they didn’t finish my coding problem. Not inclined to hire.”

How valuable are algorithms and what is the best site to study?

For getting a job? Very. Today, most interviews - especially at larger companies - are going to heavily test your general data structure knowledge. As you progress in your career, also on design knowledge and ability to talk through different design solutions.

It is expected you know these types of algorithms at least on a surface level, and if you can’t write it from scratch - at least be able to intelligently discuss pros and cons of approaches.

As you become more senior, you’re expected to remember these details less and less. But especially for junior devs it’s more likely you will encounter some of these types of questions in interviews.

Also, keep in mind an algorithm is useless on its own. Learn to use them, and when to apply them, to be most effective as a software engineer.

Will they actually make me a better programmer?

Yes. That’s most of what programming is.

Algorithms are just sets of instructions. That’s it. Technically every program you write is “an algorithm”, just not one important enough to have a special name.

The algorithms you’re probably thinking of for this question are the ones that have names. Usually these are named because someone famous published about them, or because they’re actually useful. Learn to differentiate between the two, and focus on the useful ones.

1 Like

Sure any algorithms practice site should help, but you should spend your time where it counts. “failing to get my second software job” is kinda vague and could actually be for a number of reasons.

The other advice is good, my 10c:

They’re incredibly valuable, because they’re used everywhere. The simile that is most often used is that they are like recipe. You are using algorithms all the time. You will be writing algorithms a lot, it’s just that you’ll have learned that’s Just How You Write Procedure X or Y.

The recipe comparison is a good one. You don’t use [to use your example] BFS, but it isn’t some crazy complicated thing, you just aren’t working on something where it’s useful (+ it’s guaranteed you are using FE tools that rely on graph algorithms). But if you want to make curry, a recipe for carbonara isn’t going to be very helpful.

The longer you work in software, the more likely it is that you’ll want to solve some particular problem that has already been solved, and that what you need is to just implement some algorithm. Or you need to know how something works, and there’s no documentation, and so you read the code, and because you know the algorithm it relies on, you can understand it easily. Or you want help for a problem, and someone suggests you use well-known algorithm Z to solve it. And so on.

Or you might never need the knowledge directly, but having the knowledge is likely to be useful. Knowing how stuff works is never generally bad; learning how stuff works in your specialised area is generally not wasted effort.

Re good practice sites: IMO Exercism is the best, as the tests are all visible, you can use any libraries you want, the questions and solutions are normally of very high quality, and completing a challenge lets you view everyone else’s submitted solutions. And it has a huge number of languages available, (with many of the same challenges in common where appropriate), which is exceptionally helpful when learning a new language.

Rosetta Code I also like very much as reference more than anything else.

Edit: also, nit picking, but recursion is a technique, it’s not an algorithm. You have recursive algorithms, but recursion is just a basic method of solving a problem. You may not use it, but it’s like a loop. The implementation of how it works (or how a loop works) in the source code of the engine would be an [extremely low-level] algorithm, but recursion itself, no

2 Likes

Thanks a lot for this.