S
S
Sergey2017-01-18 16:37:27
Mathematics
Sergey, 2017-01-18 16:37:27

How to quickly determine that the set contains all natural numbers from N to M?

There is a set of natural numbers from N to M.
M and N can change in time.
How can you quickly determine whether a given set contains all natural numbers from N to M without resorting to a complete enumeration of all elements (more precisely, a complete enumeration at the beginning can be done, but then when adding / removing elements, this is not necessary).
Those. for example, initially in the set there is:
1,3 - the criterion should say that this is not a complete set.
then we added 4
1,3,4 - again not complete.
added 2
1,2,3,4 -- complete.
Here the criterion is to say that we have in the set all natural numbers from 1 to 4 inclusive.
PS Comparison of the sum of elements with the sum of an arithmetic progression between N(min element) and M(max element) comes to mind. But how reliable is this?
PSS Set can only have unique elements

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
evgeniy_lm, 2017-01-18
@begemot_sun

M-N+1= the number of members of the set , of
course, provided that there are no identical members in the set.
Otherwise, only sorting and searching for the first missing member individually

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question