Challenge

Project 2

1)

def binary_search(signal, can_data):
low = 0
high = len(can_data) - 1

while low <= high:
mid = (low + high) // 2
mid_val = can_data[mid]

if mid_val == signal:
return mid
elif mid_val < signal:
low = mid + 1
else:
high = mid - 1

return -1 # Signal not found

# Example usage
instrument_cluster_data = [10, 20, 30, 40, 50, 60, 70, 80, 90]
signal_to_find = 60

index = binary_search(signal_to_find, instrument_cluster_data)
if index != -1:
print(f"Signal {signal_to_find} found at index {index}.")
else:
print(f"Signal {signal_to_find} not found.")

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.