0% found this document useful (0 votes)
6 views

Sets Worksheet1 Java Aplus

The document is a worksheet containing questions about Java collections, specifically focusing on legality of code snippets involving Collection, List, and Set interfaces. It also includes questions about the time complexity of TreeSet and HashSet, as well as expected outputs from various code examples. The worksheet is designed for students to demonstrate their understanding of these concepts.

Uploaded by

murtazaazm065
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Sets Worksheet1 Java Aplus

The document is a worksheet containing questions about Java collections, specifically focusing on legality of code snippets involving Collection, List, and Set interfaces. It also includes questions about the time complexity of TreeSet and HashSet, as well as expected outputs from various code examples. The worksheet is designed for students to demonstrate their understanding of these concepts.

Uploaded by

murtazaazm065
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

A+ Sets Worksheet 1

Answer each of the following questions. ( 100 points )

1. Is the following code [ legal / illegal ]? Collection c = new Collection();

2. Is the following code [ legal / illegal ]? Collection c = new List();

3. Is the following code [ legal / illegal ]? Collection c = new ArrayList();

4. Is the following code [ legal / illegal ]? List x = new Set();

5. Is the following code [ legal / illegal ]? List x = new TreeSet();

6. Is the following code [ legal / illegal ]? Collection x = new TreeSet();

7. What is the big0 for a TreeSet? [ O(log2N) / O(1) / O(N) ]

8. What is the big0 for a HashSet? [ O(log2N) / O(1) / O(N) ]

9. TreeSet can only store Objects that implement which interface? _____________________________

10. What is output by the code at right?


Set<Integer> s = new TreeSet<Integer>();
s.add(5);
s.add(6);
s.add(6);
s.add(7);
out.println(s);

11. What is output by the code at right?


Set<Integer> a = new TreeSet<Integer>();
a.add(9);
out.println(a.add(6));
out.println(a.add(6));
a.add(1);
out.println(a);

12. What is output by the code at right?


Set<String> b = new TreeSet<String>();
b.add("a");
b.add("6");
b.add("A");
b.add("d");
out.println(b);

© A+ Computer Science – Sets Worksheet - www.apluscompsci.com

You might also like