Java Programing: Compare times per single search between HashSet and TreeSet col
ID: 640340 • Letter: J
Question
Java Programing:
Compare times per single search between HashSet and TreeSet collections.
Select and store words from 2 books by the same author in 2 separate sets (use www.gutenberg.org). Use one of these sets to search word-by-word in the other set. Measure time per each search. Show results from this experiment along with your conclusion. Also submit code.
Use these two books by Charles Dickens:
https://www.gutenberg.org/files/24022/24022-0.txt
https://www.gutenberg.org/cache/epub/1400/pg1400.txt
Explanation / Answer
HashSet is much faster than TreeSet (constant-time versus log-time for most operations like add, remove and contains) but offers no ordering guarantees like TreeSet.
HashSet:
TreeSet:
Important points:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.