An elephant in Cairo is a term used in
computer programming
Computer programming is the process of performing a particular computation (or more generally, accomplishing a specific computing result), usually by designing and building an executable computer program. Programming involves tasks such as ana ...
to describe a piece of data that matches the search criteria purposefully inserted at the end of a search space, in order to make sure the search algorithm terminates; it is a humorous example of a
sentinel value
In computer programming, a sentinel value (also referred to as a flag value, trip value, rogue value, signal value, or dummy data) is a special value in the context of an algorithm which uses its presence as a condition of termination, typically in ...
. The term derives from a humorous essay circulated on the
Internet
The Internet (or internet) is the global system of interconnected computer networks that uses the Internet protocol suite (TCP/IP) to communicate between networks and devices. It is a '' network of networks'' that consists of private, pub ...
that was published in
''Byte'' magazine on September 1989, describing how various professions would go about hunting elephants.
Algorithm
When hunting elephants, the article describes programmers as following this algorithm:
:# Go to
Africa
Africa is the world's second-largest and second-most populous continent, after Asia in both cases. At about 30.3 million km2 (11.7 million square miles) including adjacent islands, it covers 6% of Earth's total surface area ...
.
:# Start at the
Cape of Good Hope
The Cape of Good Hope ( af, Kaap die Goeie Hoop ) ;''Kaap'' in isolation: pt, Cabo da Boa Esperança is a rocky headland on the Atlantic coast of the Cape Peninsula in South Africa.
A common misconception is that the Cape of Good Hope is t ...
.
[The ]Cape of Good Hope
The Cape of Good Hope ( af, Kaap die Goeie Hoop ) ;''Kaap'' in isolation: pt, Cabo da Boa Esperança is a rocky headland on the Atlantic coast of the Cape Peninsula in South Africa.
A common misconception is that the Cape of Good Hope is t ...
has been traditionally believed to be Africa's southernmost point, but that is actually Cape Agulhas
Cape Agulhas (; pt, Cabo das Agulhas , "Cape of the Needles") is a rocky headland in Western Cape, South Africa.
It is the geographic southern tip of the African continent and the beginning of the dividing line between the Atlantic and Indian ...
''.
:# Work northward in an orderly manner, traversing the continent alternately east and west,
:# During each traverse pass:
:#:* Catch each animal seen.
:#:* Compare each animal caught to a known elephant.
:#:* Stop when a match is detected.
This algorithm has a bug, namely a
bounds checking
In computer programming, bounds checking is any method of detecting whether a variable is within some bounds before it is used. It is usually used to ensure that a number fits into a given type (range checking), or that a variable being used as a ...
error: if no elephants are found, the programmer will continue northwards and end up in the Mediterranean sea, causing
abnormal termination
An abnormal end or abend is an abnormal termination of software, or a program crash.
This usage derives from an error message from the IBM OS/360, IBM zOS operating systems. Usually capitalized, but may appear as "abend". Some common ABEND codes ...
by
drowning
Drowning is a type of suffocation induced by the submersion of the mouth and nose in a liquid. Most instances of fatal drowning occur alone or in situations where others present are either unaware of the victim's situation or unable to offer a ...
.
Thus experienced programmers modify the above algorithm by placing a known elephant in
Cairo
Cairo ( ; ar, القاهرة, al-Qāhirah, ) is the capital of Egypt and its largest city, home to 10 million people. It is also part of the largest urban agglomeration in Africa, the Arab world and the Middle East: The Greater Cairo metro ...
to ensure that the algorithm will terminate.
The modified algorithm is therefore as follows:
:# Go to
Africa
Africa is the world's second-largest and second-most populous continent, after Asia in both cases. At about 30.3 million km2 (11.7 million square miles) including adjacent islands, it covers 6% of Earth's total surface area ...
.
:# Put an elephant in
Cairo
Cairo ( ; ar, القاهرة, al-Qāhirah, ) is the capital of Egypt and its largest city, home to 10 million people. It is also part of the largest urban agglomeration in Africa, the Arab world and the Middle East: The Greater Cairo metro ...
.
:# Start at the
Cape of Good Hope
The Cape of Good Hope ( af, Kaap die Goeie Hoop ) ;''Kaap'' in isolation: pt, Cabo da Boa Esperança is a rocky headland on the Atlantic coast of the Cape Peninsula in South Africa.
A common misconception is that the Cape of Good Hope is t ...
.
:# Work northward in an orderly manner, traversing the continent alternately east and west,
:# During each traverse pass:
:#:* Catch each animal seen.
:#:* Compare each animal caught to a known elephant.
:#:* Stop when a match is detected.
:# If you are in Cairo, then there are no elephants in Africa (other than the one you placed there).
See also
*
Elephant test
The duck test is a form of abductive reasoning, usually expressed as "If it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck."
The test implies that a person can identify an unknown subject by observing t ...
Notes
{{reflist, group=notes
References
External links
List of the other elephant hunting techniques(PDF)
Computer humor
Metaphors referring to elephants