Lab: Page Ranking
- Page Ranking algorithm
Defining and invoking functions
Downloads folder, download the
Task 1 - Page Ranking for three pages
We will write a program to compute the page ranking for this particular graph:
Open the file
pageRank3.htmlin your editor. Examine the code.
Define a function
computePageRank3()in a file named
pageRank.js. This function reads the values for each of the three pages from the web page, and calculates the new values, after one iteration only, based on the
Brin and Page Algorithm. At the end, it presents the results on the web page.
Add a button on the web page and arrange so that when the button is clicked the
computePageRank3()function is called. Feel free to reference material from a previous lab, or check the on line w3schools documentation/tutorials on JS buttons.
- What happens if you click on the button again and again, multiple times?
Task 2 - Page Ranking for four pages
- Create a file,
pageRank4.html, that will be used to compute the page ranking on this particular graph, which contains 4 pages:
In your file
pageRank.jsdefine a function named
computePageRankOneRound(). It will just do what its name says: compute the ranking of each of the four pages in this graph, after only one iteration of the Brin and Page algorithm. Use your work on the previous task to get guided.
- Test your work by calling the function multiple times, as you click on the
Compute button, until the values converge (do not change any more).
Define one more function, named
computePageRankManyRounds()which takes an integer number,
n, as input. This function will call the
n times. You are encouraged to check the online documentation in w3schools: search for "w3schools js for loop"
Attach this function to the
Compute button. Experiment to see what number you should pass it as input, so that the final values are computed.
- If time permits, add one more input field to the page, for the user to enter the number of rounds they would like to perform.