# CS302P Assignment 3 solution 2023

CS302P Assignment 3 solution 2023. In this assignment, you were tasked with implementing a binary search algorithm in Python. Binary search is a fundamental algorithm in computer science and is used to efficiently find an element in a sorted list. The key idea behind binary search is to repeatedly divide the search interval in half until the element is found.

To implement binary search, you first need to sort the list using a sorting algorithm, such as merge sort or quick sort. Once the list is sorted, you can begin the search by setting the left and right endpoints of the interval. Then, you check the middle element of the interval and compare it to the target value.

If the middle element is less than the target value, you update the left endpoint to be the middle element plus one. If the middle element is greater than the target value, you update the right endpoint to be the middle element minus one. You repeat this process until the target value is found, or the interval becomes empty.

One advantage of binary search is that it has a time complexity of O (log n), where n is the size of the list. This means that binary search is very efficient for large lists. However, binary search can only be used on sorted lists. If the list is not sorted, you first need to sort it, which can take O(n log n) time.

Overall, this assignment was a good opportunity to practice implementing a fundamental algorithm in computer science. By completing this assignment, you should now have a better understanding of binary search and its applications.

### Get solution file From here

See below latest assignment solutions: