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

Mi6: write a python program to for binary search (✓ Sandbox Passed) #23

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

psurabh
Copy link
Owner

@psurabh psurabh commented Feb 27, 2024

Description

This pull request adds a Python program that implements a binary search algorithm. The program takes a sorted list and a key as input and returns the index of the key in the list. If the list is not sorted or the key is not in the list, it returns -1.

Summary

  • Added a new file binary_search.py which contains the implementation of the binary search algorithm.
  • The function binary_search(lst, key) performs the binary search. It takes a list and a key as input and returns the index of the key in the list.
  • The function returns -1 if the list is not sorted or the key is not in the list.
  • Included test cases in the __main__ section to verify the functionality of the binary search algorithm.

Fixes #22.


🎉 Latest improvements to Mi6: #

💡 To get Mi6 to edit this pull request, you can:

  • Comment below, and MI6 can edit the entire PR
  • Comment on a file, Mi6 will only modify the commented file
  • Edit the original issue to get Mi6 to recreate the PR from scratch

@psurabh
Copy link
Owner Author

psurabh commented Feb 27, 2024

Rollback Files For Mi6

  • Rollback changes to binary_search.py

This is an automated message generated by Mi6

@psurabh
Copy link
Owner Author

psurabh commented Feb 27, 2024

Apply to your PR?

  • Apply: All new business logic should have corresponding unit tests.
  • Apply: Refactor large functions to be more modular.
  • Apply: Add docstrings to all functions and file headers.

This is an automated message generated by Mi6

@psurabh psurabh added the mi6 Mi6 Copilot. label Feb 27, 2024
@psurabh
Copy link
Owner Author

psurabh commented Feb 27, 2024

Apply to your PR?

  • Apply: All new business logic should have corresponding unit tests.
  • Apply: Refactor large functions to be more modular.
  • Apply: Add docstrings to all functions and file headers.

This is an automated message generated by Mi6

@AhmedSeemalK
Copy link

Add docstrings to all functions and file headers.

binary_search.py Outdated
This file implements a binary search algorithm.
"""

def binary_search(lst, key):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add docstring to the function

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add docstring to the function

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add docstring to the function

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mi6: Add docstring to the function

Copy link
Owner Author

@psurabh psurabh Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Wrote Changes

Done.

This is an automated message generated by Mi6

high = mid - 1
return -1

if __name__ == "__main__":

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add docstring

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please add a docstring

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a docstring

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a docstring

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add docstring to the function

binary_search.py Outdated
This file implements a binary search algorithm.
"""

def binary_search(lst, key):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add docstring to the function

Copy link

@AhmedSeemalK AhmedSeemalK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mi6: add a docstring

Copy link

@AhmedSeemalK AhmedSeemalK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mi6: Add docstring to the function

binary_search.py Outdated
This file implements a binary search algorithm.
"""

def binary_search(lst, key):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add docstring to the function

binary_search.py Outdated
This file implements a binary search algorithm.
"""

def binary_search(lst, key):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mi6: Add docstring to the function

Copy link

@AhmedSeemalK AhmedSeemalK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mi6: Add docstrings to all functions and file headers.

Copy link

@AhmedSeemalK AhmedSeemalK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mi6: Add docstrings to all functions and file headers.

binary_search.py Outdated
if lst != sorted(lst):
return -1

low, high = 0, len(lst) - 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the variable to meaningful names

binary_search.py Outdated
This file implements a binary search algorithm.
"""

def binary_search(lst, key):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mi6: Give meaningful variable names

Copy link
Owner Author

@psurabh psurabh Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Wrote Changes

Done.

This is an automated message generated by Mi6

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

Successfully merging this pull request may close these issues.

2 participants