Recently there was a comment that in reality almost all (I think about 90%) programmers do not use algorithms and they do not need it in their work.
If we talk about the Web, then there is really a large number of programmers do not bother with algorithms and they do not need to know them, because most of the code that you have to write – just displaying data and a little less – save, update and delete.
A site like my blog can be written by any novice programmer who doesn’t need to know any algorithms. It’s not necessary to think about search algorithms, about which one is the most efficient, because you just need to know SQL queries and a little bit about how indexes work and how they can be used for optimization.
To write a SELECT query, you don’t need to know about the existence of binary search or trees. It is desirable to know trees and to know better how indexes physically work in the database you are using, but this is not necessary information. But even if you don’t know it, you won’t make a bad programmer.
But is it interesting to write simple SELECT queries or a simple user interface? That’s the job of low-level programmers in most companies. Yes, they are the majority, but if you want to do more serious things, write business logic, create something new, you need algorithms.
When working with large and complex projects, even when storing data in the database, it is desirable to know the search algorithms and at least understand how the data is accessed. I can’t get tired of giving examples of programmers writing code like:
Listemployees = DataProvider.GetEmployees();
Listpositions = DataProvider.GetPositions();
foreach (Employee e in employees) {
e.Position = positions.Where(p => p.PositionID == e.PositionId).FirstOrDefault();
}
The meaning of the code is simple – we get a list of employees and a list of positions from the database. Each employee in the list has only a position ID (Employee.PositionID). Our task is to find the ID of the position in the list of positions and link it to the employee.
Such tasks are very common and how often I see the code shown above. No, it’s not shit code, but it is absolutely inefficient because the authors don’t know how search works. They have read somewhere that LINQ is great at optimizing queries and performing them quickly, but the search capabilities also depend on the data structure.
You don’t need to write your own efficient search; you just need to know how the data structures work internally and which search is most efficient and then you will know where the inefficiencies lie.
So even though you’re not going to write a search algorithm, the knowledge you’re going to apply all the time when you’re writing code like this. And in this case it’s better to turn the second array into a Lookup, Dictionary or Hash, and it will work at a completely different speed:
Listemployees = DataProvider.GetEmployees();
var positions = DataProvider.GetPositions().ToLookup(….);
foreach (Employee e in employees) {
e.Position = positions[e.PositionId];
}
I agree that 90% of programmers don’t write code that directly uses algorithms, but almost all of us write code when we need to understand algorithms to write better and more efficient code.
How much depth to go into them? I don’t think there should be a limit. At the very least you need to know sorting and searching – that’s just the masthead.
By the way, in the first question I think there was also a sub-question that you only need to know the algorithms to pass the interview. So, searching and sorting are the things you need understanding for everyday life and knowledge for a successful interview. It’s very rare to actually write sorting or searching, I can’t remember the last time that happened in my practice.
And the rest algorithms, which are written in more serious books – probably, you will never use them in your practice too, especially if you work in Web, but just for self-development, it is pleasant to read and learn some things!
Speaking specifically about the implementation of algorithms, then there are more often encountered game makers. Even when writing something simple, such as mobile games, you have to deal with mathematics and implement some algorithm yourself. If search or sorting is already implemented in most languages and platforms, then finding a shortcut between two points on the field will most likely have to be implemented yourself.
I am interested in implementing some logic, which is more complicated than simple Web applications, which is probably why I write games for iOS for fun.