CLRS icon indicating copy to clipboard operation
CLRS copied to clipboard

Solution of the problem 5-2.(a) seems to be incorrect

Open KnightChaser opened this issue 11 months ago • 2 comments

Problem location: https://walkccc.me/CLRS/Chap05/Problems/5-2/ (Chapter 5, 5-2.a)

The answer in the given solution is like below.

RANDOM-SEARCH(x, A, n)
    v = Ø
    while |Ø| != n
        i = RANDOM(1, n)
        if A[i] = x
            return i
        else
            v = v ∩ i
    return NIL

However, v ∩ i would imply taking the intersection between v and i, which doesn't make sense since i is not a set, it's just a number taken from RANDOM(1, n). I expect it should be corrected to v = v ∪ {i} or v.add(i) to add i to the set v.

KnightChaser avatar Jan 04 '25 07:01 KnightChaser

I agree there are problems. The while loop as written will skip entirely unless n = 0, so while |v| and union is probably meant. Do you want to open a PR?

jxu avatar Apr 03 '25 22:04 jxu

Yes, If I can, I want to open a pull request to correct this problem and contribute to this repository.

KnightChaser avatar Apr 03 '25 23:04 KnightChaser