Question: SE and Programming 2090- Extra Work for Practice Write a function in HASKELL to do the following... Recursive Binary Search - binary_search(data, item, offset) Takes

SE and Programming 2090- Extra Work for Practice

Write a function in HASKELL to do the following...

Recursive Binary Search - binary_search(data, item, offset)

Takes a sorted list, data, and performs a recursion binary search of data for the element item. If found, returns the index where the item is found. If not found, returns 1. offset is a variable used for recursive calls to record the offset from the original data. The function will always be initially called with this set to 0. You are permitted to use the following functions:

take n alist - returns, as a list, the first n items in an alist

drop n alist = returns a list without the first n items of alist

quot num divisor - returns the quotient of num / divisor

length alist - returns the length of a list

mathematical/comparison operations (+, -, <, etc.)

!! - list index operator

Template:

module Function where
import Data.List
import Data.Maybe
binary_search list item offset = Nothing -- fill in

Examples:

*Main> binary_search([0, 3, 5], 5, 0) 2 *Main> binary_search([0, 3, 5, 7], 0, 0) 0 *Main> binary_search([0, 3, 5, 7], 42, 0) -1

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 Databases Questions!