Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

Comprehend the concept of the "psychological contract."

Answered: 1 week ago