Need help with sml languege I need to write a binarySearch function that recursively implements the binary search algorithm to search a sorted integer list for a specified integer and returns true if it is found, false otherwise.  For exa

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 18PE
icon
Related questions
Question
100%

Need help with sml languege I need to write a binarySearch function that recursively implements the binary search algorithm to search a sorted integer list for a specified integer and returns true if it is found, false otherwise.  For example, binarySearch ([100,200,300,400,500], 200) returns true, whereas binarySearch([100,200,300,400,500], 299) returns false. Hint: Write a helper function mid that returns a tuple (index, value) representing the middle value in a list. For example, mid [10, 2, 40, 8, 22] returns (2,40) because the value 40 at index 2 is the middle value in the list. Similarly, mid [10, 20] would return (1, 20). Use mid in conjunction with slice to implement binarySearch.

Here is my slice function:

fun count(index,hd::tl,start,stop) =
if index+1 >= stop then hd::nil
else if index >= start then hd::count(index+1,tl,start,stop)
else count(index+1,tl,start,stop);
fun slice(x::y, start, stop) = 
count(0,x::y,start,stop);

And here is the dummy implementation of binary search :

fun binarySearch(sortedList, value) = false;

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Lists
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning