CS121 FINAL QUESTIONS AND CORRECT ANSWERS
A nonlinear collection in which there is essentially no inherent organization to the
elements in the collect - Answers - Set
The difference between a set and map is that a set stores the key and the data _____
while a map separates the key from the data and only stores the key and a reference to
the data - Answers - Together
Which data structure does not keep its elements in any type of order - Answers - set
What happens when we try to add an element to a set in which the element is already
present - Answers - it is not added
Which data structures can be used to implement a set from Java API - Answers -
Hashtable and balanced binary tree
To use a treeset, your objects must belong to a class that implements the ____
interface - Answers - Comparable
Which java code is not correct - Answers - hashset<String> cats = new
treeset<String>();
In our lab 13, a set was implemented by using a linked node (list), then what complexity
would testing for containment have? - Answers - O(n)
Do not use PC. What is the correct answer on the console window?
Set<String> myset1 = new treeset<String>();
Myset1.add("X");
Myset1.add("Y");
Myset1.add("X");
Myset1.add("Z");
Set<String> myset2 = new treeset<String>();
Myset2.add("Y");
, Myset2.add("Z");
Myset2.add("W");
Myset2.add("Y");
Set<String> set3 = new treeset<String>(myset1);
Set3.retainall(myset2);
System.out.println(set3); - Answers - [Y, Z]
Do not use PC. What is the correct answer on the console window?
Set<String> myset1 = new treeset<String>();
Myset1.add("X");
Myset1.add("Y");
Myset1.add("X");
Myset1.add("Z");
Set<String> myset2 = new treeset<String>();
Myset2.add("Y");
Myset2.add("Z");
Myset2.add("W");
Myset2.add("Y");
Set<String> set3 = new treeset<String>(myset1);
Set3.removeall(myset2);
System.out.println(set3); - Answers - [X]
Do not use PC. What is the correct answer on the console window?
Set<String> myset1 = new hashset<String>();
Myset1.add("X");
A nonlinear collection in which there is essentially no inherent organization to the
elements in the collect - Answers - Set
The difference between a set and map is that a set stores the key and the data _____
while a map separates the key from the data and only stores the key and a reference to
the data - Answers - Together
Which data structure does not keep its elements in any type of order - Answers - set
What happens when we try to add an element to a set in which the element is already
present - Answers - it is not added
Which data structures can be used to implement a set from Java API - Answers -
Hashtable and balanced binary tree
To use a treeset, your objects must belong to a class that implements the ____
interface - Answers - Comparable
Which java code is not correct - Answers - hashset<String> cats = new
treeset<String>();
In our lab 13, a set was implemented by using a linked node (list), then what complexity
would testing for containment have? - Answers - O(n)
Do not use PC. What is the correct answer on the console window?
Set<String> myset1 = new treeset<String>();
Myset1.add("X");
Myset1.add("Y");
Myset1.add("X");
Myset1.add("Z");
Set<String> myset2 = new treeset<String>();
Myset2.add("Y");
, Myset2.add("Z");
Myset2.add("W");
Myset2.add("Y");
Set<String> set3 = new treeset<String>(myset1);
Set3.retainall(myset2);
System.out.println(set3); - Answers - [Y, Z]
Do not use PC. What is the correct answer on the console window?
Set<String> myset1 = new treeset<String>();
Myset1.add("X");
Myset1.add("Y");
Myset1.add("X");
Myset1.add("Z");
Set<String> myset2 = new treeset<String>();
Myset2.add("Y");
Myset2.add("Z");
Myset2.add("W");
Myset2.add("Y");
Set<String> set3 = new treeset<String>(myset1);
Set3.removeall(myset2);
System.out.println(set3); - Answers - [X]
Do not use PC. What is the correct answer on the console window?
Set<String> myset1 = new hashset<String>();
Myset1.add("X");