Question
Consider the algorithm below, which identifies the elements of an array that are no larger than a given threshold. A) Prove that hi lo n
Consider the algorithm below, which identifies the elements of an array that are no larger than a given threshold.
A) Prove that hi lo n 2i + 1 after iteration i of the outer repeat loop of SmallElements, for every iteration. I.e., hi lo n 1 after the first iteration, n 3 after the second, and so forth.
Hint: you may wish to use loold to represent the value of lo at the end of the previous iteration and lonew to represent the value of lo at the end of the current iteration, and similar variables for hi.
B) Use the previous claim to prove that the outer loop terminates.
Input: data: an array of integers Input: n: the length of data Input: t: threshold value Output all elements of data that are S t 1 Algorithm Small Elements 2 lo 0 3 hi n 1 4 repeat repeat lo lo 1 7 until data lo t or his lo repeat hi hi 1 10 until data hil Stor his lo 11 if hi lo then return data 1. lo 1] 12 13 end 14 Swap data lo and data hi 15 until 1Step 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