Binary search Consider the binary search algorithm implementation below. def binarySearch [T] (arr: Array [T], e: T) (using ord: Ordering [T]) = def inner (lo: Int, hi: Int): Boolean = if lohi then val mid= lo + ((hi-lo) / 2) val cmp ord.compare(e, arr(mid)) if cmp=0 then true // e == arr (mid) else if cmp < 0 then inner (lo, mid-1) // e< arr(mid) else inner(mid+1, hi) //e> arr(mid) else false inner (0, arr.length-1) Simulate its execution on the sorted array below when searching for the value -8. Click on the array elements in the same order the algorithm accesses them. Note: submission, reloading the page, and a session timeout will create a new instance! 3 4 9 10 11 12 13 14 15
Binary search Consider the binary search algorithm implementation below. def binarySearch [T] (arr: Array [T], e: T) (using ord: Ordering [T]) = def inner (lo: Int, hi: Int): Boolean = if lohi then val mid= lo + ((hi-lo) / 2) val cmp ord.compare(e, arr(mid)) if cmp=0 then true // e == arr (mid) else if cmp < 0 then inner (lo, mid-1) // e< arr(mid) else inner(mid+1, hi) //e> arr(mid) else false inner (0, arr.length-1) Simulate its execution on the sorted array below when searching for the value -8. Click on the array elements in the same order the algorithm accesses them. Note: submission, reloading the page, and a session timeout will create a new instance! 3 4 9 10 11 12 13 14 15
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 6 steps
Follow-up Questions
Read through expert solutions to related follow-up questions below.