answer.
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
2 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]2 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]2 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
Define a structure type auto_t to represent an automobile. Include components for the make and model (strings), the odometer rea
yulyashka [42]

Answer:

see explaination

Explanation:

#include <stdio.h>

#include <string.h>

#define BUFSIZE 1000

struct auto_t scan_auto(char *);

struct date_t {

char day[2];

char month[2];

char year[4];

};

struct tank_t {

char tankCapacity[10];

char currentFuelLevel[10];

};

struct auto_t {

char make[50];

char model[50];

char odometerReading[10];

struct date_t manufactureDate;

struct date_t purchaseDate;

struct tank_t gasTank;

};

int main(int argc, char *argv[]) {

/* the first command-line parameter is in argv[1]

(arg[0] is the name of the program) */

FILE *fp = fopen(argv[1], "r"); /* "r" = open for reading */

char buff[BUFSIZE]; /* a buffer to hold what you read in */

struct auto_t newAuto;

/* read in one line, up to BUFSIZE-1 in length */

while(fgets(buff, BUFSIZE - 1, fp) != NULL)

{

/* buff has one line of the file, do with it what you will... */

newAuto = scan_auto(buff);

printf("%s\n", newAuto.make);

}

fclose(fp); /* close the file */

}

struct auto_t scan_auto(char *line) {

int spacesCount = 0;

int i, endOfMake, endOfModel, endOfOdometer;

for (i = 0; i < sizeof(line); i++) {

if (line[i] == ' ') {

spacesCount++;

if (spacesCount == 1) {

endOfMake = i;

}

else if (spacesCount == 2) {

endOfModel = i;

}

else if (spacesCount == 3) {

endOfOdometer = i;

}

}

}

struct auto_t newAuto;

int count = 0;

for (i = 0; i < endOfMake; i++) {

newAuto.make[count++] = line[i];

}

newAuto.make[count] = '\0';

count = 0;

for (i = endOfMake+1; i < endOfModel; i++) {

newAuto.model[count++] = line[i];

}

newAuto.model[count] = '\0';

count = 0;

for (i = endOfModel+1; i < endOfOdometer; i++) {

newAuto.odometerReading[count++] = line[i];

}

newAuto.odometerReading[count] = '\0';

return newAuto;

}

8 0
2 years ago
A mass m is attached to the end of a rope of length r = 3 meters. The rope can only be whirled around at speeds of 1, 10, 20, or
gayaneshka [121]

Answer:

Explanation:

Let's do this in Python. We know that the formula for the centripetal force caused by whirling the mass is:

F = m\frac{v^2}{r}

where v is the speed (1, 10, 20, 40) and r = 3 m is the rope length.

Then we can use for loop to try calculating the tension force of each speed

def maximum_speed(m):

    for speed in [1, 10, 20, 40]:

         tension_force = m*speed^2/3

         if tension_force > 60:

              return speed

    return speed

7 0
2 years ago
A developer needs to create a visualforce page that displays case data. The page will be used by both support reps and support m
shutvik [7]

Answer:

B. Use a new support manager permission sets

Explanation:

According to the requirements, field level security is required so, 1st options is not suitable because it may reduce the maintenance cost but increase the risk of security.

By creating a separate page for each of the two, it will leads to increase in the maintenance cost of the system. So <u>Option C</u> is also not suitable.

Option B is more Suitable as compared to others, that <em>Create a new support manager permission set</em>, with the help of this, both of Support rep and Support manager can visualize their required information with the help of support manager permission. This solution will not compromise the security and not increase the maintenance cost.

7 0
2 years ago
How can you check an orthographic drawing to be sure there are no missing lines
user100 [1]
With an magnify glass
4 0
2 years ago
Network flow issues come up in dealing with natural disasters and other crises, since major unexpected events often require the
nasty-shy [4]

Answer:

Check the explanation

Explanation:

Algorithm for solving flood condition:

We suggest an algorithm to resolve the flood condition by creating a flow network graph.

Let us assume for every patient "p" there is a node "2" and for every hospital "h" there is a node "uh" and there is an edge ()T, uh) exist between patient "p" and hospital "h" with flow capacity of 1 iff patient "p" is reachable to hospital "h" within a half-hour.

Then source node "s" is made between all the patient-nodes by an edge with flow capacity of 1 and then the sink "t" is made by linking all the hospital nodes by an edge with capacity "[n/k]".

There is an approach to send patients to hospitals: when there is a source "s" to sink "t" flow of "n". We can send 1 flow-unit from source "s" to sink "t" along the paths (s, yp, uh, t) whenever a probable approach is available to send patients.

This approach of sending patients to hospitals doesn't break the capacity limitation of edges. Hence we can send patient "p" to hospital "h" with 1 flow- unit if edge(m uh) permits at least 1 flow- unit.

The running-time of this algorithm is found by finding the time needed to solve max-flow graph with nodes O(n+k) and edges O(n^{k}) edges.

5 0
2 years ago
Other questions:
  • Donna often travels around the world. When she travels, she needs to access her emails from different locations. However, to kee
    6·2 answers
  • The navigation bar on the left side of ____ view contains commands to perform actions common to most office programs.
    15·1 answer
  • FOREACH, EXPLODE and MAIL are examples of crazy functions.
    13·1 answer
  • In step 4 of the CSMA/CA protocol, a station that successfully transmits a frame begins the CSMA/CA protocol for a second frame
    9·1 answer
  • Using the RAID controller on the motherboard, you configure three hard disks in a RAID 5 array. You leave the array unpartitione
    14·1 answer
  • Wendy is an attacker who recently gained access to a vulnerable web server running Microsoft Windows. What command can she use t
    9·1 answer
  • Program MATH_SCORES: Your math instructor gives three tests worth 50 points each. You can drop one of the test scores. The final
    7·1 answer
  • Write code that determines the number of full days represented by the number of hours stored in the variable hours and stores th
    15·1 answer
  • You know that you should check the room for security against unwanted entry do you check locks on doors and windows. What else d
    15·1 answer
  • An e-commerce client is moving from on-premise, legacy systems to a cloud-based platform. During the transition, the client is a
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!