# How imperative are algorithms?

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?

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.