Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a function which does a binary search, as we studied in class. We proved its correctness using induction. Answer the following regarding this

This is a function which does a binary search, as we studied in class. We proved its correctness using induction. Answer the following regarding this function.
You may have additional questions on this exact code later in the exam.
pre: A is an array a..b of integers; a <= b+1
function BinSearch (A:Array, a,b: integer, x:eltype)
if a > b then
return false
else
mid :=(a+b) div 2
if x = A[mid] then
return true
else
if x < A[mid]
return BinSearch(A, a, mid-1, x)
else
return BinSearch(A, mid+1, b, x)
The inductive hypothesis assumes that the algorithm is _?_
Group of answer choices
correct for problem sizes >0 and < n
correct for 0 elements
correct for any problem size n
incorrect if x <> A[mid]

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

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions