Sale!

# CSC 220.02+03 MIDTERM EXAM 02 solved

Original price was: \$35.00.Current price is: \$28.00.

Category:

5/5 - (1 vote)

## PART A – 50 Points

A.1 – 5 Points What does compareTo() possibly return when the method compares x vs. y? CSC 220.02+03 MIDTERM EXAM 02 SPRING 2021 TA 3 A.2 – 5 Points Among stack, queue, deque, and priority queue, which structure(s) does not accept null? Explain why? A.3 – 10 Points What is the output? And why? String x, y; char w; x = “ComputingQuantum”; y = “ComputingClassical”; System.out.println(y.compareTo(x));

Output: And why: TA 4 x = “QuantumComputing”; y = “QuantumKomputing”; System.out.println(x.compareTo(y)); Output: And why: x = “ClassicalComputing”; y = “ClassicalComputingX”; System.out.println(y.compareTo(x)); Output: And why: CSC 220.02+03 MIDTERM EXAM 02 SPRING 2021 TA 5 x = “ConventionalComputing”; y = “ConventionalComputinG”; System.out.println(x.compareTo(y)); Output: And why: x = “x” + “y”; w = ‘x’; System.out.println(x.compareTo(w)); Output: And why:

## A.4 – 10 Points

How does Selection Sort work? What are the steps? 9 7 5 8 1 7 4 3 2 Show the contents of the array above each time a Selection Sort changes it while sorting the array into ascending order.

A.5 – 10 Points How does Insertion Sort work? What are the steps? 9 1 8 7 6 5 2 3 4 Show the contents of the array above each time an Insertion Sort changes it while sorting the array into ascending order.

A.6 – 10 Points How does Shell Sort work? What are the steps? 9 6 8 7 5 1 3 2 4 5 Show the contents of the array above each time a Shell Sort changes it while sorting the array into ascending order.

## PART B – 50 Points

### B.1 – 10 Points

What is a queue? How does it work? Use an example and diagrams to explain its operations. Display the Queue at the marked lines. Queue q = new LinkedList<>(); for (int i = 3; i <= 8; i++) { q.add(i); } q.remove(q.size() – 1); // 1 q.offer(q.element() + 3); // 2 System.out.println(q.contains(9)); // 3 q.add(q.remove()); // 4 q.offer(q.peek()); // 5 FRONT 1. 2. 3. Output: 4. 5.

### B.2 – 10 Points

What is a deque? How does it work? Use an example and diagrams to explain its operations. Display the Deque at the marked lines. Deque d = new LinkedList<>(); d.add(“H”); d.addFirst(“O”); d.addLast(d.contains(“P”)); // 1 d.offer(d.element()); // 2 d.offerLast(d.remove()); // 3 d.offerFirst(d.remove(d.element())); // 4 d.push(d.remove(“E”)); // 5 FRONT 1. 2. 3. 4. 5.

### B.3 – 10 Points

What is a priority queue? How does it work? Use an example and diagrams to explain its operations. Display the Priority Queue at the marked lines. PriorityQueue pq = new PriorityQueue<>(); pq.offer(“C”); pq.add(“O”); pq.offer(“M”); pq.add(“P”); pq.offer(String.valueOf(pq.remove(pq.peek()))); // 1 pq.add(String.valueOf(pq.contains(“X”))); // 2 pq.add(String.valueOf(pq.contains(pq.remove()))); // 3 pq.offer(pq.remove()); // 4 pq.add(pq.peek()); // 5 FRONT 1. 2. 3. 4. 5.

### B.4 – 10 Points

What is a list? How does it work? Use an example and diagrams to explain its operations. Display the List at the marked lines. LinkedList li = new LinkedList(); for (int i = 3; i <= 8; i++) { li.add(i); } li.remove(li.get(2)); li.set(4,li.peekLast()); li.add(li.size()+1); // 1 li.addFirst(li.get(li.size()-2)); // 2 Collections.sort(li); // 3 li.add(li.indexOf(3)); // 4 li.addFirst(li.peekFirst()); // 5 FRONT 1. 2. 3. 4. 5.

### B.5 – 5 Points

Given a queue q of Integer elements, please write code to check if the elements are: – Not Sorted – Sorted in Ascending Order – Sorted in Descending Order

### B.6 – 5 Points

Given 2 lists of comparable String elements and of different lengths, please write code to output: – “The tail of A is the reverse of B.” if listA: x, y, z, f, a, b, d, A, B, C, D, E, F listB: F, E, D, C, B, A – “The tail of A is NOT the reverse of B.” if not