java - Matching data in 2 different linked lists -
so have program supposed match babysitters people based on inputted info. info both parties saved in linked lists. is possible match data babysitter linked-list parent linked-list? , make output "__ possible matched you"
if not have data, simple inefficient way of solving problem is:
boolean matches(person person, babysitter babysitter) { // implement logic returns whether babysitter , person match return person.getnumberofchildren() <= babysitter.getmaximumnumberofchildren() && babysitter.getworkingdays().containsall(person.needsbabysitterfordays()); } (person person: people) { (babysitter babysitter: babysitters) { if (matches(person, babysitter)) { system.out.println("babysitter " + babysitter + " recommended " + person); } } }
the above algorithm takes o(b * p) time b = number of babysitters, p = number of people. large b , p, slow.
based on logic of matches
achieve solution close o(b + p) reverse index. if have 10.000 babysitters , 10.000 people optimized solution run pretty while above algorithm take couple of seconds.
Comments
Post a Comment