JargonFile/original/html/F/fencepost-error.html
2014-03-27 18:54:56 +00:00

25 lines
3.3 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>fencepost error</title><link rel="stylesheet" href="../../jargon.css" type="text/css"/><meta name="generator" content="DocBook XSL Stylesheets V1.61.0"/><link rel="home" href="../index.html" title="The Jargon File"/><link rel="up" href="../F.html" title="F"/><link rel="previous" href="fence.html" title="fence"/><link rel="next" href="fiber-seeking-backhoe.html" title="fiber-seeking backhoe"/></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">fencepost error</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="fence.html">Prev</a> </td><th width="60%" align="center">F</th><td width="20%" align="right"> <a accesskey="n" href="fiber-seeking-backhoe.html">Next</a></td></tr></table><hr/></div><dt><a id="fencepost-error"/><dt xmlns="" id="fencepost-error"><b>fencepost error</b>: <span xmlns="http://www.w3.org/1999/xhtml" class="grammar">n.</span></dt></dt><dd><p> 1. [common] A problem with the discrete equivalent of a boundary
condition, often exhibited in programs by iterative loops. From the
following problem: &#8220;<span class="quote">If you build a fence 100 feet long with posts 10
feet apart, how many posts do you need?</span>&#8221; (Either 9 or 11 is a better
answer than the obvious 10.) For example, suppose you have a long list or
array of items, and want to process items
<tt class="literal">m</tt> through
<tt class="literal">n</tt>; how many items are there? The obvious
answer is <tt class="literal">n - m</tt>, but that is off by one;
the right answer is <tt class="literal">n - m + 1</tt>. A program
that used the &#8216;obvious&#8217; formula would have a fencepost error in
it. See also <a href="../Z/zeroth.html"><i class="glossterm">zeroth</i></a> and
<a href="../O/off-by-one-error.html"><i class="glossterm">off-by-one error</i></a>, 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 <tt class="literal">N</tt> people try to sit in
<tt class="literal">N - 1</tt> chairs, but it's not a fencepost
error. 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. </p></dd><dd><p> 2. [rare] An error induced by unexpected regularities in input
values, which can (for instance) completely thwart a theoretically
efficient binary tree or hash table implementation. (The error here
involves the difference between expected and worst case behaviors of an
algorithm.)</p></dd><div class="navfooter"><hr/><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="fence.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="../F.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="fiber-seeking-backhoe.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">fence </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> fiber-seeking backhoe</td></tr></table></div></body></html>