Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
KnightChaser opened this issue Jan 4, 2025 · 0 comments
Open

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

KnightChaser opened this issue Jan 4, 2025 · 0 comments

Comments

@KnightChaser
Copy link

KnightChaser commented Jan 4, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant