Descriptive Question

Input are a sequence S of n distinct keys, not necessarily in sorted order, and two integers m1 and m2(1 ≤ m1, m2 ≤n) . For any x in S, we define the rank of x in S to be
|{k∈S :k ≤x}|. Write an algorithm that will output all the keys of S whose ranks fall in the interval [m1, m2]

So what does the |{k∈S :k ≤x}| mean?

I don’t know that if | | has some meaning. But inside that it represents all values that are less than or equal to x and belongs to S

1 Like

that’s it? then the question is extremely easy. I thought the || defines the length

May be then total no of values in that set if | | represents size or length

Yes, |X| means "size of the set X", if X is a set of elements.


cool, so sorting the sequence will be a good choice right, then rank can be calculate easily the size will be the index+1

can you please send the algo?