Implementing Urank Solution – Intro to Computer Science

By | January 25, 2020


So the answer is, we only need to add one line. We need to add the line at line 13. And the line that we need, is to update the graph. So we’re going to have a new entry in the graph, that is the page that we’re crawling. So that’s going to be the key for the entry that we want to associate with that page, a list of the links. That you can reach from that page, all the outgoing links. Well that’s exactly what we stored in the variable outlinks. So that’s the only line of code that we need to add, to produce the graph. We needed to initialize the graph as an empty dictionary, we needed to change the return it. But the only substantive change, was adding this line. And, we’ll run that, we’ll call crawl_web. Passing in the test URL. And this time we have two variables on the left side. So we’re going to assign the index to index. And we’ll assign the graph to graph. And let’s check that the graph has what it should. So we’ll print out to get graph entry for the index page. And, what we get, we see a list of five URLs. Hummus, arsenic, kathleen. Nickel and zinc. And this corresponds to the picture here. We had five outgoing links from the index page to those five other pages. Let’s look at another one. We can print the graph for the Kathleen page, and that had no outgoing links, so what we see here is the empty list. And, we can see the whole graph, we have each URL. With a list of all the pages that, that page links to. So both the Hummus and the Kathleen page don’t link to anything. The Zinc page links to the Nickel page, and the Arsenic page, and so on. So now we have our graph. The next step is to figure out how to use that graph, to do the page ranks.

Leave a Reply

Your email address will not be published. Required fields are marked *