Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Let A[1..n] be an array containing n distinct integers sorted in increasing order, where n greaterthanorequalto 1. The following algorithm from page 364 of the
Let A[1..n] be an array containing n distinct integers sorted in increasing order, where n greaterthanorequalto 1. The following algorithm from page 364 of the text determines if a query integer x is in A; it returns the position of in A if is present and returns zero otherwise. The initial call is Binary-Search (1, n, x). Binary-Search (1, j, x)//Search subarray A[i..j] for x, 1 A [m] and j > m) then return Binary-Search (m + 1, j, x)) else return (0) end Let P(s) be the assertion that when presented with a subarray A[i..j] of size s = j - i + 1, Binary-Search(i, j, x) returns the position of in A[i..j] if x is present in the subarray and returns zero otherwise, 1 lessthanorequalto i lessthanorequalto j lessthanorequalto n. Use Strong Induction to prove that P(s) is true for s greaterthanorequalto 1. Similar to recursive linear search (discussed in class) consider separately the cases where is presentot present in the subarray being searched (A[i..j] here)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started