|
In computer programming, a fencepost error – rarely called a "lamp-post error" – is a computer bug involving the discrete equivalent of a boundary condition, often exhibited in programs by iterative loops. This can also occur in a mathematical context, but is not usually named. Computer programming (often simply programming) is the craft of implementing one or more interrelated abstract algorithms using a particular programming language to produce a concrete computer program. ...
A computer bug is an error, flaw, mistake, failure, or fault in a computer program that prevents it from working correctly or produces an incorrect result. ...
In mathematics, boundary conditions are imposed on the solutions of ordinary differential equations and partial differential equations, to fit the solutions to the actual problem. ...
In computer science and in computer programming, statements in pseudocode or in a program are normally obeyed one after the other in the order in which they are written (sequential flow of control). ...
Mathematics, often abbreviated maths in Commonwealth English and math in American English, is the study of abstraction. ...
The following problem illustrates the error: - "If you build a fence 100 feet long with posts 10 feet apart, how many posts do you need?"
Many people will immediately answer 10, which is incorrect. The fence certainly has 10 sections, but the posts lie at the boundaries of these sections. We can consider each section in turn and place a pole at its left-hand end: thus for each section there is one pole. However, the common error lies in that the end of the final section has not yet been given a pole: this is the 11th. Conversely, in a row of 10 lamp-posts there are 9 gaps between them. In computing, suppose you have a long list or array of items, and want to process items m through n; how many items are there? The obvious answer is n−m, but that is off by one; the right answer is n−m+1. The "obvious" formula exhibits a fencepost error. (This is the motivation behind the representation of ranges in computing by half-open intervals: the range from m to n (both inclusive) is very often represented by the range from m (inclusive) to n+1 (exclusive) to avoid fencepost errors.) In computer programming, an array, also known as a vector or list, is one of the simplest data structures. ...
In elementary algebra, an interval is a set that contains every real number between two indicated numbers, and possibly the two numbers themselves. ...
See also zeroth and note that not all off-by-one errors are fencepost errors. The game of Musical Chairs involves a catastrophic off-by-one error where n people try to sit in n−1 chairs, but this is not a fencepost error (see also pigeonhole principle). Fencepost errors come from counting things rather than the spaces between them, or vice versa, or by neglecting to consider whether one should count one or both ends of a row. The zeroth item is the initial item of a sequence, if that sequence is numbered beginning from zero rather than one. ...
An off-by-one error in computer programming is an avoidable error in which a loop iterates one too many or one too few times than desired. ...
Musical Chairs is a game played by a group of people, often in an informal setting purely for entertainment such as a birthday party. ...
The pigeonhole principle states that if n pigeons are put into m pigeonholes, and if n > m, then at least one pigeonhole must contain more than one pigeon. ...
A rare secondary meaning is an error induced by unexpected regularities in input values, which can (for instance) completely thwart a theoretically efficient binary tree or hash function implementation. The error here involves the difference between expected and worst case behaviours of an algorithm. In computer science, a binary tree is an ordered tree data structure in which each node has at most two children. ...
A hash function is a function that converts an input from a (typically) large domain into an output in a (typically) smaller range (the hash value, often a subset of the integers). ...
Flowcharts are often used to represent algorithms. ...
An earlier version of this article was based on fencepost error (http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=fencepost%20error) at FOLDOC (http://www.foldoc.org), used with permission. Received: from diver. ...
|