Question

In: Computer Science

In lecture we discussed Milgram’s 1967 experiment; he picked 300 people at random in Nebraska and...

In lecture we discussed Milgram’s 1967 experiment; he picked 300 people at random in Nebraska and asked them to send a letter to a stockbroker in Boston, by way of relaying the letter through a chain of people. The rule is that every person has to know the next person they are sending the 1 letter to on a first name basis. He found that on average each letter went through the hands of 6.4 people before reaching the stockbroker. This is where the expression ”six degrees of separation” comes from. When you tell your friend Dirk about this experiment he says he is not surprised. Dirk says that often, when he tells something to a friend, a couple of days later he hears back the same information from someone else! You decide to test whether the six degrees of separation principle can also be applied to oneself. Let’s imagine that “friendships” on Facebook are a good representation of Milgram’s rule for being on first-name terms with somebody. Assume you are given access to all of the friendship links on Facebook as a graph (where nodes are accounts, and links are “friends”). Design an algorithm to determine if there is a chain of at most 7 friends (because the average number in Milgram’s experiment was 6.4) such that Dirk is friends with both the first and the last person. You may assume that the graph is undirected. For full credit your algorithm should run in time O(m + n) (where n and m are the number of nodes and edges, respectively).

Hint: MODIFY/ USE BFS please helP!

Solutions

Expert Solution

What you're looking for is cycle detection in undirected graph using BFS and the only change I have to make is add a counter to keep a track of how many nodes are intermediaries.

1. Initialize the parent array as -1. It will keep track of the parents of nodes we encountered. Initially, all nodes have parents set to -1 because we don't know yet that who is who's parent(valid assumption, right?)

2. Initialize counter to 0 and visited(array to check what all nodes we have visited - standard bfs) as -1, indicating we haven't yet visited any node.

3. Create a queue for BFS. Enqueue the start node(Dirk) to it. Mark the start node(Dirk) as visited and insert it to the queue.

4. While the queue is not empty, deque a vertex from queue (call it u) and increment counter by 1. For all adjacent vertices v, check

  • If v has not yet been visited - mark v as visited, increment counter by 1, enqueue v and set parent of v as u.
  • else, if v has been visited, check if parent of u is not v. If that is the case, return counter and break out of the loop because it's a cycle, right?

5. Return "-1" indicating that no cycle was found, if nothing was returned from 4b.

** In your case, you should return true/break if the value of counter is at most 7. I haven't added this, because it's meant to be a general algorithm.

Running time : O(m + n)


Related Solutions

Consider the field experiment with politicians that we discussed in the lecture. The experiment is based...
Consider the field experiment with politicians that we discussed in the lecture. The experiment is based on a modified dictator game. In Treatment 1 (i.e. T1), nature plays with high probability (equal to 0.8) and randomly assigns the endowment either to the politician-dictator or to the recipient. The politician--dictator plays with complementary probability (and knows, when making a decision, that this decision will be implemented); in contrast, a recipient who receives zero (or the full endowment), will not know whether...
1. We discussed in the lecture that the coronavirus is both an AS and AD shock....
1. We discussed in the lecture that the coronavirus is both an AS and AD shock. Based on the lecture, draw a graph showing both of the movements. You need a properly drawn graph as you did for homework 4. Update for clarity: For this question, we’re only capturing the effect of the virus itself. Don’t assume there are any particular policies associated with these shocks. It’s probably easiest to think of the AS shock as the reduced labor force...
In this week's lecture we have discussed the concept of insider trading as it exists and...
In this week's lecture we have discussed the concept of insider trading as it exists and is viewed around the world. Discuss your view on how insider trading should be viewed
Describe how the “kidney” works in amphixous using the anatomical terms we discussed in lecture and...
Describe how the “kidney” works in amphixous using the anatomical terms we discussed in lecture and then a possible mechanism of how it may move materials from the blood
In this week's lecture we discussed multiple concepts related to emotions. For this discussion, discuss your...
In this week's lecture we discussed multiple concepts related to emotions. For this discussion, discuss your thoughts about the relationship between emotions and consciousness.
In Lecture A9, we discussed an example of new product introduction. Draw the two trees of...
In Lecture A9, we discussed an example of new product introduction. Draw the two trees of Managers X and Y. Solve the two trees to find each manager’s EMV. Which manager’s tree has a higher EMV? What is the economic meaning of the difference of the two EMV’s? [Hints: Think about the value of knowing if the production process is delayed or not when the manager needs to make the price decision] (Optional) What are the risk profiles of the...
In Lecture 5, we discussed how to solve the Tower of Hanoi problem (Exercise 5.36 in...
In Lecture 5, we discussed how to solve the Tower of Hanoi problem (Exercise 5.36 in the textbook). Consider the following problem variant in which one extra constraint has been added: There are three pegs and n disks of different sizes. Initially, all disks are on the leftmost peg and arranged in order of decreasing size, with the smallest disk on top. The task is to move all the disks to the rightmost peg, under the constraints that: • Only...
11) Discussion: Female Employment Engagement As we discussed in the lecture, The decades between 1950 and...
11) Discussion: Female Employment Engagement As we discussed in the lecture, The decades between 1950 and 2010 were associated with a steady decline in the percentage of working age males in work and a steady increase in the percentage of working age females in work. Increased female employment was associated with both low-paid insecure work (retail, hospitality) and high-paid secure work (education, health care). Since 2010, we have seen major steps to improve female employment – unpaid paternity leave of...
From our Week 2 lecture, we discussed the history of Health and Health Education. In 1850,...
From our Week 2 lecture, we discussed the history of Health and Health Education. In 1850, Lemuel Shattuck wrote a Report of the Sanitary Commission of Massachusetts and shared how public health problems should be approached. Provide examples of his recommendations and explain if those approaches do or do not apply to today’s public health problems. Answer in essay based
: Recall the airplane cargo problem we have discussed in our first lecture. An air-freight company...
: Recall the airplane cargo problem we have discussed in our first lecture. An air-freight company has 8 adjacent positions on its Boeing-727 aircraft for freight containers. The weights of this containers depend on what they are carrying. and company statistics indicate that %7 of the containers are classified as ”heavy”. While heavy containers are not inherently dangerous, having two such containers next to each other is considered dangerous should the plane encounter a wind gust. Understandably, company wants to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT