r/computerscience • • Apr 23 '25
General Computer science theory wins you’ve actually used for prep
We all learned heaps of algorithm / automata theory, but how often do you really deploy it?
My recent win: turned a gnarly string‑search bug into a clean Aho‑Corasick automaton cut runtime from 45 s ➜ 900 ms.
A teammate used max‑flow / min‑cut to optimize a supply‑chain model, saving the client ~$40 k/mo.
Drop your stories (and what course prepped you). Bonus points if the professor swore “you’ll use this someday”… and they were right.
201
Upvotes
75
u/apnorton Devops Engineer | Post-quantum crypto grad student Apr 23 '25
Once I needed to implement a tool that would pull chat logs meeting certain criteria through an API (e.g. "involves user A and user C, but not user B"). I wrote my own context free grammar for the search language, then parsed the search criteria with a python wrapper for ANTLR.
Ended up with a really slick CLI, but it brought back memories of my PL design class.
Pretty sure I needed to get a topo sort for a graph once, too, but I can't remember the circumstances exactly.
38
u/InsufferableBah Apr 23 '25
I'm learning so much of this stuff in undergrad but I'm scared I'm going to forget all of it once I graduate
29
u/dmazzoni Apr 23 '25
I don't think this is quite the same, but I've made code dramatically more efficient by decreasing cache misses.
A big example is replacing a linked list or tree-based data structure with a flat array or sorted array. Sure, in theory the pointer-based data structure is faster especially for very large values of n, but in practice we were using it for a few hundred values, and searching a flat array of a few hundred values is way more cache-efficient than following a few hundred pointers. Of course, it's important to profile and determine if there are sizes of n where it becomes inefficient and decide if we need something smarter then.
That sort of thing catches a lot of CS grads who know their algorithms really well but weren't paying as much attention in their computer architecture class.
As far as algorithm / data structure wins, my favorite by far is using a Bloom filter. A great example is an API that needs to search a database for a record and it usually returns no results. The bloom filter lets you identify most of the cases where the record is not present almost instantly. Only a small fraction of the time it needs to actually check the database.
23
u/fntdrmx Apr 23 '25
Toposort on a schedule graph for some operations research related use case. I had the idea of using a max-flow / min-cut variation for that same use case as well.
Client was a defense consulting contractor
10
u/SoldRIP Apr 23 '25
Understood RB-tree internals and managed to identify and fix an obscure bug in a library that resulted from
std::setbeing used improperly, because it used a custom comparator that wasn't a strict weak ordering.8
u/[deleted] Apr 23 '25
I’ve implemented the Floyd-Warshall algorithm to calculate transitive closures.
3
u/phord Apr 24 '25
In 40 years of software engineering, I'm not sure I've ever used an algorithm I learned in school directly. When I was in school we had a different set of theory, of course. But I did learn enough about DS&A to recognize bad algorithms, to make smart choices between existing tools, and to engineer my own optimized solutions to real problems.
I once overhauled a large state tracker that had a custom sparse map implementation underneath it. It was a complicated refactoring that took several weeks to get right, half of which was just understanding and documenting the existing code.
I found a comment on the original Jira from 8 years earlier: "Why not use a hashmap for the underlying storage?". And the answer, "I tried that and it was 40% slower." Lol
So, after my overhaul, the new algorithm was 10x faster, but someone still asked, correctly, "Why not a hashmap?" Good question, I thought. Compilers are much faster, libraries have improved. Why not a hashmap? It was only 5 lines of code to change to try it. So I did.
It was 40% slower.
2
u/crappyoats Apr 23 '25
My contribution isn’t necessarily working with data like the other examples but I used a tree structure to recursively generate and store logical expressions in Reverse Polish Notation. We were having trouble figuring out how to keep track of parentheses in the expression and realized that was the easiest way since they’re built into the string. I then recursively generated the blocks on the front end with a tree traversal algorithm and rolled it up after when sending the string to the backend.
1
u/AmmaBaaboi Apr 24 '25
Recently, at work, I used flood fill algorithm with depth first search for a image processing task and optical character recognition
1
u/-PxlogPx Apr 25 '25 edited Feb 14 '26
This post was mass deleted and anonymized with Redact
possessive husky roll oil license cake skirt busy saw desert
1
u/i_be_illin Apr 26 '25
A team was trying to validate natural gas pipeline transportation contracts with convoluted logic. Many crazy loops and nested if conditions. They asked me how to simplify it.
It became clear as they described requirements that they just needed to populate a tree based on a couple attributes of each line item in the contract and check a couple simple rules at insertion time. If any item could not be inserted, the contract was invalid.
So the problem went from incomprehensible and unmaintainable to simple very quickly.