Sorting

comments 4
Uncategorized

I was going to start this by talking about an earworm that’s been bothering me but I couldn’t make it work. (I don’t claim that what I’ve done is good or anything, of course, but trust me — it was worse  before.)

Sorting is often important. Why? Well, if you’re looking for something (and who doesn’t look for something from time to time) it’s a heck of a lot easier when the ‘things’ you’re searching through are sorted in some way. If you’re looking for (say) a book, it helps if the collection of books is sorted using some — any — scheme. This scheme can be complex (The Library of Congress Classification system springs to mind. Or maybe the Dewey Decimal system.) to simple (alphabetical by author, perhaps). There are valid reasons to choose any of the above schemes (or others!) but any scheme makes life easier. (Oh, all right — it’s from the Red Scare, a Tick villain. I’m not sure where Samoa comes in.))

(Aside: I have my own scheme — two, actually. My books are scattered through five or six rooms (including the basement), sorted — more or less — by size and colour. For this post I dug up my copy of Sedgewick but to do that I had to remember that it’s blue. And my comic books are in boxes under a bed in the spare room where each box represents a different publisher. To find (say) my copies of Cerebus the Aardvark I have to remember that it was published by Aardvark-Vanaheim. A-V didn’t publish a whole lot else, so they don’t have a box of their own so I have to remember the publisher they share a box with. (The sticky notes last about a day.) And god help me if I’m looking for a comic that changed publishers. Despite the somewhat…quirky nature of these ‘schemes’, they’re better than nothing — stuff is still sorted. Not particularly well, but it’s enough: I can find things when I need to.)

Sorting is often taught in introductory courses in computer science. (At least it was thirty years ago. I meant to ask Lead Rose if it still is (she’s a computer science educator and researcher, after all) but I didn’t get around to it. So much for exhaustive research and careful attention to detail.) It was (is?) taught for several reasons. First of all, as I’ve discussed above, it’s a moderately important topic. Secondly, it’s fairly simple to teach, at least at the introductory level. Thirdly, it’s a problem that lets the instructor discuss different ways of achieving the same goal: ie. different algorithms. (This sorting algorithm is easy to code. That sorting algorithm is efficient for ‘almost-sorted’ data. That other sorting algorithm is stable. And so on. Back in the day in computer science 101 I/we were taught some of the worst sorting algorithms in the history of the world, probably because those are the ones that are easy to explain to a room full of surly, somnolent adolescents at 8:30 on a Monday morning. For most of my life since then I’ve been partial to mergesort, but only because that’s what I’ve had easiest access to — someone else did all the hard work. Laziness is, after all, a virtue — if you’re a programmer.)

Somewhere else where sorted ‘things’ can be relevant is, well, retail. In some stores, things aren’t sorted (or, if they are, it’s using a scheme that’s kept secret from the customer base). Those are the stores that have people (me, for example) wandering about them in a daze, looking lost and unhappy. Worse, every damned store that has a scheme has its own and all of them have, to put it mildly, quirks. For example, a supermarket near me used to display lime-flavoured sparkling water several aisles away from where they displayed lemon-flavoured sparkling water. And a prominent technology peddler places one size of digital memory in a different department than the other sizes. And I said “used to” — things change. Change can be good, but as a famous mathematician (who doesn’t live around the corner from me) once said “The progress of civilisation is not wholly a uniform drift towards better things.” Change isn’t always for the better — the fizzy beverages are now More Sorted, but I have no doubt that something else is less.

But it’s not all chaos, not all disorder, not all confusion. There are (often localized) ‘islands’ where things are sorted. Like spices.

Some places they’re arranged in a (to first appearances) completely random fashion. I’ve seen them sorted by size of container. I’ve seen them sorted by producer. I’ve seen them sorted by something like popularity. But I’ve also seen them sorted by name.

I like that. That’s actually, like, useful.

And that’s where the story actually begins.

There’s a store that we shop at fairly regularly. It’s a local establishment, not a chain and if I had to pigeonhole it, I’d call it a health food store. (I still haven’t quite forgiven them for forcing the nice pumpkin tart lady into retirement, but I’m trying to move on. Honestly I am.)

Anyway, they sell spices. In bulk, so instead of spending five bucks on a teeny little jar of something, I spend, um, less (one-tenth? probably something like that) on a teeny little baggie that holds more. At one point there was a sort of a wall of bins, arranged alphabetically by name of spice (yay) with a jumble of glass jars on the floor that held things that didn’t fit in The Wall. The bins were sorted (mostly) and so were the jars, but they weren’t sorted together, if that makes sense.

Then there were renovations. Changes. Unexpectedly, though, these ones were for the better. (Well, mostly.) In particular, the jars Went Away and the wall-o-bins was made bigger — big enough to hold pretty much everything.  So everything was sorted, the sun shone, the bells rang and the elves barfed. (Bet you didn’t know that elf vomit smells like nutmeg. There wasn’t a bin for it, though.)

And that’s the way things stood when we ran out of five-spice powder.

Five-spice powder is a mixture of (duh) five spices. Wikipedia tells me that it’s traditionally used in Chinese, Asian and Arabic cuisine. We are none of the above, but we have a Rock Pile. The Rock Pile is what Peg Bracken called the thirty or so recipes that would get anyone through a month of dinners. One of the recipes in our pile has five-spice powder in it.

That means we don’t run out of it very often, but last week we did, so it was off to the store, off to the sorted wall of bins.

It wasn’t there.

The first question in my mind was something like “Well, how do you spell it? With an ‘F’ or with a ‘5’?” If you spell it with the letter ‘F’ then I would look for it under ‘F’ (duh). If you spell it with the digit ‘5’, then where? In ASCII, the numbers come before the letters. In EBCDIC (it’s unlikely they’d be using that, I admit), the numbers come after the letters. Some people, though, interleave numbers with letters — they’d put ‘5’ under ‘F’. I looked in all three places. It wasn’t in any of them. I tried the old standby — the exhaustive search (used for unsorted data, sigh). It was under ‘C’ — for Chinese.

Oh.

Sometimes sorting isn’t enough.

Advertisements

The Author

Rose Glace is the pseudonym of nobody important.

4 Comments

  1. Pingback: Dissing – Rose Glace's Blog

  2. Pingback: Installing – Rose Glace's Blog

  3. Pingback: Varying | Rose Glace's Blog

  4. Pingback: Ricing – Rose Glace's Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s