攘• 攘 Name: Wisc ID:
CS 577: Introduction to Algorithms Homework 7 Out: 03/23/21 Due: 03/30/21
-_-
Ground Rules
• Answer the questions in the boxes provided on the question sheets. If you run out of room for an answer, add a page to the end of the document. Do not feel obligated to fill the entire solution box. The size of the box does not correspond to the intended solution length.
• The homework is to be done and submitted individually. You may discuss the homework with others in either section but you must write up the solution on your own.
• Youarenotallowedtoconsultanymaterialoutsideofassignedtextbooksandmaterialtheinstructorspostonthe course websites. In particular, consulting the internet will be considered plagiarism and penalized appropriately.
• The homework is due at 11:59 PM CT on the due date. No extensions to the due date will be given under any circumstances.
• Homework must be submitted electronically on Gradescope. Problem 1
You are a police officer trying to crack a case. You want to check whether an important file is in the evidence room. Files have IDs that are positive integers and the evidence room contains n files in sorted order of their IDs. Unfortunately, you do not have direct access to the evidence room; the only one who has access is Randy, who is corrupt and wants to make things hard for you. In the following we assume that x is the file ID you are looking for.
1. You know that the evidence room is organized as a sorted list of n elements. If Randy was not corrupt you would probably do binary search by asking him to give you the median file of the list. Unfortunately, you can only give Randy two indices l, u and he returns to you a file with index chosen uniformly at random from the range {l,…,u}. That is you can call
RANDY(l, u) = (i, ai), where i is a uniformly random integer chosen from l, . . . , u inclusive and ai is the ID of the corresponding file.
You solve the problem by doing something similar to binary search. You start by calling RANDY(1, n). Let’s assume that Randy returns (i, ai). You compare x to ai.
• If x = ai you found the file you were looking for. • Ifx