Tree is sorted according to age of Person... user will enter name And I have to tell persons age... so for name search I have to do O(n) then let;s say I found 4 people with same name... then compare between them >.. Is there a way to optimize this ??
yes, try override the compareTo() method:
I'll think about it tomorrow, I'm almost sleeping. But two quick thoughts: - check the idea of hash map in jdk 8+, how list/array in a bucket becomes a tree when threshold is reached - what if you implement compareTo to use combined name+age value, that way that ["tolstoy",32] > ["tolstoy",23] and build tree based on that comparator. Like using special type of hashes like in image searching
+ check how composite insides in databases work
Обсуждают сегодня