Question: undefined Task A: Siblings (5 Marks) Implement a function siblings(person, family) with the following specification. Input: A string containing a persons name, person, and a
undefined
Task A: Siblings (5 Marks) Implement a function siblings(person, family) with the following specification. Input: A string containing a persons name, person, and a family tree database family as specified above. Output: A list containing the names of all siblings, both half and full, of person that are stored in the database. Your function implementation must have a worst-case time complexity of O(n log n), where n is the size of the input database. For example: >>> duck_tree = [[Donald Duck,Quackmore Duck,Hortense McDuck], ... [Della Duck, Quackmore Duck, Hortense McDuck], ... [Hortense McDuck, Fergus McDuck, Downy ODrake], ... [Scrooge McDuck, None, Downy ODrake], ... [Fergus McDuck, Dingus McDuck, Molly Mallard], ... [Huey Duck, None, Della Duck], ... [Dewey Duck, None, Della Duck], ... [Louie Duck, None, Della Duck]] >>> siblings(Della Duck, duck_tree) [Donald Duck] >>> sorted(siblings(Louie Duck, duck_tree)) [Dewey Duck, Huey Duck] >>> siblings(Scrooge McDuck, duck_tree) [Hortense McDuck] >>> siblings(Fergus McDuck, duck_tree) [] >>> siblings(Daisy Duck, duck_tree) []
Part 2: Sibling Search and Combining Trees (12%, due in Week 11) In this part of the assignment, you will write a function for returning more complex relationship information, and a function that takes two potentially overlapping family trees and combines the information into a single database. Task A: Siblings (5 Marks) Implement a function siblings (person, family) with the following specification. Input: A string containing a person's name, person, and a family tree database family as specified above. Output: A list containing the names of all siblings, both half and full of person that are stored in the database. Your function implementation must have a worst-case time complexity of O(n logn), where n is the size of the input database. For example: >>> duck_tree = [['Donald Duck', 'Quackmore Duck', 'Hortense McDuck'], ['Della Duck', 'Quackmore Duck', 'Hortense McDuck'), ['Hortense McDuck', 'Fergus McDuck', 'Downy ODrake'], ['Scrooge McDuck', None, 'Downy ODrake'], ['Fergus McDuck', 'Dingus McDuck', 'Molly Mallard'], ['Huey Duck', None, 'Della Duck'), ['Dewey Duck', None, 'Della Duck'), ['Louie Duck', None, 'Della Duck']] >>> siblings ('Della Duck', duck_tree) ['Donald Duck'] >>> sorted (siblings ('Louie Duck', duck_tree)) ['Dewey Duck', 'Huey Duck'] >>> siblings('Scrooge McDuck', duck_tree) ['Hortense McDuck'] >>> siblings('Fergus McDuck', duck_tree) [] >>> siblings ( 'Daisy Duck', duck_tree) [] # Part 2: (due Week 11) # def siblings (person, family): Input: A person's name (person) and a family tree database (family) as specified above. Output: A list containing the names of all siblings, both half and full, of person that are stored in the database. For example: >>> duck_tree = [['Donald Duck', 'Quackmore Duck', 'Hortense McDuck'], ['Della Duck', 'Quackmore Duck', 'Hortense McDuck'], ['Hortense McDuck', 'Fergus McDuck', 'Downy ODrake'], ['Scrooge McDuck', None, 'Downy ODrake'], ['Fergus McDuck', 'Dingus McDuck', 'Molly Mallard'], ['Huey Duck', None, Della Duck'], [ 'Dewey Duck', None, 'Della Duck'], ['Louie Duck', None, Della Duck']] >>> siblings ('Della Duck', duck_tree) ['Donald Duck'] >>> sorted (siblings ('Louie Duck', duck_tree)) ['Dewey Duck', 'Huey Duck'] >>> siblings('Scrooge McDuck', duck_tree) ['Hortense McDuck'] >>> siblings ('Fergus McDuck', duck_tree) [] >>> siblings ('Daisy Duck', duck_tree) []
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
