SentinelValue.md (679B)
1 # Sentinel Value 2 3 CS202 (personal learning) 4 5 **Definition:** A sentinel value is a constant value used to end an execution loop. 6 7 This is also referred to as a flag value, trip value, rogue value, signal value, or dummy data. 8 9 This is how you describe -1 in the context of a bfs algorithm where -1 denotes a visited location. When doing this, we know -1 is an in-band piece of data (valid based on type), but distinct from legal data values (ie. positives if we are using a non-negative weighted graph as an example). 10 11 Another example where we use -1 as a sentinel value is as follows: 12 13 ```python3 14 15 def find(arr, val): 16 for i in arr: 17 if i == val: 18 return i 19 return -1 20 ```