3

Imagine the following pseudocode

objects[i], 1 <= i <= n 

objects[0] = 0

for i from 1 to n
  if(objects[i] - objects[i-1] > constant)
    do something

I'd like to know if there's a specific name for the assignment objects[0] = 0. I know that when values like these are used to stop loops, they are called sentinel values. In this case, however, I'm using it so that the first object evaluated (objects[1]) will have something to compare against - obviously, objects[0] is not a real object, just sort of a flag. Is it still called a sentinel value? Is there another name for this? Or should I not be doing this at all?

Let me know if I haven't made myself clear and I should try to explain my question in another way.

dcastro
  • 66,540
  • 21
  • 145
  • 155

2 Answers2

2

Cormen et al. writes in Introduction to Algorithms (3rd ed.) on page 238:

A sentinel is a dummy object that allows us to simplify boundary conditions.

This definition is broad enough to account for your usage (e.g. sentinel values of infinity are used in CLRS to simplify the merge routine of mergesort).

Nabb
  • 3,434
  • 3
  • 22
  • 32
1

I've always called it a "sentinel" whether at the beginning or the end, and haven't yet been fired for that.

DarenW
  • 16,549
  • 7
  • 63
  • 102
  • 1
    But this does not match the definition of a sentinel value at all: "a special value whose presence guarantees termination of a loop" (from: http://en.wikipedia.org/wiki/Sentinel_value) – dcastro Dec 12 '12 at 01:47
  • 2
    @dcastro: Cormen et al. writes "A sentinel is a dummy object that allows us to simplify boundary conditions." – Nabb Dec 12 '12 at 04:31
  • @Nabb: Ah, that settles it then. All the other definitions I've found do not account for these cases. This is actually for my masters thesis and that citation is very helpful. Would you put it as an answer so I could accept it? – dcastro Dec 12 '12 at 08:44