Archive for January, 2007

Revisiting heap sort

Thursday, January 25th, 2007

Among the day’s mysteries is how, despite having a long list of things to do, I found myself reading the Wikipedia entry on heap sort. Which leads to an admission: I never really “got” heap sort.

Back when I was studying the basic sorting algorithms, I passed heap sort over in favor of order preserving sorts like bubble sort, quick merge sort, and that great bar bet winner when you’re arguing with someone who insists that O(n log n) time is the best you can do, radix sort. Heap sort struck me as taking a lot of haphazard swapping to achieve a result that didn’t preserve order, and most of the sorting I needed to do required preserving order. So, bye bye heap sort.

Since then, there’s been no reason to revisit the issue. When I count the number of times in the last decade that I’ve coded up a sort routine, I don’t even have to use any fingers. The built-in sort in whichever language I’ve been coded with has always been good enough for the problem at hand. I’ve reinvented plenty of other wheels, but never sorting.

So why, when there’s work to do, spend a half-hour puzzling through the heap sort algorithm? Damn good question. Stumbling on a reference to it might have tweaking some latent guilt (of the “I made it through College without ever having read <pick a classic>, and one day they might find out and revoke my diploma” variety). Or maybe I was bored and needed a shot of intellectual stimulation. Grokking heap sort is a bit of a challenge. It strikes me as the type of algorithm that was dreamed up by someone whose idea of fun is figuring out ways to do long sequence of captures in checkers.

Was it worth the time? I think so. I may never need a heap sort, but the form of the algorithm is a good reminder that two-pass attacks, where the first pass does some non-immediately-obvious setup that the second pass can exploit, can be effective against some problems.

A reader kindly pointed out that I had my sorts confused, and that it’s mergesort that preserves order, not quicksort. I rechecked, and yup, I’d gotten them backwards.

An appropriate level of care

Monday, January 22nd, 2007

Thumbing through Gerald Weinberg’s The Psychology of Computer Programming (first edition) to verify a quote, I found a snippet that I’d underlined while at college, working for the college computer center.

“[E]ach program has an appropriate level of care and sophistication dependent on the uses to which it will be put. Working above that level is, a way, even less professional than working below it.”

I had no way then of knowing how true that would continue to be, but must have had some inkling of how finding the right level would be a challenge for many years to follow. It’s a challenge for teams and companies as well as for individuals. Companies, especially startups, can wound themselves mortally by shipping a bug-ridden product. And they can burn through time and cash trying to build a “quality” product, when putting something half-baked but “good enough” out in front of customers sooner could have gained vital feedback that the product wasn’t quite right.

An unexpected “honor”

Saturday, January 20th, 2007

Tonight, without warning, and in the presense of friends who were already members, I was inducted into the honorary society of back yard grillers who’ve run out of propane in the middle of cooking for dinner parties.

Whiteboards and Cameras

Saturday, January 20th, 2007

You’ve spent the last fifty-five minutes of the meeting capturing information on the whiteboard, but you’re about to lose the room. People are already lined up outside the door, and you know the first thing they’ll do is erase the board. Or perhaps you’ve been discussing sensitive issues, and erasing the board is something you need to do before giving up the room. What becomes of the information?

Teams often rely on a designated scribe to take notes and email them out or post them on a Wiki. If that’s as far as you go, you risk information loss or corruption. Scribing is hard, especially when things are moving fast and people are drawing diagrams. A good way to mitigate this risk is to take and post pictures. That means having a camera at hand. A working camera.

I went through a few months of “O.K., who has the team camera?” and “Oh nuts, who has fresh batteries?” before heading off to the local office supply store to buy a 3 megapixel Nikon Coolpix. It’s lived in my pack for two years now, along with a set of spare rechargeable batteries (which get regularly rotated through the “to be charged” pile). 3mp is just at the limit for taking good whiteboard pictures. I’ve tried 2mp, but the results weren’t useable. The one problem is the flash, which tends to white out an area of the whiteboard, requiring either multiple shots or shooting off-center, which leads to odd looking results. If the room is well-lit, I can often get by without flash, but it’s risky.

Digital camera technology has advanced a bit since I bought the Nikon. Image stabilization and higher sensitivity sensors are now readily available for a quite reasonable amount of money. So, for my birthday this year, I arranged (by “honey, I emailed you a URL with an idea for a present, and it’s on Sale!”) to get a 6 megapixel Lumix DMC-LZ5. Image stabilization, plus greater scene control options in software to handle lighting and exposure, means better whiteboard pictures. (And better non-whiteboard pictures, of course.)

My wife got the Nikon, and our daughter got my wife’s old Canon, which is the perfect sturdy camera for a 9 year old.

Data that supports part of the Agile Manifesto

Tuesday, January 16th, 2007

Those who’ve become proponents of Agile after using Agile practices and seeing that they work are often at a loss when prospects ask for hard data instead of anecdotes and “trust me, it works!”. Steve McConnell has hard data on “soft factors” that supports “Individuals and interactions over process and tools“. It’s not new, but I missed it the first time by.

One caveat is that Steve leans heavily on a vetting of the Cocomo II estimation model. He writes:

“In Cocomo II terms, the influence of office environment is 2.6, which is significantly greater than that of process maturity.”

My dim memory on this, which I need to follow his references to check, is that the Cocomo II analysis happened before XP/Agile caught on, so the effect of “an office with a door” didn’t have the XP alternative of “quiet open seating for a team that is doing pair programming” to compare against. When you’re in a prairie dog cube farm, especially if you’re mixed in among people who yack on the phone, an office with a door is a big step up for productivity. A place for a team to work together where the only interruptions are other team members talking about the work the team has in progress can be a bigger step up. Or so it’s claimed. I’ve seen it work, but I need some better data to cite.

Five Things

Thursday, January 11th, 2007

Johanna tagged me for the “5 things you don’t know about me” meme. So:

  1. Thanks to an assistant Scout Master who worked at the phone company and had access to their GE Mark IV, I was the first Boy Scout in Nebraska to earn the Computer merit badge. (Thank you, Mr. Richardson.)
  2. On my first summer job, I got to drive a tow truck, a dump truck, a paving truck, and several hundred cars. For a while, I could back anything with four wheels into tight parking spaces.
  3. While camping in the Rocky Mountains, we hiked across the Continental Divide. There was a sign, with arrows pointing in each direction. Fulfilling the fantasy of every boy who ever learned about the Continental Divide in a boring Geography class, I peed on both sides of it.
  4. I performed the Heimlich maneuver at a dinner party. Looking it up now to check spelling, I learned that “Heimlich Maneuver” is a registered service mark.
  5. An article I wrote for PC World Magazine was translated into Japanese, but I didn’t find out about it until a year later when a small royalty check arrived along with a letter that mentioned an audit. I wonder how that happened…

I’m usually late to the party on memes like this, so it may take a while to find someone to tag.