Python icon indicating copy to clipboard operation
Python copied to clipboard

Incorrect output for Binary Search when list contains duplicates

Open anumolusneha opened this issue 1 month ago • 2 comments

Repository commit

3929955ab0649cddff28864bfa5ed8f506b48847

Python version (python --version)

Python 3.12.3

Dependencies version (pip freeze)

attrs==23.2.0 Babel==2.10.3 bcc==0.29.1 blinker==1.7.0 Brlapi==0.8.5 certifi==2023.11.17 cfgv==3.4.0 chardet==5.2.0 click==8.1.6 cloud-init==25.1.4 colorama==0.4.6 command-not-found==0.3 configobj==5.0.8 cryptography==41.0.7 cupshelpers==1.0 dbus-python==1.3.2 defer==1.0.6 distlib==0.4.0 distro==1.9.0 distro-info==1.7+build1 filelock==3.20.0 httplib2==0.20.4 identify==2.6.15 idna==3.6 iniconfig==2.3.0 Jinja2==3.1.2 jsonpatch==1.32 jsonpointer==2.0 jsonschema==4.10.3 language-selector==0.1 launchpadlib==1.11.0 lazr.restfulclient==0.14.6 lazr.uri==1.0.6 louis==3.29.0 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 netaddr==0.8.0 netifaces==0.11.0 nodeenv==1.9.1 oauthlib==3.2.2 olefile==0.46 packaging==25.0 pexpect==4.9.0 pillow==10.2.0 pip==24.0 platformdirs==4.5.0 pluggy==1.6.0 pre_commit==4.3.0 ptyprocess==0.7.0 pycairo==1.25.1 pycups==2.0.1 Pygments==2.17.2 PyGObject==3.48.2 PyJWT==2.7.0 pyparsing==3.1.1 pyrsistent==0.20.0 pyserial==3.5 pytest==8.4.2 python-apt==2.7.7+ubuntu4 python-dateutil==2.8.2 python-debian==0.1.49+ubuntu2 pytz==2024.1 pyxdg==0.28 PyYAML==6.0.1 requests==2.31.0 rich==13.7.1 ruff==0.14.3 setuptools==68.1.2 six==1.16.0 ssh-import-id==5.11 systemd-python==235 typing_extensions==4.10.0 ubuntu-drivers-common==0.0.0 ubuntu-pro-client==8001 ufw==0.36.2 unattended-upgrades==0.1 urllib3==2.0.7 virtualenv==20.35.4 wadllib==1.3.6 wheel==0.42.0 xdg==5 xkit==0.0.0

Expected behavior

Binary search should return the index of the first matching element when duplicates exist.

Actual behavior

The algorithm returns the last index of the matching element instead of the first.

anumolusneha avatar Nov 02 '25 02:11 anumolusneha

I'll like to work on this issue , please assign it to me

Aditya-Singh27 avatar Nov 07 '25 08:11 Aditya-Singh27

hi, can you please assign this issue to me.

poorva-gupta avatar Nov 30 '25 15:11 poorva-gupta