SSQ / Coursera-Stanford-Divide-and-Conquer-Sorting-and-Searching-and-Randomized-Algorithms

Notebook for quick search
MIT License
98 stars 83 forks source link

floating point issue. #5

Open 3mrotaha opened 2 years ago

3mrotaha commented 2 years ago

I am not sure if it happened to anyone else but the code didn't go as expected on my IDE, the third test case by which I mean (the middle pivot) has a wrong answer for the number of comparisons. the issue simply is that the function that maps the flag into an index is giving me a floating index which causes a run time error, so I had to convert the answer to an integer value. (denoted by yellow)

the second issue is that the condition in the function that returns the pivot (ChoosePivot) value needs to convert the division result (n/2) to an integer so that the condition goes the right way. (denoted by red)

image

after I edited it, I got the correct answer. BTW, I am not a python coder but I am happy to help. Screenshot 2022-11-09 123704