-
Notifications
You must be signed in to change notification settings - Fork 529
Open
Description
Hello.
Looks like there is a bug in the select function
cpbook-code/ch2/ourown/fenwicktree_ds.py
Line 36 in fa53432
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
Metadata
Metadata
Assignees
Labels
No labels