I have a table of integers, say A, and consider the counting function C, which, for a given x, gives the number of elements in A which are less or equal to x. Next, I want to plot C(x) in some range, say for x less then or equal to N. The question is: How this can be done quickly?
A very naive approach is illustrated by the following example.
max = 10^3;
n = 10^3;
A = RandomInteger[{1, max}, n];
c[k_]:=c[k]=Length[Intersection[A,Range[k]];
and c[k] gives the number of integers in A
which are less then or equal to k
. One can also use
cc[k_]:=cc[k]=Count[A, u_ /; u < k + 1];
However, if the set A
has, say n = 10^5
elements, then to compute all values of c[k]
is time consuming. I am pretty sure that there should be a quick and efficient method to compute all values of c[k]
in a given range, but I failed to find one.