1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
|
/// Write a predicate ms_tree(Graph,Tree,Sum) to construct the minimal spanning tree of a given labelled
/// graph. Hint: Use the algorithm of Prim. A small modification of the solution of P83 does the trick. The data of
/// the example graph to the right can be found in the file p84.dat.
///
/// Example:
///
/// <example in lisp>
///
/// Example in F#:
/// > let graphW = [('a',['b'; 'd';]); ('b',['a';'c';'d';'e';]); ('c',['b';'e';]); ('d',['a';'b';'e';'f';]);
/// ('e',['b';'c';'d';'f';'g';]); ('f',['d';'e';'g';]); ('g',['e';'f';]); ];;
/// > let gwF =
/// let weigthMap = Map [(('a','b'), 7);(('a','d'), 5);(('b','a'), 7);(('b','c'), 8);(('b','d'), 9);
/// (('b','e'), 7);(('c','b'), 8);(('c','e'), 5);(('d','a'), 5);(('d','b'), 9);
/// (('d','e'), 15);(('d','f'), 6);(('e','b'), 7);(('e','c'), 5);(('e','d'), 15);
/// (('e','f'), 8);(('e','g'), 9);(('f','d'), 6);(('f','e'), 8);(('f','g'), 11);
/// (('g','e'), 9);(('g','f'), 11);]
/// fun (a,b) -> weigthMap.[(a,b)];;
///
/// val graphW : (char * char list) list =
/// [('a', ['b'; 'd']); ('b', ['a'; 'c'; 'd'; 'e']); ('c', ['b'; 'e']);
/// ('d', ['a'; 'b'; 'e'; 'f']); ('e', ['b'; 'c'; 'd'; 'f'; 'g']);
/// ('f', ['d'; 'e'; 'g']); ('g', ['e'; 'f'])]
/// val gwF : (char * char -> int)
///
/// > prim gw gwF;;
/// val it : char Graph =
/// (['a'; 'd'; 'f'; 'b'; 'e'; 'c'; 'g'],
/// [('a', 'd'); ('d', 'f'); ('a', 'b'); ('b', 'e'); ('e', 'c'); ('e', 'g')])
///
(Solution)
|