Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 4 out of 49 pages
Exam (elaborations)

C212 WRITTEN TEST UPDATED ACTUAL QUESTIONS AND CORRECT ANSWERS

Document preview thumbnail
Preview 4 out of 49 pages

C212 WRITTEN TEST UPDATED ACTUAL QUESTIONS AND CORRECT ANSWERS

Content preview

C212 WRITTEN TEST UPDATED ACTUAL
QUESTIONS AND CORRECT ANSWERS

⩥ Define: list.
Answer: A list is a collection that remembers the order of
elements.


⩥ Define: set.
Answer: A set is an unordered collection of unique elements.


⩥ Define: map.
Answer: A maps keeps associations between key and value
objects.


⩥ Define: linked list..
Answer: Data structure used for collecting a sequence of objects
that allows efficient addition and removal of elements in the
middle of the sequence.


⩥ Define: list iterator..

,Answer: An iterator encapsulates a position anywhere inside the
linked list.


⩥ Do linked lists take more storage space than arrays of the
same size? Explain..
Answer: Yes, for two reasons. A linked list needs to store the
neighboring node references, which are not needed in an array.
Moreover, there is some overhead for storing an object. In a
linked list, each node is a separate object that incurs this
overhead, whereas an array is a single object.


⩥ Why don't we need iterators with arrays?.
Answer: We can simply access each array element with an
integer index.


⩥ Consider the types HashSet and TreeSet. Do they have
anything in common?.
Answer: They both implement the Set interface. Set
implementations arrange the elements so that they can locate
them quickly.


⩥ Write a loop that removes all strings with length less than four
from a linked list of strings called words..

,Answer: ListIterator<String> iter = words.iterator();
while(iter.hasNext()){
String str = iter.next();
if(str.length() < 4) { iter.remove(); }
}


⩥ Write a loop that prints every second element of a linked list
of strings called words. (Answer)..
Answer: ListIterator<String> iter = words.iterator();
int count = 0;
while(iter.hasNext()){
count++;
if (count %. 2 == 0){
System.out.println(iter.next());
}
}


⩥ Can you add an element to a set at an iterator position?
Explain why or why not..

, Answer: It makes no sense to add an element at a particular
position in a set, because the set can order the elements any way
it likes.


⩥ Arrays and lists remember the order in which you added
elements, sets do not. Why would you want to use a set instead
of an array or list?.
Answer: Adding and removing elements as well as testing for
membership is more efficient with sets.


⩥ Why are set iterators different from list iterators?.
Answer: You do not know, nor can you control, in which order
the set keeps the elements.


⩥ Write a loop that prints all elements that are in both
Set<String> s and Set<String> t..
Answer: for (String str : s){
if(t.contains(str)){
System.out.println(str);
}
}

Document information

Uploaded on
June 9, 2026
Number of pages
49
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers
$13.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
TopGradeInsider
4.1
(9)
Sold
130
Followers
2
Items
46228
Last sold
1 day ago


Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions