Using algorithms to detect the food chain in the Premier League

Source: Internet
Author: User
Tags rounds
This is a creation in Article, where the information may have evolved or changed.

Recently saw a news: the English Premier League to reproduce the horror of the food chain! 20 Strong fits together 14 rounds this year, for football and the English Premier League interested readers must understand that the so-called food chain is a team better than Team B, team B better than team C,......, n team is better than team A, as of the 14th round, according to all the team One of the biggest food chains has been formed and the 20 teams in the Premier League have joined the food chain, fits together.

I saw this news, a little bit of programmer's involuntary idea, can the algorithm check the current largest food chain, and can the food chain listed? This is a good example of the algorithm to solve the actual problem.

Naturally, the relationship between the two teams can be represented by graphs, because we only consider the relationship between the winning and losing, regardless of the draw, so we can use a graph to express. The food chain can be expressed simply as either a win or a negative, so we have a positive graph in which the relationship between the two nodes is represented by a win.

Of course, I'm not very familiar with the graph-related algorithms, so i specifically searched the relevant mature algorithm. For the solution to the food chain, we can see if there is a ring in the graph that contains all 20 nodes (20 Premier League teams). That is, to solve the strong connected component in this graph.

Baidu Encyclopedia: The direction graph strong connected components: in the graph G, if two vertices vi,vj (VI>VJ) has a direction from the VI to the VJ path, while there is a direction from the VJ to the VI of the path, it is said that two vertices strong connectivity (strongly connected). If there is strong connectivity to every two vertices of the graph G, the G is a strongly connected graph. A strongly connected sub-graph of a graph, called a strongly connected component (strongly connected components).

Related algorithms include Kosaraju, Tarjan, Gabow, etc., interested friends can search the relevant introduction.

I use the Tarjon algorithm provided by Http://github.com/looplab/tarjan to calculate:

1234567891011121314151617181920212223242526272829303132333435
 PackageMainImport("FMT""Github.com/looplab/tarjan")funcMain () {graph: = Make(Map[Interface{}][]Interface{}) graph["Chelsea"] = []Interface{}{"Manchester City","Tottenham","Middlesbrough","Everton","Southampton","Manchester United","Leicester City","Hull City","Burnley","Waterford","West Ham"}graph["Arsenal"] = []Interface{}{"West Ham","Bournemouth","Sunderland","Swansea","Burnley","Chelsea","Hull City","Southampton","Waterford"}graph["Liverpool"] = []Interface{}{"Sunderland","Waterford","Crystal Palace","West Bromwich Albion","Swansea","Hull City","Chelsea","Leicester City","Arsenal"}graph["Manchester City"] = []Interface{}{"Crystal Palace","Burnley","West Bromwich Albion","Swansea","Bournemouth","Manchester United","West Ham","Stoke City","Sunderland"}graph["Tottenham"] = []Interface{}{"Swansea","West Ham","Manchester City","Middlesbrough","Sunderland","Stoke City","Crystal Palace"}graph["Manchester United"] = []Interface{}{"Swansea","Leicester City","Hull City","Southampton","Bournemouth"}graph["West Bromwich Albion"] = []Interface{}{"Waterford","Burnley","Leicester City","West Ham","Bournemouth","Crystal Palace"}graph["Everton"] = []Interface{}{"West Ham","Stoke City","West Bromwich Albion"}graph["Stoke City"] = []Interface{}{"Burnley","Waterford","Swansea","Hull City","Sunderland"}graph["Bournemouth"] = []Interface{}{"Liverpool","Stoke City","Hull City","Everton","West Bromwich Albion"}graph["Waterford"] = []Interface{}{"Leicester City","Hull City","Middlesbrough","Manchester United","West Ham"}graph["Southampton"] = []Interface{}{"Everton","Burnley","West Ham","Swansea"}graph["Middlesbrough"] = []Interface{}{"Hull City","Bournemouth","Sunderland"}graph["Crystal Palace"] = []Interface{}{"Southampton","Sunderland","Stoke City","Middlesbrough"}graph["Everton"] = []Interface{}{"West Ham","Middlesbrough","Sunderland"}graph["Burnley"] = []Interface{}{"Crystal Palace","Everton","Waterford","Liverpool"}graph["Leicester City"] = []Interface{}{"Crystal Palace","Burnley","Swansea"}graph["West Ham"] = []Interface{}{"Sunderland","Crystal Palace","Bournemouth"}graph["Sunderland"] = []Interface{}{"Leicester City","Hull City","Bournemouth"}graph["Hull City"] = []Interface{}{"Southampton","Swansea","Leicester City"}graph["Swansea"] = []Interface{}{"Crystal Palace","Burnley"}output: = Tarjan. Connections (graph) fmt. Printf ("%d,%v\n",Len(Output[0]), Output)}

The running can get its strong connectivity components:

1
 - [[Arsenal Spurs Manchester United Manchester City Chelsea Swansea West Bromwich Albion Liverpool Bournemouth Middlesbrough Watford Burnley Stoke City Crystal Leicester-Sunderland West Ham Everton Southampton Hull]]

As you can see, this strong connectivity component contains all 20 teams, stating that the longest food chain in the premiership has been formed after the end of the 14th round.

But the results did not return the food chain, which only showed that the 20 teams formed the food chain.

Because I am not familiar with the relevant algorithms, the reader should answer the following questions, or provide their own code:

    1. The Tarjan algorithm and the Gabow algorithm cannot compute this topological relationship, and the Kosaraju algorithm can?
    2. Because of the small amount of data, you can search directly through the DFS algorithm?

The biggest food chain in La Liga has been formed, the answer is no, because Real Madrid has not lost the first 14 rounds. Interested readers can calculate which teams are currently the biggest food chain in La Liga.

Related Article

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.