Interactive Preference Ranking

Breaking analysis paralysis in O(N lg N)

It’s not always easy to figure out the relative importance of our various preferences. For example, when trying to find a place to move, do you care more about price, walkability, parking, proximity to work, safety, …? Or when trying to find a job, is it about salary, equity, the interestingness of the problem, the people you work with, the opportunity to learn new things, the location, the quality of the coffee in the break room…? Or maybe you’re just picking dinner and you’re trying to balance healthiness versus cuisine type versus how long they take to deliver. It can be intimidating (at least for certain personality types, I suppose) to stare at such a list of characteristics and try to really rank which aspects you care about more than others.

I built a little tool to make this process easier by only making you consider one pair of options at a time. Try the live demo below and then I’ll explain more below.

Live demo: interactive preference ranking

(See the code at GitHub)


    Seeing too many options at a time is overwhelming, but given just a pair it’s often easier to decide whether we like “x” better than “y”, less than “y”, or equally as much. You can imagine setting up a tournament to rank the options using this information. This is exactly what a sorting algorithm does!

    Most languages allow you to specify a custom comparator function for sorting that given two elements x and y, decides which is the lesser. If in the comparator we prompt the user for input, we can run this tournament on the fly by hijacking the built-in sort.

    (There’s a catch, of course. This kind of sort assumes that comparisons are transitive: that if x > y and y > z, that x > z. This may not actually be true of our preferences, depending on how strictly rational you are. But I’ve found that the rankings produced by this method at the very least are a good starting point to break an impasse in thinking, after which you can permute the list as you like…)

    In this demo I implemented the method in JavaScript because the browser gives us some basic UI for user interaction and list display on the cheap. The code is online at GitHub if you’d like to play with it (warning: I make no claims to being a frontend engineer). The user prompting could certainly be better (JS doesn’t currently offer a simple prompt to get three possible responses that is universal across browsers without a polyfill), but it’s good enough to get the job done and show off the concept.

    The only slightly tricky thing going on here is in function find_equal_indices: it’s nice to be able to allow the user to indicate that some items are equal in value to others. However, because we only collect pairwise comparisons, even if the user has already indicated that x = y and y = z, the code does not directly know that x = z, so in this function we build up the equality mapping to make a cleaner output for the user.