(define (acyclic? graph) (if (null? graph) #t (let ((sink (find-sink graph))) (if sink (acyclic? (remove-sink (first sink) graph)) #f)))) (define (find-sink graph) (if (null? graph) #f (if (sink? (first graph)) (first graph) (find-sink (rest graph))))) (define (sink? node) (null? (rest node))) (define (remove-sink sink graph) (if (null? graph) () (let ((node (first graph))) (if (equal? sink (first node)) (remove-sink sink (rest graph)) (cons (cons (first node) (expunge sink (rest node))) (remove-sink sink (rest graph))))))) (define (expunge sink nodes) (if (null? nodes) () (if (equal? sink (first nodes)) (expunge sink (rest nodes)) (cons (first nodes) (expunge sink (rest nodes)))))) (define g1 '((a b c) (b c e) (c) (d a c) (e d))) (define g2 '((a b c) (b c) (c) (d a c))) (define (expunge2 sink nodes) (drop (lambda (node) (equal? node sink)) nodes))