These types of threads get wild and I am reluctant to chime in because there are always many, many experts on these topics. With that said, take my simple statements at your own risk. I will state that my profession is the design of engines that many of you probably own.
Knock and detonation are a result of cylinder temperature. Temperature is defined by a number of things including ambient air temperature, geometric compression ratio, engine load, etc. Temperature in a IC engine changes as the volume of the cylinder changes and as thermodynamic processes (combustion) take place. Octane (although not really a great indicator) is a rating of a fuel's ability to resist combustion. There is a direct relationship between the Octane number and the energy required to start combustion.
Its important to understand there is a difference between knock and pre-detonation. An ECU can pick-up pinging (knock) and make adjustments to attempt to deal with that. The quickest method is to pull out timing. On most modern engines it works pretty well. If an engine experiences true pre-detonation, which is uncontrolled combustion as the result of high pressure waves that snowball on top of one another, there is nothing to be done, it runs away in fractions of a second and will destroy your engine. No amount of timing adjustment will fix that.
Something one may find interesting is that many of today's turbocharged gasoline engines run on the knock line constantly. They only make rated power on premium fuel and under WOT conditions are constantly mitigating knock.
All of that said, the general theme in this thread is correct; that at higher altitudes, cylinder temperatures (and hence pressure) will be lower and the required octane to prevent engine damage is reduced. It is also true premium fuel is called premium not really due to its octane rating, but because it is of much higher quality. As some mentioned in here, buy the best fuel you can afford. It doesn't hurt! I've ran Tecumseh snow blower engines on race gas left over from the summer. No difference in operation other than the exhaust had an awesome aroma!