Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Programming in Racket or Scheme Given: Problem (replace '...' with correct code): (provide graph? pagerank? num-pages num-links get-backlinks mk-initial-pagerank step-pagerank iterate-pagerank-until rank-pages) ;; This program
Programming in Racket or Scheme
Given:
Problem (replace '...' with correct code):
(provide graph? pagerank? num-pages num-links get-backlinks mk-initial-pagerank step-pagerank iterate-pagerank-until rank-pages) ;; This program accepts graphs as input. Graphs are represented as a ;; list of links, where each link is a list '(,src , dst) that signals ; ; page src links to page dst. ;; (-> any? boolean?) (define (graph? glst) (and (list? glst) (andmap (lambda (element) (match element ['(,(? symbol? src) ,(? symbol? dst)) #t] [else #f])) glst))) ;; Our implementation takes input graphs and turns them into | PageRanks. A PageRank is a Racket hash-map that maps pages (each nted as a Racket symbol) to their corresponding weights, ;; where those weights must sum to 1 (over the whole map). A PageRank encodes a discrete probability distribution over pages. ;; (-> any? boolean?) (define (pagerank? pr) (and (hash? pr) (andmap symbol? (hash-keys pr)) (andmap rational? (hash-values pr)) ;; All the values in the PageRank must sum to 1. I.e., the ;; PageRank forms a probability distribution. (= 1 (foldl + 0 (hash-values pr))))) ;; Takes some input graph and computes the number of pages in the ; graph. For example, the graph '((no n1) (n1 n2)) has 3 pages, no ;; ni, and n2. ;; (-> graph? nonnegative-integer?) (define (num-pages graph) ...) (provide graph? pagerank? num-pages num-links get-backlinks mk-initial-pagerank step-pagerank iterate-pagerank-until rank-pages) ;; This program accepts graphs as input. Graphs are represented as a ;; list of links, where each link is a list '(,src , dst) that signals ; ; page src links to page dst. ;; (-> any? boolean?) (define (graph? glst) (and (list? glst) (andmap (lambda (element) (match element ['(,(? symbol? src) ,(? symbol? dst)) #t] [else #f])) glst))) ;; Our implementation takes input graphs and turns them into | PageRanks. A PageRank is a Racket hash-map that maps pages (each nted as a Racket symbol) to their corresponding weights, ;; where those weights must sum to 1 (over the whole map). A PageRank encodes a discrete probability distribution over pages. ;; (-> any? boolean?) (define (pagerank? pr) (and (hash? pr) (andmap symbol? (hash-keys pr)) (andmap rational? (hash-values pr)) ;; All the values in the PageRank must sum to 1. I.e., the ;; PageRank forms a probability distribution. (= 1 (foldl + 0 (hash-values pr))))) ;; Takes some input graph and computes the number of pages in the ; graph. For example, the graph '((no n1) (n1 n2)) has 3 pages, no ;; ni, and n2. ;; (-> graph? nonnegative-integer?) (define (num-pages graph) ...)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started