45
$\begingroup$

It can be perplexing for students to begin counting at 0 when they enter a CS class. I made it a point over and over to talk about "Day 0" and "Week 0" in the opening days and weeks just to build familiarity with the idea. Even so, I sought when explaining this idea to ground it in some real-life/non-CS example where we as humans use 0-indexing naturally and possibly without knowing it.

Question: where can we find 0-indexing outside of CS and grounded in everyday human experience?

I'll share the one example I can think of below (Q&A style), but I'd love to hear more, potentially better, examples.

[Note: This question relates to another I just posed.]

$\endgroup$
17
  • 19
    $\begingroup$ The index of an array is a measure of the distance from the start. (not what you asked for, but another way to explain it). $\endgroup$ Commented May 27, 2017 at 10:12
  • 4
    $\begingroup$ There are a few here: en.wikipedia.org/wiki/Zero-based_numbering $\endgroup$ Commented May 27, 2017 at 10:32
  • 7
    $\begingroup$ When playing board games, my six year old starts counting from zero, for the square her counter is on. $\endgroup$
    – Miles
    Commented May 27, 2017 at 19:13
  • 5
    $\begingroup$ One is the first natural number, but nought is the zeroth. $\endgroup$
    – Miles
    Commented May 29, 2017 at 18:41
  • 10
    $\begingroup$ As seen by the majority of the comments, the key is to separate index from count. index relates to distance or movement, which has zero as the beginning, while count relates to quantity, which has a (possibly) natural beginning of one. If the students have the proper level of mathematics, you can also use the powers-of-10 (the first, lowest, digit is x*10^0. $\endgroup$ Commented May 30, 2017 at 13:44

21 Answers 21

49
$\begingroup$

You can get at this concept very intuitively in strings before you ever get to arrays. Take a string like "hello world" and ask them a subtle-sounding point: does the string begin here: "*hello world", or here: "h*ello world". They'll certainly be able to identify the correct answer.

Then ask, "how far from the start of the string do we have to go to get to the 'h'? Answer in a number of characters. Do we have to move 5 characters away? 3? 1?" Again, they should be able to identify 0.

Now, it's time for the big reveal. (My description here is in Java)

"When I want to get at that first character, h, I do it with myString.charAt(0). Given what we just discussed, why do you think I would use 0, and not 1?"

At this point, they will naturally move to the idea that it is at the beginning, and that we have moved no steps from the beginning.

"Excellent. This is an example of an index value. And, in Java, when we do index values, we don't count from '1', we actually count the DISTANCE from the start. So, if we want the first character, we move no distance. And how far do we move to get the 3rd character? ..."

When you later get to arrays, you can remind them of the concept, and just say that it is being used again here.

$\endgroup$
1
  • 6
    $\begingroup$ I like this. You can get more real-life examples based on counting the DISTANCE. e.g. If you knock on the first door in an apartment block and ask where Alice lives, they say 'go down 3 doors', that's like indexing into the array of apartments. And if Alice lives in the first then you don't move, ie you go down 0 doors. $\endgroup$
    – Rory
    Commented May 27, 2017 at 21:26
44
$\begingroup$

Ages in the United States (it's not the same around the world).

For the first year of life, children are 0 years old. Only after completion of a year is the age changed to 1. By this logic, a child in his/her second year of life is 1 just as the second element of an array is found at index 1.

Edit: another example is the counting of centuries. An event occurring in the 100s would be in the second century.

Edit #2: watching the Champions League Final, I just thought of another: the timing of soccer. A goal scored during the 20th minute is scored while 19:xx is on the clock.

$\endgroup$
6
  • 12
    $\begingroup$ I thing this answer is exactly it. Just like a ruler, and @Choirbean's string answer: we measure from 0, but (usually) count from 1. In arrays we are giving the distance, a measure. $\endgroup$ Commented May 27, 2017 at 11:22
  • 8
    $\begingroup$ I really like the idea of thinking of the index not as a count per se but as a measurement from the origin. $\endgroup$
    – Peter
    Commented May 27, 2017 at 18:46
  • $\begingroup$ I think this is the right answer to the original question, but want to add for the OP something unrelated that I've found useful: the words that languages and libraries use can make this much easier or harder to grasp. Whenever I'm dealing with 0-based indexes, I mentally translate to skip and take, which makes them perfectly clear. If you can find a library that uses these terms as your first introduction to the concept, it might make it easier to learn. $\endgroup$ Commented Sep 24, 2020 at 22:09
  • $\begingroup$ "For the first year of life, children are 0 years old. " but we would say that they were in their first year of life $\endgroup$ Commented May 30, 2022 at 8:22
  • $\begingroup$ A valid point and true if the measuring criteria is years. When a child is in it first year of life I've often heard its age being referred to in terms of months. As an alternative to your example, and this is very much a custom of a group or a culture, many years ago I often heard migrants from eastern Europe refer to people, whether child or adult, as being in their such-and-such year of life, not so many year old. ... $\endgroup$
    – user11948
    Commented Jun 4, 2022 at 10:33
38
$\begingroup$

An analogy that will work well in Europe, but not in North America:

Lift Control Panel

Image licensed under the CC BY-SA 3.0 by Bidgee of Wikimedia Commons.

Floors (in European countries) are typically numbered with 0 (or G) as the ground floor, then 1 as the first floor above ground, etc. This could easily be compared to a list/array of floors, with floors[0] being ground, floors[1] being the first floor, and so on.

Note that this analogy won't work particularly well in North American countries, as their convention is to number the ground floor as 1. Nevertheless, the visual element of a building and lift numbered from zero could serve as an intriguing example to illustrate zero-based indexing.

$\endgroup$
3
  • 3
    $\begingroup$ The problem with this is, that, while they are numbered 0, 1, and so on, the floor with number one is also called the first floor (at least in Germany and other European countries I know of), while in an array the first element is not indexed with 1. $\endgroup$ Commented Jun 6, 2018 at 14:29
  • 2
    $\begingroup$ @RaimundKrämer well, that's a defect of the way we talk about arrays, probably stemming back to Fortran days. I avoid using erstes, zweites etc. to refer to array elements, and say instead Startelement and Nachfolgerelement. In English, I use list terminology: the head and the head of tail. (Naming more than the frontmost two, the last, or the middle elements is seldom necessary.) $\endgroup$ Commented Sep 3, 2018 at 10:56
  • 1
    $\begingroup$ <colorful curse redacted>, you beat me to it. An elevator was the first example I thought about. :-) $\endgroup$
    – codingCat
    Commented May 31, 2022 at 14:07
24
$\begingroup$

The clock (24 hours system)

If we look at the clock, we have two examples of counting hours. The 24 hour system starts at 0. The 12 hour system is interesting, neither starting at 0 or 1.

The 12-hour clock

In the 12-hour clock system we start at 12 and make our way up to 11.

This needs some explanation. The 12 hour clock has a funny way of counting, that you may not have noticed. It goes 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11. (look carefully at a clock that has AM and PM indicators. Without these, then it is just a regular circular (mod 12) counting system.) 12am, 1am, 2am, 3am, 4am, 5am, 6am, 7am, 8am, 9am, 10am, 11am 12pm, 1pm, 2pm, 3pm, 4pm, 5pm, 6pm, 7pm, 8pm, 9pm, 10pm, 11pm

The 24-hour clock:

In the 24-hour clock things are simpler. Numbers just go up, until we get to the end of the day (mod 24). However we start with zero, this may be to keep it backward compatible with the 12-hour system, but also makes the time of day, be the elapsed time since the start of the day (see other answers that stat that starting at zero is just how you measure things).

$00\colon{}00\colon{}00$$23\colon{}59\colon{}59.99\dot9$


Note I have finally found an advantage of daylight shifting time. In the summer noon is at 13:00, and midnight at 1-oclock. This makes the 12hour system start at 1: i.e 1, 2, 3 … 11, 12; (instead of 12, 1, 2, 3 … 11). However AM and PM are now wrong, as the meridian does not move.

$\endgroup$
5
  • 3
    $\begingroup$ I think the idea is that the first hour of the day in the 24-hour clock is 00:00. Hence, what would be 12:01 am is in fact 00:01. See militarytimechart.com $\endgroup$
    – Peter
    Commented May 27, 2017 at 18:55
  • 2
    $\begingroup$ So what does the phrase "The Eleventh Hour" mean, 10 am? Big deal. Still have more than 13 hours to go. $\endgroup$
    – user737
    Commented Jun 15, 2017 at 19:33
  • 1
    $\begingroup$ @nocomprende strangely the 11th hour meant from 11pm. So the 12th hour of the afternoon. $\endgroup$ Commented Jun 15, 2017 at 21:36
  • 2
    $\begingroup$ @nocomprende I just realised that the 11hour is like an octave. An octave is named because depending how you count there is ether 7 or 12 notes in an octave. The 2 biggest cases of error are, null references, not validating inputs, and out by one errors. $\endgroup$ Commented Aug 23, 2017 at 14:00
  • 1
    $\begingroup$ Also, a 'third' in music is the 3rd note in the scale, not three up from the first note. A fifth, seventh, etc - same thing. Octave is thus: 8 notes up, or the entire scale starting over again. The hours of the day used to be noted from sunrise, so there were only about 12 (near the equator). Hours at night were not noted, because no one could see the sundial. "Ship's Bells" start at noon / midnight with a single ring and add one at the half hour. They start over after 8 rings, thus 4, 8 and so on. $\endgroup$
    – user737
    Commented Aug 23, 2017 at 14:35
11
$\begingroup$

I don't see anything confusing in 0-based indexing. In fact, it seems that 0-based indexing is not less natural for humans than 1-based indexing. Humans use 1-based indexing just because of following some long-standing, but weird tradition.

I remember that when I was a pre-school child (<7 years old) and has not been yet influenced by social traditions of numbering (I didn't visit a kindergarten), I used a mixed numbering scheme. For example, when we had in our house a lot of guests sitting around a table, and I was crawling under the table, plotting some childish prank — and I needed to make an association between torsos (I see above the table when I'm out of under-the-table area) and pairs of legs (I see when I'm under the table); I don't remember what prank I was planning, but I strongly remember that to remember a position of a victim-guest, I used scheme like "three+one":
"three+one" numbering (picture based on "Break" by Llisole (cc))
I.e. neither referring this guest as third, nor referring him as fourth was not enough intuitive for me. Indeed: "three" is a number of guests before him — not his position; "four" is a number of guests including him — not his position; probably, if I knew fractional numbers at that time, I'd referred him as "3½-th", but I didn't.
I remembered this episode well, because when I was running to another room to take equipment needed for prank, muttering "three plus one" to myself aloud (not to forget it), the same age girl who was one of guests shouted "four" — which annoyed me very much ("f@#k, I know how to add much larger numbers, but '3+1' is a position specification rather than just sum").

0-based stuff is preferrable everywhere, where gauges are used. You start time from zero (you say "0 hours" at midnight, not "1 hour"; "0 minutes" when a new hour starts, not "1 minute"; "0 seconds" when a new minute starts, not "1 second"), temperature from zero, distance from zero, etc. What really confuses is actual discrepancy between 0-based and 1-based, not the 0-based itself; for example, I needed some time at school to realize why people usually call it "<N+1>-th second" ("minute", "hour", etc) when it's still "0:00:<N>" on stopwatch:
Time scale: time range from 0:00:<N> to 0:00:<N+1> is usually called as <N+1>-th second
IMHO: Nothing would break if some day people will finally switch to 0-based indexing; even vice versa, it would become much more intuitive and comfortable — a stopwatch shows "0:00:<N>", so let's call it "<N>-th second" (not "<N+1>-th"); but some-why people had chosen this weird way of 1-based indexing long ago.

TL;DR: In 0-based indexing we count items before (up to, but excluding) current; in 1-based indexing we count items through (up to and including) current. Neither way is in fact intuitive (for a child that has free choice). Both ways need to be learned.

$\endgroup$
1
  • 3
    $\begingroup$ When I was a child, I thought that adding past 10 required adding two: one to change the 9 to a zero and one more to put the one in front. It took a while for a tutor to figure out why all my sums were off by one. $\endgroup$
    – user737
    Commented Jun 15, 2017 at 19:39
9
$\begingroup$

Exponents representing the values of the digits in positional number systems.

e.g. the-arabic-system / denary / the-system-you-learnt-in-primary-school.

10³  10² 10¹ 10⁰
1000 100 10  1

or binary

2³ 2² 2¹ 2⁰
8  4  2  1

The binary example in binary

10¹¹ 10¹⁰ 10¹ 10⁰
1000 100  10  1

This was @GypsySpellweaver idea, see comment.

$\endgroup$
2
  • 1
    $\begingroup$ Same for polynomials: p(x) = a₀ x⁰ + a₁ x¹ + a₂ x² + … + aₙ xⁿ. $\endgroup$
    – Sasha
    Commented May 6, 2018 at 6:30
  • $\begingroup$ I think this is my favorite example, and moreso because it's likely to come up in an intro computing course before any other use-cases (arrays, etc.). It connects to basic knowledge students should already possess, so I've come to highlight it and foreshadow that we'll be using that a lot in later topics. $\endgroup$ Commented Sep 30, 2022 at 16:06
9
$\begingroup$

Rulers start at zero:

enter image description here

At zero centimetres, you have nothing, whereas at one centimetres, you have one unit of length. Memory is similar: You start filling at the beginning (zero), hence, the first x-memory units contain x units of data, the next unit contains unit x+1.

$\endgroup$
4
  • 2
    $\begingroup$ I think comparing an array to a ruler is probably the nicest, most visual thing at hand. If you have a ruler with both inches and centimeters you also have a metaphor for different memory sizes for variable types. $\endgroup$
    – ObscureOwl
    Commented Mar 6, 2020 at 17:55
  • $\begingroup$ Since this question was posted, I have come to realise that a ruler is not a metaphor for this think. It is the think. Zero indexing is simply measuring the distance from the start. There are many examples of this in the other answers. $\endgroup$ Commented May 29, 2022 at 18:05
  • $\begingroup$ A great visual example $\endgroup$
    – codingCat
    Commented May 31, 2022 at 14:14
  • 1
    $\begingroup$ I don't think the ruler is a good metaphor at all. The ruler begins with the first centimetre, not the zeroth. And the first centimetre - that is, centimetre 1 - starts at zero and ends at one. There is unfortunately no way to reconcile these concepts. The ordinal number words (and equivalents in other languages) predate the invention of the number zero by millennia. $\endgroup$
    – Steve
    Commented Jul 25, 2022 at 18:13
4
$\begingroup$

Think about human ages. Babies that are newly born are at age 0. That's zero-based indexing.

$\endgroup$
1
  • $\begingroup$ This is also true for anything that is measured. In the end I realised that zero indexing is not counting; it is measuring. $\endgroup$ Commented Oct 1, 2022 at 13:52
3
$\begingroup$

UK school years

We used to have years 1,2, 1,2,3,4, 1,2,3,4,5,6th form.

We then changed to 1,2,3,4,5,6,7,8,9,10,11,12,13 (years 12 and 13 are 6th form, no one know where this name comes from).

Then we added reception year, to get R,1,2,3,4,5,6,7,8,9,10,11,12,13.
R is just a different symbol for 0. (In the US K is used for 0.)

$\endgroup$
4
  • 1
    $\begingroup$ In the U.S. there would be 'K' and 13 would mean college, 'K' has been around for quite a while -- everything else is the same! $\endgroup$ Commented Sep 14, 2018 at 19:55
  • 1
    $\begingroup$ @JosephDoggie In UK years 12 and 13, can be college, but some(may be most) schools, have a 6th form. This Does the same as the early college years, but at a school. After these 2 years, a lot of pupils go on to university (or work, or more college). $\endgroup$ Commented Sep 15, 2018 at 10:01
  • $\begingroup$ In the US, there's also sometimes Pre-K, which I guess would be -1. $\endgroup$ Commented Jan 12, 2019 at 0:26
  • $\begingroup$ @SolomonUcko same in UK, (I love -1 indexed arrays) $\endgroup$ Commented Jan 12, 2019 at 9:22
3
$\begingroup$

Distances in boardgames with discrete spaces. For example: Chess, wargames, Dungeons & Dragons played on a battlemap, etc. Counting movement, the space you start in counts as space zero (or more accurately: if a piece stays in the same space, then it has moved zero distance).

There are a number of situations in wargames and RPGs where two pieces might share the same space; and if one shoots at the other, then the distance between them is considered to be zero. Many D&D magic spells have a range listed as zero to reflect this (thinking past editions here; current edition explicitly says "Self" or "Touch" in these cases).

$\endgroup$
2
$\begingroup$

A common example I use is centuries/years. We start with the first century on a range of 0-100 years. Or the first year of a century, which always ends in 00. It describes the amount of x that has passed, not the n-th x.

The word "first" is the confusing thing for beginners I feel.

$\endgroup$
7
  • 3
    $\begingroup$ There was no your zero, therefore the end of a century ends in 00. 2000 was the last year of the 20th century. Most people get this wrong, the rest of us let it pass for a year, then have a 2nd party. $\endgroup$ Commented Jun 15, 2017 at 21:42
  • 4
    $\begingroup$ I sometimes say "oneth" to avoid the ambiguity of "first". $\endgroup$ Commented Jul 27, 2017 at 23:00
  • 4
    $\begingroup$ @ctrl-alt-delor actually, it’s the perfect example of what a mess is created when not using index zero. ”Most people get this wrong” by intuitively assuming that a century should start with year zero and end with year 99 and are “wrong”, because there was no year zero. But we still live in the 21st century whose index (year number) starts with a 20 (except for the last one) and the third millennium whose index (year number) starts with a two (except for the last one). And if that one guy was truly born 24.12.1, your 2nd party was wrong as well (otherwise, that number is totally meaningless). $\endgroup$
    – Holger
    Commented Sep 6, 2018 at 11:55
  • 2
    $\begingroup$ @ctrl-alt-delor: You are correct. However, this 0-based system is actually used to express the age of a person, and people are not known to struggle with that. The difference is that when you're at "age 0", we omit the year count altogether: "He is 3 months old", not "He is 0 years and 3 months old". When you 0-index, and you're at index 0, that often entails deferring to a more precise (non-0) measurement. $\endgroup$
    – Flater
    Commented Sep 18, 2018 at 6:33
  • 1
    $\begingroup$ @Flater yes you bring up an interesting point. In Europe and US, we measure age, so 3 years old, means that you are between 3 and 4 years old, that is have been alive 3 years, but no more than 4 (Well maybe an extra ¾ day, see leap year). In some parts of the world, they say what year you are in. Therefore a new born is 1, (in 1st year). This is similar to school year, before we added year zero (K in US, R in UK). In any respect the systems are all self consistent. but can result in an out by one error if the 2 people communicating are using a different system. $\endgroup$ Commented Sep 18, 2018 at 7:11
2
$\begingroup$

The ground floor is the de facto 0th floor.

Humans are born at age 0.

Military time starts at 0:00. Despite the day having 24 hours, it is not correct to write 24:00.

As a side-note, Japanese TV uses 0-indexed 12-hour notation. That means 11 AM is followed by 0 PM, not 12 PM.

$\endgroup$
3
  • $\begingroup$ Counting 12,1,2,3,4,5,6,7,8,9,10,11 is what is strange. Measuring from 0 is, (what is a good word for this, oh yes) measuring. $\endgroup$ Commented Jul 1, 2020 at 21:35
  • $\begingroup$ Nice note about Japanese TV. However the rest is already covered in other answer. If you were to write about just Japaneses TV, then I would upvote. $\endgroup$ Commented Aug 30, 2020 at 14:20
  • 1
    $\begingroup$ In Japan, they also use the implied modulo system, where it's common to indicate hours with numbers 24 or greater. For example, a bar might be open from 20 till 26. It makes it clear that the closing time is past midnight. I love that system! $\endgroup$ Commented Aug 31, 2020 at 17:10
2
$\begingroup$

For anyone old enough (>30years):

In the UK a few years back we had only a few TV channels, first 1, then 2, they slowly increased to 5: BBC1, BBC2, ITV, channel 4, and eventually channel 5 The TVs typically had 10 numbered slots (sometimes 8). We would but the channels into the slots 1 = BBC1, 2 = BBC2, 3 = ITV, 4 = channel-4, 5 = channel-5. So where to put the video recorder ( a device to record TV shows for later viewing). If we use slot 6 and the TV companies finally add a 6th channel, then we will have to move it, so if the TV has a slot zero, then we put it in there.


Eventually we suddenly got a load more, with digital TV (Freeview). This story ignores, payed for channels (satellite and cable).

$\endgroup$
6
  • 2
    $\begingroup$ The US had a channel 1 at some point but it was repurposed very early on. TV channels started at 2. Zero was right out. $\endgroup$
    – user737
    Commented Jun 15, 2017 at 19:40
  • $\begingroup$ This numbering system was far from universal on UK TVs. A Hitachi model we had in the early 90s had 12 presets, but they were numbered up from 1 to 12. Some models I encountered later c.2000 would treat channel 0 as the AV/SCART input, but only a subset did this. $\endgroup$
    – Kaz
    Commented May 29, 2022 at 14:07
  • $\begingroup$ @Kaz. True, I have updated the answer. $\endgroup$ Commented May 29, 2022 at 17:44
  • $\begingroup$ I quickly read all the answers and it seems that no one mentioned 21th century starts from 2000, another typical example of 0 based index $\endgroup$ Commented Jun 5 at 7:21
  • $\begingroup$ @Qiulang 邱朗 Your comment is attached to an answer, not to the question. $\endgroup$ Commented Jul 1 at 17:44
1
$\begingroup$

An example from thermodynamics: the study of heat and temperature.

In thermodynamics there are 4 laws, numbered from zero. Look to see when your pupils study this in physics (science). You now have cross curricular linking, which is also good.

Like Asimov's 0th law of robotics, the zeroth low of thermodynamics was added after the other 3: “The zeroth law was not initially recognized as a law, as its basis in thermodynamical equilibrium was implied in the other laws. The first, second, and third laws had been explicitly stated prior and found common acceptance in the physics community. Once the importance of the zeroth law for the definition of temperature was realized, it was impracticable to renumber the other laws, hence it was numbered the zeroth law.” — https://en.wikipedia.org/wiki/Thermodynamics#Laws_of_thermodynamics

  • Zeroth law of thermodynamics: If two systems are in thermal equilibrium with a third system, they are in thermal equilibrium with each other. This law helps define the notion of temperature.

  • First law of thermodynamics: When energy passes, as work, as heat, or with matter, into or out from a system, the system's internal energy changes in accord with the law of conservation of energy. Equivalently, perpetual motion machines of the first kind are impossible.

  • Second law of thermodynamics: In a natural thermodynamic process, the sum of the entropies of the interacting thermodynamic systems increases. Equivalently, perpetual motion machines of the second kind are impossible.

  • Third law of thermodynamics: The entropy of a system approaches a constant value as the temperature approaches absolute zero. With the exception of non-crystalline solids (glasses) the entropy of a system at absolute zero is typically close to zero, and is equal to the logarithm of the product of the quantum ground states.

Extract from https://en.wikipedia.org/wiki/Laws_of_thermodynamics Text is available under the Creative Commons Attribution-ShareAlike License

$\endgroup$
2
  • 2
    $\begingroup$ Similarly, Asimov's Laws start from zero (although chronologically, the zeroth law was added later). $\endgroup$
    – Aurora0001
    Commented May 27, 2017 at 10:18
  • 1
    $\begingroup$ @Aurora0001 I added in a bit on asimov. (also I think you should make an answer on asimov) $\endgroup$ Commented Jun 4, 2017 at 7:50
1
$\begingroup$

This one in related to computing, but sufficiently different, as it related to the social side. You can link it in by teaching the social side before indexing.

  • The freedom to run the program as you wish, for any purpose (freedom 0).
  • The freedom to study how the program works, and change it so it does your computing as you wish (freedom 1). Access to the source code is a precondition for this.
  • The freedom to redistribute copies so you can help your neighbour (freedom 2).
  • The freedom to distribute copies of your modified versions to others (freedom 3). By doing this you can give the whole community a chance to benefit from your changes. Access to the source code is a precondition for this.

Extract from https://www.gnu.org/philosophy/free-sw.en.html (Creative Commons Attribution-NoDerivatives 4.0 International License).

$\endgroup$
4
  • 1
    $\begingroup$ You are missing 5 freedoms. And the fact that a bunch of computing folks used an 0 indexed array as is kinda... expected. OP is looking for non-computing examples, like military time and people's age (as mentioned in other answers/comments) $\endgroup$
    – ivanivan
    Commented Jan 23, 2018 at 14:26
  • 1
    $\begingroup$ @ivanivan can you tell us about the 5 freedoms, I know not of this. And added answer on 24hour time. $\endgroup$ Commented Jan 23, 2018 at 17:01
  • 1
    $\begingroup$ the freedoms you list are from the Free Software Foundation - Stallman and co. However, the Open Source Definition lists other requirements/freedoms needed for a license to be considered Open - opensource.org/osd-annotated. Remember, Stallman insists that all software be free, the Open Source Initiative wants as much as possible to be free, but not at the expense of extremism $\endgroup$
    – ivanivan
    Commented Jan 23, 2018 at 19:57
  • $\begingroup$ @ivanivan the Free Software foundation also have a longer version: these 3 points are only a summary. The freedoms in the rest of the Free Software definition, and the Open Source definition do not add any extra freedoms. They only add clarification. The Free Software definition has 3 levels: the name "Free Software" (where free refers to freedom not price), the 4 freedoms, and the detailed explanation. The Open Source definition only has a detailed explanation, so is harder to grok. $\endgroup$ Commented Aug 30, 2020 at 14:15
1
$\begingroup$

Light gang switches, same the way you teach binary counting. (Well, the same way that I was taught binary arithmetic back when knowing binary and hex were important.)

EDIT: An off transistor (simulated by a light switch) is considered to be 0 (no voltage) and an on to be 1 (voltage passing). Since "all zeros" is a valid configuration, 0 is a valid address where Important Bits can reside. That's why many languages base arrays using 0.

EDIT 2: It's also the basis of pointer arithmetic. Your array has a base address at location A, so that's where the first element goes. When you're referencing the elements in a loop, you add an offset O to get to each array element. To access the first element, the value of O must be 0.

enter image description here

$\endgroup$
7
  • 1
    $\begingroup$ @Buffy sorry. I assumed that CS Educators all know the light-switch analogy. $\endgroup$
    – RonJohn
    Commented Jan 15, 2018 at 14:33
  • 1
    $\begingroup$ @Buffy ok. I added (a hopefully clear) explanation. $\endgroup$
    – RonJohn
    Commented Jan 15, 2018 at 14:38
  • 2
    $\begingroup$ @Buffy interesting. This was Standard Knowledge 35 years ago when students had to learn pointer arithmetic and take at least one class in Assembly. $\endgroup$
    – RonJohn
    Commented Jan 15, 2018 at 14:49
  • 1
    $\begingroup$ Welcome to CSEducators. Come back often. $\endgroup$
    – Buffy
    Commented Jan 15, 2018 at 14:52
  • 1
    $\begingroup$ Using 0 and 1 for binary states is unrelated to the mathematical values of 0 and 1. We could instead use "nothing" and "something" and the entire field of logic would remain correct. This is why programming now favors true and false, instead of "a non-zero integer" and "a zero integer". It disambiguates logical evaluations from mathematical ones and prevents developers mistakenly assuming one for the other. $\endgroup$
    – Flater
    Commented Sep 18, 2018 at 6:37
1
$\begingroup$

Subtraction paradox: In North-American football, if a runner goes from the 3 yard line to the 4 yard-line, there is a (4-3) = 1 yard gain. However, if your math teacher assigns problems 3-4 (integers), you have to do two problems. So in what engineers call an "analog" system, the Result = Stop - Start; but for integers it can be more complex.

So in North American football, the yard line starts at "0" which is called the "Goal Line" typically.

$\endgroup$
6
  • 1
    $\begingroup$ if a runner goes from the 3 yard line to the 4 yard-line, there is a (4-3) = 1 yard gain. However, if your math teacher assigns problems 3-4 (integers) The core difference here is that the former denotes the distance between points, and the latter denotes the points themselves. 2017 and 2018 are two distinct years (points), but the timespan (distance) between NYE 2017 and NYE 2018 is one year. This does not actually answer why 0-based indexing is used, as you're simply comparing two inherently different things. ("from 3 to 4" vs "3 and 4") $\endgroup$
    – Flater
    Commented Sep 18, 2018 at 6:27
  • $\begingroup$ One must use 0 as a base, however. $\endgroup$ Commented Sep 18, 2018 at 12:15
  • 1
    $\begingroup$ One must use 0 as a base. I don't quite agree, 0-indexing is not universally superior to 1-indexing. As I mentioned in my earlier comment, it depends on what you're actually expressing (points, the distance between them, ...). There are many cases where the 0th element is a literal "nothing", thus precluding 0 from being relevant (especially when pertaining to physical objects). $\endgroup$
    – Flater
    Commented Sep 18, 2018 at 13:34
  • 1
    $\begingroup$ I think this is what is called a fence-post error: You have questions 3,and 4. These are the posts. It is an error in this case to count the fence panels ($4-3$). You are not measuring the distance between the posts (number of panels), you are counting the posts. See also inclusive and exclusive ranges. Some languages use inclusive lower and exclusive upper, as this choice has less problems than other choices. $\endgroup$ Commented Aug 30, 2020 at 14:23
  • $\begingroup$ Note that in North American football, the "Goal Line" is the same as a zero-yard line, which is zero-based. For the math problems, you aren't doing problem 2, but if you subtract 4-2 = 2 you get the right answer. Thinking about 'how' this works is difficult, at least for me, and I have a Ph.D. in Electrical Engineering, focusing on computer simulations using eigen-spaces. $\endgroup$ Commented Aug 31, 2020 at 16:45
1
$\begingroup$

Some train stations (but not many) have a platform 0:

https://www.youtube.com/watch?v=SPQRNmXVP8s

If you are lucky enough to live in one of these towns, then it may be a very good example.

$\endgroup$
1
$\begingroup$

I realize this post is old. However, what helped me and what may help others is that 0 is indeed on the number line. The best analogy I can give to support this cause is related to a bank account.

If you are -\$5 in your account and you add \$10. Your total sum is \$5. Placing this on the number line (as seen below) -5 becomes your "0" as you count up by 10. If you start -5 as 1, your short \$1. If you skip 0 in your addition of 10, you gain \$1.

-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5

Simplifying things to its core has been my most successful tool in life.

GL,

$\endgroup$
1
$\begingroup$

Since this question was posted, I have come to realise that a ruler is not a metaphor for this think. It is the think. Zero indexing is simply measuring the distance from the start. There are many examples of this in the other answers.

We need to not see the index as on ordinal number, but as the distance from the start.

$\endgroup$
1
  • $\begingroup$ I'm surprised that it never occurred to me to use a rule for this exact reason. When I explain the concept in class, I say the address of the array is the location of the first position, and the index is the distance from that position. $\endgroup$
    – codingCat
    Commented May 31, 2022 at 14:19
0
$\begingroup$

where can we find 0-indexing outside of CS and grounded in everyday human experience?

This is really begging the question (in the strict sense): you assume that there's any need for it, whereas I boldly claim that there's none whatsoever, making the question moot. In fact, I think it's really counterproductive, and is an attempt to solve a non-existent problem.

As far as educational theories go, such a question is very loaded. Are you sure that such everyday human experience will have any other applicability to the problem? It's like trying to teach quantum mechanics while referring to everyday human experience: it's totally futile, since there's no everyday human experience that has any resemblance to what happens on quantum level, and if there is then the resemblance is wholly superficial.

See, the heart of the problem is whether there is any way to continue deduction based on human experience. If you refer to human experience, the students will naturally try to rely on what they know from "real life" as they go on in their studies, and they'll try to rely on that first, before reaching into the "unfamiliar" but task-specific knowledge. In most cases, the real-life "analogues" are baggage, since any further deductions one makes based on them tend to be either outright invalid, or subtly broken.

I personally don't think that there's much to 0-indexing. Tell the students that it's a convention no different from starting to count at 1. It's something we agreed to, and when you use some programming languages, the convention is 0-based. That's all there's to it. You can explain to the students that it's no different to agreeing to greet the teacher by saying "hello" or "good [morning|afternoon]" rather than "yo brother, what's up?". It's entirely arbitrary, it's based on a-priori decision to treat the "yo brother" form of address as informal or disrespectful or what have you.

$\endgroup$
1
  • $\begingroup$ While I agree in general. It turns out that there are many good examples. And that it is not counting, it is measuring (see other answers). I think I will use your last paragraph as advice for a lot of thinks. I have sometimes just shown students that what they think is normal is not the only way (e.g. base 12/24/60 clocks, so why not binary). $\endgroup$ Commented Sep 1, 2020 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.