CompSci 100e: Program Design & Analysis II(Spring 2009) | ||
Problem: Family Trees Redux(from the Duke Internet Programming Contest)
For Compsci 100eYour program should read from a file chosen via a JFileChooser that allows you to navigate to a file and open it via a Scanner/BufferedReader. See previous programs from class that serve as a model. Your program should print its output using System.out.print statements (or println) which will appear in the Eclipse console window.This is worth 10 points.
BackgroundExpression trees, B and B* trees, red-black trees, quad trees, PQ trees; trees play a significant role in many domains of computer science. Sometimes the name of a problem may indicate that trees are used when they are not, as in the Artificial Intelligence planning problem traditionally called the Monkey and Bananas problem . Sometimes trees may be used in a problem whose name gives no indication that trees are involved, as in the Huffman code .This problem involves determining how pairs of people who may be part of a "family tree" are related.
The ProblemGiven a sequence of child-parent pairs, where a pair consists of the child's name followed by the (single) parent's name, and a list of query pairs also expressed as two names, you are to write a program to determine whether and how each of the query pairs is related. If the names comprising a query pair are related the program should determine what the relationship is. Consider academic advisees and advisors as exemplars of such a single parent genealogy (we assume a single advisor, i.e., no co-advisors).In this problem the child-parent pair p q denotes that p is the child of q . In determining relationships between names we use the following definitions:
The InputThe input consists of parent-child pairs of names, one pair per line. Each name in a pair consists of lower-case alphabetic characters or periods (used to separate first and last names, for example). Child names are separated from parent names by one or more spaces. Parent-child pairs are terminated by a pair whose first component is the string "no.child". Such a pair is NOT to be considered as a parent-child pair, but only as a delimiter to separate the parent-child pairs from the query pairs. There will be no circular relationships, i.e., no name p can be both an ancestor and a descendent of the same name q.A large sample data file can be used to check your solution. Here's the corresponding output. The parent-child pairs are followed by a sequence of query pairs in the same format as the parent-child pairs, i.e., each name in a query pair is a sequence of lower-case alphabetic characters and periods, and names are separated by one or more spaces. Query pairs are terminated by a pair whose first component is the string "no.child". There will be a maximum of 300 different names overall (parent-child and query pairs). All names will be fewer than 31 characters in length. There will be no more than 100 query pairs.
The OutputFor each query-pair p q of names the output should indicate the relationship p is-the-relative-of q by the appropriate string of the form
Sample Input alonzo.church oswald.veblen stephen.kleene alonzo.church dana.scott alonzo.church martin.davis alonzo.church pat.fischer hartley.rogers mike.paterson david.park dennis.ritchie pat.fischer hartley.rogers alonzo.church les.valiant mike.paterson bob.constable stephen.kleene david.park hartley.rogers no.child no.parent stephen.kleene bob.constable hartley.rogers stephen.kleene les.valiant alonzo.church les.valiant dennis.ritchie dennis.ritchie les.valiant pat.fischer michael.rabin no.child no.parent Sample Output parent sibling great great grand child 1 cousin removed 1 1 cousin removed 1 no relation SubmittingTo submit use the name extra, don't forget your README. |
||
| Last updated Fri May 08 16:08:14 EDT 2009 | ||