Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Practice Competition Problem Help  RSS feed

Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on a practice competition problem, and having trouble determining what data structure I should use, and how I go about starting this problem. Initially I thought about using a HashMap, but that didn't work out very well. Here is the problem description:

You have been given bits and pieces of your family tree. Your task is to determine if two people are related based on several connections.


The first line will contain a single integer n that indicates the number of connections. The next n lines will consist of a name, a connection, and another name. The connections will be either mom, dad, brother, sister, daughter or son. The next line will contain a single integer m that indicates the number of test cases. The next m lines will consist of two names.

Your program should determine if the two names are related


Ouput either Related or Not Related, depending on whether they are connected or not. There will be m lines of output.


John brother Susan
Kim mom John
Dave son Jim
Jim John
Kim Susan

Example output to screen:
Not related

An approach on how to solve this would greatly be appreciated!

Posts: 62194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you start by drawing some family trees by hand, and seeing how the different relationships can be depicted. Tha will allow you to model relationships like “brother” or “daughter”.
If you settle for what they are giving you, you deserve what you get. Fight for this tiny ad!
Programmatically Create PDF Using Free Spire.PDF with Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!