I collect vinyl, and I'd just finished the Trees and Graphs module on Codecademy's Computer Science path. So when the portfolio project asked me to build a recommendation program, the choice made itself: a tool where you type a couple of letters, and it suggests a genre from my shelves, then ranks the best records in it. It's small, but it let me put two things I'd just learned — a tree structure and a sorting algorithm — to work on data I actually care about.
How it works
You type a few letters, the program suggests a matching genre, and if you say yes, it prints that genre's albums ranked best-first.
The code
The program has two moving parts. The first is a trie — a tree that stores each genre one letter per node, so words sharing a start (like rock and rap) share nodes. Typing letters is just a walk down the tree: from the letters you enter, I step to that node and collect every complete genre in the subtree below it. That's the autocomplete behaviour, and it's a plain recursive tree traversal underneath. The second part is a quicksort that ranks a genre's albums by rating before display. I wrote it to take a key function, so the same sort can order by rating or by year without changing the algorithm — it partitions each list around a pivot into higher, equal, and lower buckets and recurses. The data lives in a dictionary mapping each genre to a list of album records, and a short terminal loop ties it together: read input, search the trie, sort the results, print them.
Code on GitHub: https://github.com/ioanadaria/music-recommender
Conclusion
Building this made a trie click in a way the lessons alone didn't — seeing shared prefixes fall out of the structure for free, rather than being something I had to code. The obvious next step is letting the user pick when several genres match instead of defaulting to the first, and swapping the sort key to rank by year. If you're learning data structures, I'd recommend picking data you find fun; debugging a trie is a lot more motivating when the payoff is a record recommendation.

Top comments (0)