Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Prove both parts of the question given below (Using a proof of loop invariant and anything other than a proof using loop invariant will automatically

Prove both parts of the question given below (Using a proof of loop invariant and anything other than a proof using loop invariant will automatically be rated poorly):

image text in transcribed

Input: data: a sorted array of integers Input: n: size of data Input: t: an integer Output: index i such that datalit, or -1 if t is not in data 1 Algorithm: BinarySearch 2 lo-1 4 while lo -1 do 6if datalmid-t then 7 return t else if data[mid t then 9 10else hi = mid 12 end 13 end 14 if datallol - t then 15 16 else 17return -1 18 end return datallo Prove the following about the implementation of binary search above. 1. Prove that if n is a power of 2 (that is, if n - 2k for some integer k), then hi - lo -2%- after iteration i of the while loop, for all i 2 1. Note: you do not have to prove the loop invariant if the algorithm does not reach the end of the loop, so you may assume that datalmid. 2. Use the preceding loop invariant to prove that the while loop must even- tually terminate

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions