Starting at the very beginning, you could pick up some material on graph
theory, and work through it, while making use of the graph library.

E.g. Here's an introduction to the absolute basics of Graph Theory:

https://www.youtube.com/watch?v=HmQR8Xy9DeM


And here I've followed along in Racket, figuring out parts of the library
as I go:

#lang racket

(require graph
         math/matrix)

; Define a simple graph
(define g (unweighted-graph/undirected
           '((v1 v2) (v1 v3) (v1 v4) (v4 v5) (v5 v6))))


; How many vertices are in the graph?
(define (cardinality g)
  (length (get-vertices g)))

(cardinality g)


; How many neighbors does vertex v have?
(define (degree g v)
  (length (get-neighbors g v)))

(degree g 'v1)


; Compute the adjacency list
(define (adjacency-list g)
  (for/list ([v (in-vertices g)])
    (list v
          (for/list ([ n (in-neighbors g v)])
            n))))

(adjacency-list g)


; Compute the adjacency matrix
(define (adjacency-matrix g)
  (define card-g (cardinality g))
  (define vertices (for/list ([v (in-vertices g)]) v))
  (build-matrix card-g card-g
                (λ (u v)
                  (if (has-edge? g (list-ref vertices u) (list-ref vertices
v))
                      1 0))))

(adjacency-matrix g)


; Is the graph actually a tree?
(define (is-tree? g)
  (= (length (get-edges g))            ; Counts edges twice (in both
directions)
     (* 2 (length (mst-kruskal g)))))

(is-tree? g)

(define loop (unweighted-graph/undirected '((a b) (a c) (b c))))
(is-tree? loop)


; Visualize the tree
(displayln (graphviz g))

; Paste output into www.webgraphviz.com to make an image


I hope that's enough to get you started

Dan

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to