Graph Theory Solution for Microsoft bridge Problem

Source: Internet
Author: User

Graph Theory Solution for Microsoft bridge Problem

Microsoft's bridge problem is that four people have to use a flashlight when crossing a bridge at night. There is only one flashlight, and at most two people can pass each time, the speed of the four people crossing the bridge is 1 minute, 2 minutes, 5 minutes, and 10 minutes respectively. How long does it take for four people to go through the bridge at least?

If graph theory is used for modeling, a directed graph can be constructed using the state of four people at both ends of the bridge as nodes, as shown in, the state of the person who has crossed the bridge is used as the node of the graph. At the beginning, no one bridges the bridge. Therefore, it is expressed as null. In the first round, two people bridge the bridge and there are 6 possible combinations: (1, 2) (), it takes 2, 5, 5, 10 minutes to switch from an empty state to these states, time is used as the weight of a directed edge. When two people bridge the bridge, they need to take a flashlight back to pick up other people. There are four possible situations: 1, 2, 5, 10, one of them stayed on the other side of the river, (1, 2) this state can only be converted to (1) (2) two states, the corresponding edge weight is 2, 1 minute, (1, 2) to (1) it takes 2 minutes to return the result, and the following graph theory model can be created. It is required to determine the minimum length of time for four people to use Xiaoqiao. In fact, the shortest path between (empty) nodes and (1, 2, 5, 10) nodes is obtained in the figure.


According to the Dijkstra shortest path algorithm, it is easy to find the shortest path, as shown in the crude line. In this way, the total time is 2 + 1 + 10 + 2 + 2 = 17 minutes, so if we can learn Graph Theory live, this kind of intellectual problem becomes an entry-level question of graph theory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.