june23's avatar

How many times have you used traditional algorithms and data structures professionally?

How many times have you implemented traditional algorithms such as bubble sort, quick sort, merge sort or even linear search and other search algorithms on a day to day basis? I have understood and I have even asked AI prompts like Gemini, that algorithms like the ones mentioned above are not needed because the Databases does all the heavy lifting. So my question is how would you implement algorithms such as binary search in a web application, for example, an E-Commerce websites search function? Would you create the search function from scratch using binary search or use the Database features? This applies to all features from a web application.

2 likes
5 replies
vincent15000's avatar

I know how to code these algorithms, but I never coded one of them in my personal or professional projects. For example PHP has enough functions to search, sort, merge, ...

1 like
Tray2's avatar

Database for sure, either the RDBMS itself, or a service like REDIS or similar. There are many search options to choose from, rolling your own will not be as performant and likely to increase the development cost over time.

If I use a external api that doesn't have the sorting I need, and if the payload is small, then I handle it myself rather then string it in the DB and process it from there. If it is a big payload, then I store it in the db, and let the db handle it.

What ever you build yourself will be slower and use more resources than the db.

2 likes
jlrdw's avatar

Jeffrey has a whole series on searching: https://laracasts.com/series/supercharged-search-with-typesense

There are also github packages.

But I just use the database. Many years ago I messed with b-tree a little in a pedigree program for progeny. But ended up just using the database even though it took a little longer. One dog way back in the generations took about 12 seconds on a slower computer, but only about 4 seconds on a faster computer. But if printed, I am talking about almost 200 pages of progeny (only 5 generations back). So I figured 4 seconds to display this wasn't too bad. Imagine if 6 or 7 generations.

Even a search right now on amazon is about 3 seconds before the page is usable. Try it, go there and just punch in cat toys. So with a lot of results per page don't fret if it's a couple of seconds.

For speed simple use less results per page. Of course we are talking images here also.

Just visit some sites and count as the page loads. Even here there is at least a second delay sometimes on a first page load, and faster as you continue.

I can't believe the folks that expect every page will load every time in a millisecond.

Text will load faster, images longer. And depends on the amount per page.

2 likes
JussiMannisto's avatar

The blunt answer is no, you don't (and shouldn't) implement these things yourself if you're looking to deliver a product.

  1. Databases and search engines are dedicated projects that have been developed and battle-tested over years or decades. They use optimizations and heuristics that go way beyond primitive algorithms.
  2. If you were to implement your own search engine in a commercial app, someone would have to maintain it indefinitely. You'd better document it really well.

You use low-level algorithms indirectly all the time through PHP function calls and database queries, not to mention the operation system and all its utilities. But at the web application layer, you almost never need to implement them yourself. You're usually not doing heavy in-memory processing to begin with, but if you are, the language probably has you covered. It's impossible to write something like quicksort in PHP that's as fast as the built-in implementation written in C.

2 likes
june23's avatar

Okay thank you for the information! Just what I was thinking, but I needed to hear it from professionals :)

1 like

Please or to participate in this conversation.