• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 3 out of 20 pages
Exam (elaborations)

C212 Correct Final Exams Questions And Answers Sure A.pdf

Document preview thumbnail
Preview 3 out of 20 pages

C212 CORRECT FINAL EXAMS QUESTIONS AND ANSWERS SURE A.pdf

Content preview

C212 CORRECT FINAL EXAMS QUESTIONS AND
ANSWERS SURE A+
✔✔11. Why are set iterators different from list iterators - ✔✔Sets do not have an
ordering, so it doesn't make sense to add an element at a particular iterator position, or
to traverse a set backwards.

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

✔✔13. How do you find all keys and values in a map - ✔✔iterate through the key set
and find the values that correspond to the keys

✔✔14. Consider the types HashMap and TreeMap. What do they have in common -
✔✔they both implement the Map interface

✔✔15. What is the difference between a set and a map - ✔✔A set stores elements. A
map stores associations between keys and values.

,✔✔16. Why is the collection of the keys of a map a set and not a list - ✔✔The ordering
does not matter, and you cannot have duplicates.

✔✔17. Why is the collection of the values of a map not a set - ✔✔Because it might have
duplicates.

✔✔18. Suppose you want to track how many times each word occurs in a document.
Declare a suitable map variable. - ✔✔Map<String, Integer> wordFrequency;
(note: you can not use a Map<String, int> because you can not use primitive types as
type parameters in Java.

✔✔19. What is a Map<String, HashSet<String>> (Give a possible use for such a
structure) - ✔✔It associates strings with sets of strings. One application would be a
thesaurus that lists synonyms for a given word.

✔✔20. What is a hash function? What is a good hash function? - ✔✔A hash function
computes an integer value from an object. A good hash function minimizes collisions -
identical hash codes for different objects.

✔✔Define: stack - ✔✔a collection of elements with "last-in", "first-out" retrieval.

✔✔Define: queue - ✔✔a collection of elements with "first-in", "first-out" retrieval.

✔✔Define: priority queue - ✔✔unlike a regular queue, the priority queue does not
maintain a first-in, first-out discipline. Instead, elements are retrieved according to their
priority. Whenever an item is removed, it is the item with the most urgent priority.

✔✔22. Why would you want to declare a variable as Queue<String> q = new
LinkedList<>() instead of simply declaring it as a linked list - ✔✔This way, we can
ensure that only queue operations can be can be invoked on the q object.

✔✔23. Why wouldn't you want to use an array list for implementing a queue -
✔✔Depending on whether you consider the 0 position the head or the tail of the queue,
you would either either add or remove elements at that position. Both are inefficient
operations because all other elements need to be moved.

✔✔24. Why wouldn't you want to use a stack to manage print jobs - ✔✔Stacks use a
"last-in" "first-out" discipline. If you are the first one to submit a print job and lots of
people add print jobs before the printer has a chance to deal with your job, they get their
printouts first, and you have to wait until all other jobs are completed.

✔✔25. What does this code print?

Queue<String> q = new LinkedList<>();

, q.add("A");
q.add("B");
q.add("C");
while (q.size() > 0) { System.out.print (q.remove() + " " ); } - ✔✔A B C

✔✔26. What is the value of the reverse Polish notation expression 2 3 4 + 5 * * -
✔✔Stack Unread expression
Empty 2 3 4 + 5 * *
234+5**
234+5**
234+5**
275**
275**
2 35 *
70

✔✔27. What steps does the selection sort algorithm go through to sort the sequence 6
5 4 3 2 1 - ✔✔1 | 5 4 3 2 6
12|4356
123456

✔✔28. Define: selection sort algorithm - ✔✔The selection sort algorithm sorts an array
by repeatedly finding the smallest element of the unsorted tail region and moving it to
the front.

✔✔29. Define: big-Oh notation - ✔✔big-Oh notation describes the growth rate of a
function

✔✔30. Selection sort is an O(n2) algorithm. What does that mean - ✔✔Doubling the
data set means a fourfold increase in the processing time.

✔✔31. How large does n need to be so that ½ * n^2 is bigger than 5/2 * n - 3 - ✔✔If n is
4, then ½ n^2 is 8 and 5/2 n - 3 is 7.

✔✔32. Define: merge sort algorithm - ✔✔The merge sort algorithm sorts an array by
cutting the array in half, recursively sorting each half, and then merging the sorted
halves.

✔✔33. Manually run the merge sort algorithm on the array
8 7 6 5 4 3 2 1. - ✔✔First sort 8 7 6 5:
Recursively, first sort 8. It's sorted.
Sort 7. It's sorted.
Merge them: 7 8
Do the same with 6 5 to get 5 6.
Merge them to get 5 6 7 8.

Document information

Uploaded on
July 14, 2026
Number of pages
20
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers
$17.49

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.
BOARDWALKer
3.4
(19)
Sold
162
Followers
6
Items
26749
Last sold
16 hours 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