Like other organisations, here also some Family tree related problem was given.
The candidate must try to implement below solutions with algorithms of O(n) time complexity (linear )
Q1: Implement a test class to inject and create the family structure one node at a time. The structure should at least
have five levels ( great grant parents, grand parent, parent, and kids, grand-kids).
- Make the tree unbalanced. Try to have a good distribution of the number of kids for a pair of parents (i.e. some
with no kids, some with 2 kids, some with 3, or 4….).
The injection time complexity should be O(n). i.e. one logical search to find the place to enter a family node.
Q2: Implement an algorithm with possibly O(n) complexity to sort the whole family tree in age descending order.
Q3: Can you think of an algorithm that can insert a new family member ( assume we found a long missing member!) in
to the correct place of a sorted (ascending) list based on age, where the algorithm’s time complexity is better than
O(n)?. pseudo code or actual implementation is fine.
I had shared the code on my gitub address & got to know that candidates were submitting the same code to clear the round.
The candidate must try to implement below solutions with algorithms of O(n) time complexity (linear )
Q1: Implement a test class to inject and create the family structure one node at a time. The structure should at least
have five levels ( great grant parents, grand parent, parent, and kids, grand-kids).
- Make the tree unbalanced. Try to have a good distribution of the number of kids for a pair of parents (i.e. some
with no kids, some with 2 kids, some with 3, or 4….).
The injection time complexity should be O(n). i.e. one logical search to find the place to enter a family node.
Q2: Implement an algorithm with possibly O(n) complexity to sort the whole family tree in age descending order.
Q3: Can you think of an algorithm that can insert a new family member ( assume we found a long missing member!) in
to the correct place of a sorted (ascending) list based on age, where the algorithm’s time complexity is better than
O(n)?. pseudo code or actual implementation is fine.
I had shared the code on my gitub address & got to know that candidates were submitting the same code to clear the round.