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

FTree.select throws IndexError: list index out of range #90

Open
arsamigullin opened this issue Jun 27, 2021 · 1 comment · May be fixed by #86
Open

FTree.select throws IndexError: list index out of range #90

arsamigullin opened this issue Jun 27, 2021 · 1 comment · May be fixed by #86

Comments

@arsamigullin
Copy link

Hello.
Looks like there is a bug in the select function

if k > self.ft[i + p]:

Steps to reproduce:

ft = FTree([1,2,3,4,5])
ft.select(15) # this throws IndexError: list index out of range in line 36

Expected behavior:
According to CP4 book, the select function "finds the smallest index/key i so that the cumulative frequency in the range [1..i]>=k". So the function should return 6 because the smallest index (of FTree.ft array) where the cumulative frequency is at least 15 is 6

@rchavesf rchavesf linked a pull request Jul 31, 2021 that will close this issue
@rchavesf
Copy link

@arsamigullin The answer for your example should be 5. However, the issue exists and it can be solved by #86.

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

Successfully merging a pull request may close this issue.

2 participants