This assignment is for extra credit only.
Start with a set of numbers 1 .. n.
Initially, each number is distinct from all the others.
There are two operations: merge and query.
Merging two numbers means making them indistinct from each other, that is,
placing them in the same "group".
Querying two numbers means answering the yes/no question: Are these two numbers
in the same group?
For instance, consider this sequence of operations:
merge(1,2). merge(4,5). query(1,2). % returns yes query(1,4). % returns no merge(2,5). query(1,5). % returns yes query(1,3). % returns no query(1,4). % returns yesThere is a standard algorithm and data structure for this problem, known as the Union-Find algorithm. However, you may use brute-force search.
Write a Prolog program that implements merge and query. The
merge operations
can be represented by a file of facts in the form shown above. You can cause
this file to be read in by giving the input
['filename'] .You must implement
query as a Prolog predicate.
Turn in your program and your own test data in the usual way.
Also run your program the class test data in
http://www.cs.uky.edu/~raphael/courses/CS450/asg.prolog.data.
assert.