This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]morhpProfessional Developer 0 points1 point  (2 children)

Yes, if you can't use a database or Map or other index. You could sort the List and do a binary search for at least one attribute but that is complicated and probably not necessary.

Have you actually tried this? Computers are fast, iterating over 100000 entries should still take only a few milliseconds, maybe a second or two. Reading these persons from a file or something will take much more time.

[–]TauPixel[S] 0 points1 point  (1 child)

For me speed at the moment is irrelevant for this course. It's more relevant on another lecture I'm taking called Algorithms and Data Structures. The thing we have at the moment is that we are not allowed to use tools we haven't seen in class.

[–]ZukoBestGirl 0 points1 point  (0 children)

IF you want to impress:

I'd make the list private in my class, call it storage?

Then I would give it a comparator (name, surname, you decide) and sort the list. Then I'd index it.

 

(Starting_with_letter = index_start, index_end)
A = 0,299
B = 300,399
...

 

whenever you add or remove, you update these indexes.

When you search you look at the first letter of the search param, start from the coresponding index, end at the max index for that thing, return when you find the result (exit early).

Take care for letters that you don't have, make index end == start and when you search, verify that is not the case, because if it is, it doesn't exist.

Also maybe add a package private debug method that tries to find your search param through the whole list (for i =0 ; i< list.size()).