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 in the method extractNamesAlternative in

Couldn’t implement binary search on linked list

i am a cse student who takes data structures course. Trying to implement binary search algorithm to my SinglyLinkedList class, somehow i’ve failed. Could you check it what’s wrong please ? The related method; I’ve debugged and it just enters the loops this side: else if(temp.getElement() > target) All class for better understanding; And the main method; It returns; Answer