Skip to content

Tag: data-structures

Method to get all the branches of a tree

I have an object from this Class: And I would like to write the JAVA method: private List<List> extractNames(Person ancestor) which gives back all the names of each branch of the tree: Do you have an idea, how I could do it ? Answer Update: Removed the dependency to lombok The relevant algorithm part is…

Checking a tree to be a BST

Here is my attempt to check whether a tree is a BST or not: Code works fine as tested with multiple test cases. But I am not sure if this is a good, clean approach. Recursive method is big it seems. I am dealing with scenarios like null left node, null right node, node itself null, both child nodes null

Java – HashMap for booking system

I have been given an exercise to develop an appropriate data structure to implement a tennis court booking system. A hashmap is what is required for this and I was given a diagram as a visual representation of the data structure. From looking at the diagram, I am unclear on how the Key and Value should be def…