Consider the following algorithm for finding a target element t in an array x_1,
ID: 3692963 • Letter: C
Question
Consider the following algorithm for finding a target element t in an array x_1, x_2,...., x_n Assume as a precondition that exactly one of the x_i 's is equal to t. Choose/at random from {1, 2,...., n} while x_1 t do choose/at random from {1, 2,...., n}.print Element t was found in location i. This algorithm continues to guess randomly until it finds where t is. Note that it does not keep track of its previous guesses, so it may check the same location more than once, Find the best-case number of comparisons made by this algorithm. Warning: Tricky. Find the worst-case number of comparisons made by this algorithm. Calculus required. Use the sum of an infinite series to find the average-case number of comparisons made by this algorithm.Explanation / Answer
Please find the answer below :
b) n2
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.