1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kramer
3 years ago
5

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 .

a.If x = ai you found the file you were looking for.
b.If x < ai you call RANDY(1, i − 1)
c.If x > ai you call RANDY(i + 1, n).

You continue recursively until you have either found the file or conclude that the file is not present in the evidence room. Show that the above algorithm accesses O(log n) files in expectation before it terminates.

2. With his trick in the previous question Randy was not able to slow you down very much1 . Now he decides to disallow "range" queries as above and only allows either sequential access to the files or access to a uniformly random file from the entire set. In particular, you now have two ways of accessing the list:

a.By looking at a uniformly random element of the list. That is by calling RANDY() = ai , where i is chosen uniformly at random from 1, . . . , n, inclusive.
Observe that you only receive the file ID, not the index of the file.

b.By asking Randy to give you the file directly following one he returned to you in some previous call. For example if you first call RANDY() and get back ai you are allowed to call NEXT(ai) and get back ai+1. Note that the list wraps around, so that NEXT(an) returns a1. If you haven’t already obtained ai in some previous call you may not call NEXT(ai).

To facilitate analyzing this setting, think of the files as being organized in the form of a circular sorted linked list where every file points to the one with the next higher ID.

(a) As a warm up, let us analyze the following setting. You are given a circle of unit circumference. You pick k points on the circle independently and uniformly at random and snip the circle at those points, obtaining k different arcs. Determine the expected length of any single arc. (Hint: Note that the length of each arc is identically distributed, so each has the same expectation. What is the sum of their expectations?)

(b) Develop a randomized algorithm for finding the file with ID x that makes at most O( √ n) calls to the functions NEXT() and RANDY() in expectation and always returns the correct answer. Analyze the running time of the algorithm. A proof of correctness is not necessary. (Hint: Your algorithm will perform some random accesses and some amount of linear search. Use part (a) to analyze the number of steps in the linear search)
Computers and Technology
2 answers:
Deffense [45]3 years ago
4 0

Answer:

Answer:

RANDY returns randomly, therefore any file within the index range with uniform distribution will have the recurrence relation to be

T(n) = T(n-i) + O(1)

With probability 1/n where i can range from 1 to n. Here, parameter n inside T(n) indicate the size of index range which will become (n-i) in next iteration.

Since i can range from 1 to n with probability 1/n, therefore the average case time complexity will be

T(n) =

Now solving T(n) = T(n/2)+O(1)

Will give T(n) = O(log n)

Therefore time complexity of this algorithm is O(log n).

Note that this is average time complexity because it's a randomized algorithm. In worst case, index range may just reduce by 1 and give time complexity of O(n) since in worst case T(n) = T(n-1)+O(1)

Explanation:

horsena [70]3 years ago
3 0

Answer:

RANDY returns randomly, therefore any file within the index range with uniform distribution will have the recurrence relation to be

T(n) = T(n-i) + O(1)

With probability 1/n where i can range from 1 to n. Here, parameter n inside T(n) indicate the size of index range which will become (n-i) in next iteration.

Since i can range from 1 to n with probability 1/n, therefore the average case time complexity will be

T(n) = \sum_{i=1}^{n}\frac{1}{n}T(n-i) + O(1) = T(n/2)+O(1)

Now solving T(n) = T(n/2)+O(1)

Will give T(n) = O(log n)

Therefore time complexity of this algorithm is O(log n).

Note that this is average time complexity because it's a randomized algorithm. In worst case, index range may just reduce by 1 and give time complexity of O(n) since in worst case T(n) = T(n-1)+O(1)

You might be interested in
Audience centered public speakers are inherently sensitive to the
DanielleElmas [232]
Diversity of their audiences
7 0
3 years ago
Read 2 more answers
What keyword is used to declare a method in python?
Harrizon [31]
I think the answer is B
8 0
3 years ago
Which of the following is a way to prevent wastes from contaminating the environment? A) Use absorbent pads to collect floor was
Firlakuza [10]

Answer

Dispose of absorbents as hazardous waste in its own hazardous waste container

Explanation

Hazardous waste is a waste that has chemical composition and properties which makes it capable of causing illness, death  or harm to humans and other life forms when released to the environment without proper management. The characteristics of such wastes include: toxic, ecotoxic, infectious substance, poisonous, explosive and flammability. Hazardous wastes can be destroyed by incineration, chemical process, and temporary on-site waste storage facilities such as waste piles and lagoons/ponds



8 0
4 years ago
Read 2 more answers
Which of the following tasks is the project manager least likely to be involved in?
user100 [1]

Answer:

i think its d sorry if i am wrong

3 0
3 years ago
Read 2 more answers
Define a method printAll() for class PetData that prints output as follows with inputs "Fluffy", 5, and 4444. Hint: Make use of
QveST [7]

Answer:

public void printAll(){  // member function petAll()

   super.printAll();  //  calls printAll() method of the superclass (base class) AnimalData using super keyword

   System.out.print(", ID: " + idNum);} // prints the ID stored in the idNum data member of the PetData class

Explanation:

Here is the complete PetData class:

public class PetData extends AnimalData {  //

private int idNum;

public void setID(int petID) {

idNum = petID;  }

// FIXME: Add printAll() member function

/* Your solution goes here */

public void printAll(){

   super.printAll();

   System.out.print(", ID: " + idNum);}  }

PetData class is a subclass which is inherited from the base class AnimalData.

This class has a private data member which is the variable idNum which is used to store the ID value.

It has a member function setID with parameter petID which is the idNum. This method basically acts as a mutator and sets the user ID.

This class has another method printAll() that uses super keyword to access the method printAll() of the base class which is AnimalData

super basically refers to the base class objects.

Here the super keyword is used with the method name of subclass PetData in order to eliminate the confusion between the method printAll() of AnimalData and PetData since both have the same method name.

In the main() method the use is prompted to enter values for userName, UserAge and UserID. Lets say user enters Fluffy as user name, 5 as user age and 4444 as userID. Then the statement userPet.printAll(); calls printAll() method of PetData class as userPet is the object of PetData class.

When this method is called, this method calls printAll() of AnimalData class which prints the Name and Age and printAll() of PetData class prints the ID. Hence the program gives the following output:

Name: Fluffy, Age: 5, ID: 4444    

8 0
3 years ago
Other questions:
  • Which of the following is needed if a computer with the IP address 172.31.210.10/24 wants to communicate with a computer with th
    5·1 answer
  • You have been tasked with training end users in security best practices and have observed a trend among users in which many are
    14·1 answer
  • My 2 in 1 laptop/tablet
    13·1 answer
  • The Joint Photographic Experts Group developed the ___________ graphic format.
    12·2 answers
  • What processes are needed to transform a c++ program to a machine language program that is ready for execution?
    14·1 answer
  • What port in your computer will you use to plug in your camera?
    14·2 answers
  • Adjusting the ______ adjusts the difference in appearance between light and dark areas of the photo.​
    10·2 answers
  • The simplest method to copy information is to first select the information you want to copy, and then use the Copy button and th
    11·1 answer
  • Examine the following code.
    9·1 answer
  • Use the drop-down menus to explain what happens when a manager assigns a task in Outlook.
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!