Quicksort – Algorithm 63, and 64

Quicksort is a well-known sorting algorithm developed by C. A. R. Hoare in 1962 while working for the small British scientific computer manufacturer Elliott Brothers Ltd. [1, 2]. In his 1980 ACM Turing Award Lecture [3] he describes how a course on Algol 60, taken in early 1961 introduced him to the concept of recursive procedures. The presence of recursion in Algol 60 allowed Hoare to write Quicksort, a concept he had invented while trying to improve upon the Shellsort of Shell [4]. The entire algorithm was described in half a page, and comprised of two algorithms (written in Algol 60): Algorithm 63 which described the partition function, and Algorithm 64 which performed the actual Quicksort function. One of the greatest benefits of Algol 60 was the fact that it, unlike Fortran, allowed recursion.

Algorithm 64

procedure quicksort (A,M,N); value M,N;
array A; integer M,N;
comment Quicksort is a very fast and convenient method of
sorting an array in the random-access store of a computer. The
entire contents of the store may be sorted, since no extra space is
required. The average number of comparisons made is 2(M-N) ln (N-M),
and the average number of exchanges is one sixth this amount.
Suitable refinements of this method will be desirable for its
implementation on any actual computer;
begin integer I,J;
if M < N then begin partition(A,M,N,I,J);
quicksort(A,M,J);
quicksort(A,I,N);
end
end quicksort

Algorithm 63

The original Algol algorithm as published in Communications of the ACM, used a series of goto statements to facilitate the partitioning of the array into those items less than the pivot, and those items greater than the pivot.

procedure partition (A,M,N,I,J); value M,N;
array A; integer M,N,I,J;
comment I and J are output variables, and A is the array (with
subscript bounds M:N) which is operated upon by this procedure.
Partition takes the value X of a random element of the array A,
and rearranges the values of the elements of the array in such a
way that there exist integers I and J with the following properties:
M ≦ J < I ≦ N provided M < N
A[R] ≦ X for M ≦ R ≦ J
A[R] = X for J < R < I
A[R] ≧ X for I ≦ R ≦ N
The procedure uses an integer procedure random(M,N) which
chooses equiprobably a random integer F between M and N, and
also a procedure exchange, which exchanges the values of its two
parameters;

begin real X; integer F;
F := random(M,N); X := A[F];
I := M; J := N;
up: for I := I step 1 until N do
if X < A[I] then go to down;
I := N;
down: for J := J step -1 until M do
if A[J] < X then go to change;
J := M;
change: if I < J then begin exchange(A[I],A[J]);
I := I + 1; J := J - 1;
go to up
end
else if I < F then begin exchange(A[I],A[F]);
I := I + 1;
end
else if F < J then begin exchange(A[F],A[J]);
J := J - 1;
end;
end partition

Further reading

  1. Hoare, C.A.R., “Algorithm 64 Quicksort”, Communications of the ACM, 4(7), p.321 (1961)
  2. Hoare, C.A.R., “Algorithm 63 Partition”, Communications of the ACM, 4(7), p.321 (1961)
  3. Hoare, C.A.R., “The Emperor’s Old Clothes”, Communications of the ACM, 24(2), p.75-83 (1981)
  4. Shell, D.L., A high-speed sorting procedure”, Communications of the ACM, 2(7), pp.30-32 (1959)

Is technology dehumanizing society?

Who would have thought in the 1970s that there would be a time when a small metal and glass rectangle could be used to summon the world. I can find out where I am in the world, order just about anything I need, have food delivered to me wherever I am, taking photographs. Its uses are endless, and yet it sometimes leaves me with somewhat of an empty feeling.

Technology was suppose to be a boon to humankind. In the 1950s it was heralded as the breakthrough that would simplify many things, from simplifying flying, to calculating distances on road trips – and many of these things made life easier in the decades that followed. But these were machines that didn’t exactly interfere with daily life, instead they allowed labour intensive calculations to be performed in an efficient manner. Dr. Grace Hopper once described the Remington Rand computer as “an extremely fast moron” (Popular Science, Nov.1956). She goes on to say “It will, at the speed of light, do exactly what it is told to do – no more, no less.”

The monolith from 2001: A Space Odyssey – Was this really a large iPhone?

Now computing has achieved many things – connected the world, made life easier for many people, and improved efficiencies. But there have also been downsides, mostly to do with the effect of computers on humans. First of all, technology is the king of distraction. This was kept in balance when machines only existed on the desktop, but the advent of mobile computing means that humans basically have a computer at arms length basically all day. Apps exist to steal peoples attention with tidbits of information used to cloud a human’s ability to think. You can spend hours looking at Instagram reels, a small portion of which contain any real useful information – and it’s random information.

It is ultimately leading to changes in human behaviour, from an inability to interact face-to-face with other people to increased levels of anxiety and depression (partially because people end up comparing themselves to others, and feel as if they are missing out because they are not spending their lives traipsing around the world). People have become disconnected from nature and the world around them.

The goal of technology should be to provide efficiencies, and solve problems. Instead it almost seems like technology has become an extension to the mind, with little or no ability to unplug. The inclusion of technologies such as AI means there is often little or no reason for people to think – because answers to everything are provided (or so people would think). Ultimately this leads to a reduction in creativity, and problem solving abilities – why solve a problem when the machine can do it for you? This is even more problematic in children that are given access to technology at an early age – in all likelihood they won’t evolve the same skills as those in previous generations (and some would like to think they are evolving other skills, but humans don’t evolve that quickly).

There are many good things that technology has done for humans, but we can’t let it control our lives. Computers are just tools, and we should learn to reduce our dependence on them.