Apply algorithms in the real world

When Would I Apply Algorithms in The Real World?

I was asked by a colleague at UoPeople about how he would apply algorithms in the real world, outside of the classroom. I think it’s an interesting question, and thought it was worth sharing my personal experience as a web developer.

The other part of the questions was on data structures such as stacks, queues and linked lists. This is roughly what I said as a reply…

Most of the algorithms you learn in a computer science class you would never have to implement in real life. If you need to sort some data, the programming language you’re using already has those algorithms implemented. For example in JavaScript to sort an array called myArray I would just do myArray.sort().

Most languages already have built in data structures for linked lists, stacks and queues also.

As for some examples of how data structures get used:

Handling messages of any type is a good example of when you would use a queue. For example Slack (the platform we were having this discussion on) depends heavily on queues. Web browsers depend heavily on queues too. Every event in a web browser gets added to a queue until it’s able to be processed.

A good use case for a Stack is handling navigation history in an app. The last thing the user did will always be on the top of the stack, so if they click “back” you simply pop the stack to bring them back one in the history.

Even stacks and queues you may not ever use, only because there are libraries out there that abstract them away for common use cases, like handling history for example.

Linked lists – actually doubly linked lists are used by Git to store the differences in each commit to your code base.

It depends on what you end up doing. The more complex and specific the system is, the more likely you are going to need to create a custom implementation of one of these data structures or algorithms, or even devise your own algorithms and data structures.

The better thing to understand is not how these algorithms are implemented, but why it is they are used and what problems they solve. If you understand that well, you’ll be able to recognize the times in real life when you may want to use one.

That basically sums up the points I made in our discussion. The one thing I have to admit, is that I haven’t worked for companies building large scale systems. So I haven’t been presented with the sorts of challenges that would require me to build or implement my own algorithms.

However, with that said, the same problem solving skills I used in those early computer science classes are still applied to my work.

Being a good developer is more about being a good problem solver. Knowing about common algorithms and data structures used in computer science becomes tools that aid you in your problem solving abilities.

It’s not that you would actually build a hash set from scratch, but knowing when it’s beneficial to use one sure comes in handy.

If you liked what you just read, don’t forget to share! Also, follow me on Facebook or Twitter to get regular updates from my blog.

Have you any experience using data structures and algorithms in a real work setting? Let me know in the comments!



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Show Buttons
Hide Buttons
%d bloggers like this: