Question: In this Short Assignment, you will be implementing two functions: bisect _ left and bisect _ right. These two functions are implemented similarly to the

In this Short Assignment, you will be implementing two functions: bisect_left and bisect_right. These two functions are implemented similarly to the binary search algorithm. The goal of both of these functions is to provide an index to place an integer, target, into an arrayList, arr, that is in ascending sorted order, such that arr maintains sorted order after target is placed. bisect_left is the leftmost index at which target can be placed and bisect_right is the rightmost index at which target can be placed. Note: if an index is selected for placement, all values right of and including the index will be moved one place to the right to accommodate insertion of the target element at position i.
int bisect_left(int[] arr, int n, int target): Return the leftmost index at which target can be placed. In other words, provide an index such that all values left of and including that index position are less than target. For example, if arr =[1,2,3,8,8,8,9,10,11], n =9, and target =8. bisect_left(arr, n, target), would return 3. If target is greater than the maximum element of arr, return n. If target is less than than the minimum element of arr, return 0.
int bisect_right(int[] arr, int n, int target): Return the rightmost index at which target can be placed. In other words, provide an index such that all values left of and including that index position are less than or equal to target. For example, if arr =[1,2,3,8,8,8,9,10,11], n =9, and target =8. bisect_right(arr, n, target), would return 6. If target is greater than the maximum element of arr, return n. If target is less than than the minimum element of arr, return 0.
You may assume that arr is nonempty and is in sorted ascending order. Indices are enumerated starting at integer value 0. You must use the Binary Search algorithm in some way. You cannot use iterative/sequential search.
write in C++ please

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!