Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of "exclusive" and "inclusive" when describing number ranges?

Simple question but, I see exclusive and inclusive when referring to number ranges.

For example, this is a line from an algorithms book:

The following function prints the powers of 2 from 1 through n (inclusive).

What is meant by this? What makes a number range inclusive or exclusive?

like image 620
Joel De La Cruz Avatar asked Aug 18 '16 04:08

Joel De La Cruz


People also ask

What does inclusive mean in a range of numbers?

We could do this pretty easily: my_list = range(51) … the word “inclusive” means that the value 50 should be included in the range. So, the ending value of the range is set to 51 (exclusive) in the Python statement, meaning that 51 is not included in the range. Submitted by Glenn Richard. almost 8 years.

What does exclusive range mean?

There really are two kinds of ranges. One is the exclusive range, which is the highest score minus the lowest score (or h − l) and the one we just defined. The second kind of range is the inclusive range, which is the highest score minus the lowest score plus 1 (or h − l + 1).

What does inclusive mean in domain and range?

The largest number in the interval is written second, following a comma. Parentheses, ( or ), are used to signify that an endpoint value is not included, called exclusive. Brackets, [ or ], are used to indicate that an endpoint value is included, called inclusive.


2 Answers

In Computer Science, inclusive/exclusive doesn't apply to algorithms, but to a number range (more specifically, to the endpoint of the range):

1 through 10 (inclusive) 1 2 3 4 5 6 7 8 9 10  1 through 10 (exclusive) 1 2 3 4 5 6 7 8 9 

In mathematics, the 2 ranges above would be:

[1, 10] [1, 10) 

You can remember it easily:

  • Inclusive - Including the last number
  • Exclusive - Excluding the last number
like image 198
Rakete1111 Avatar answered Oct 05 '22 19:10

Rakete1111


The following function prints the powers of 2 from 1 through n (inclusive).

This means that the function will compute 2^i where i = 1, 2, ..., n, in other words, i can have values from 1 up to and including the value n. i.e n is Included in Inclusive

If, on the other hand, your book had said:

The following function prints the powers of 2 from 1 through n (exclusive).

This would mean that i = 1, 2, ..., n-1, i.e. i can take values up to n-1, but not including, n, which means i = n-1 is the highest value it could have.i.e n is excluded in exclusive.

like image 35
Tim Biegeleisen Avatar answered Oct 05 '22 19:10

Tim Biegeleisen