Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Array vs ArrayList. What is the difference? 2) Suppose you have a Hashmap. Th

ID: 3749349 • Letter: 1

Question

1) Array vs ArrayList. What is the difference?
2) Suppose you have a Hashmap. There is a list of word and definition in it. The key of the hashmap is "word" and the value is that word's definition. Suppose you want to search for a particular word in that hashmap. Describe the algorithm how you would do it. What are the best case scenario and a worst case scenario for this case?
3) If I want to make a record of 1000 records and I want a mechanism to do the quick search, what should I use - Array or a list?

Explanation / Answer

Answer 1:
Arrays are fixed in sized, where as in ArrayList are growable in sized
both can store hetrogenious elements
Answer 2:
calculate the hash of the word and find the bucket number , if bucket has more than one element than please compare with the key and return the content
Best case Time complexity O(1) where bucket has single word defination
worst case Time complexity O(n) where bucket has more than 1 word
Answer 3: as you know the size in advance you can use the arrays
both has same access speed