Final Flashcards

(58 cards)

1
Q

The classes that implement the _______ interface are all indexed collections

A

List

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Set objects:

A

are not indexed do not reveal the order of insertion of items

Denable efficient search and retrieval of information

allow removal of elements without moving other elements around

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Relative to a Set, Map objects provide efficient _____ and ______ of entries that contain pairs of objects (a unique key and the information)

A

search

retrieval

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Hash tables (used to implement a Map or Set ) store objects at arbitrary locations and offer an average constant time for ______,_______,_______.

A

insertion, removal, and searching

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

is a collection that contains no duplicate elements and at most one null element

A

A set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Required methods for set interface and methods:

A

testing set ,
testing for an empty set,
determining set size,
creating an iterator over the set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Additional methods for adding an element and removing an element (the add method does not allow _________________ ).

A

duplicate items to be inserted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Constructors that enforce the “________________” rule

A

no duplicate members

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Required method: __________ tests the subset relationship

A

containsAll

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Union:
Intersection:
Difference:

A

addAll
retainAll
removeAll

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Unlike the List.add method, the Set.add method returns false if you attempt to:

A

insert a duplicate item

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Unlike a List, a Set does not have a ____ method elements cannot be accessed by index

A

get

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

You can iterate through all elements in a Set using an __________ object, but the elements will be accessed in arbitrary order

A

Iterator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Returns an iterator over the elements in this set.

A

iterator()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Collections implementing the ____ interface must contain unique elements

A

Set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Unlike the ______ method, the _____ method returns _____ if you attempt to insert a duplicate item

A

List.add. Set.add. false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Unlike a _____, a_____ does not have a ____ method-elements cannot be accessed by index

A

List. Set. get

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

You can iterate through all elements in a _____ using an ________ object , but the elements will be accessed in arbitrary order

A

Set. Iterator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

The Map is related to the

A

Set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Mathematically , a _____ is a set of ordered pairs whose elements are known as the key and the value

A

Map

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

The collection of all keys is known as the

A

keySet

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

The collection of all values is known as the

A

valueSet

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

All the elements of ________ have a corresponding member in key Set

A

valueSet

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

The goal of hash table is to

A

be able to access an entry based on its key value, not its location

25
Using a hash table enables us to find elements
as quickly as possible
26
The basis of hashing is to transform the item's key value into an _________________ which is then transformed into a table index
integer value (its hash code)
27
The hash function calculation is simply:
int index = asciiChar;
28
If you assume that on average 100 characters were used, you could use a table of 200 characters and compute the index by :
int index = uniChar % 200
29
If two hashcodes are the same indices this is called
A collision
30
To resolve collisions, ___________ can be used to store or access an item in a hash table
linear probing
31
another way of solving collisions:
Chaining
32
What is the calculations for load factor?
Load factor = number of filled cells / table size
33
What does load factor percentage tell us?
Performance
34
With load factor the lower it is the
better there performance as there is a smaller chance of collision
35
In hash tables, If there are no collisions, items can
be added or retrieved without searching, regardless of table size
36
With a hash table you cannot
traverse a hash table in a meaningful way since the sequence of stored values is arbitrary
37
Unlike lists, trees are ________ and | ___________
nonlinear hierarchical
38
Trees can represent hierarchical organizations of information:
class hierarchy disk directory and subdirectories
39
Trees can be defined and processed ___________
recursively
40
A binary tree consists of a collection of elements or nodes , with each node linked to _____________ successors
at most two
41
What is the root of a tree hierarchy?
The node at the top of the tree
42
The successors of a tree node called it’s
children
43
Each node in a tree has exactly _____ parent except for the root node which has no parent
one
44
node that has no children is called a
Leaf node
45
In recursive fashion, the child of a node is considered the root of a ________ of that node
subtree
46
Three common kinds of tree traversal
Inorder Preorder Postorder
47
In a preorder traversal the first node we visit is always
The root
48
In a postorder traversal the last node we visit is always
The root
49
In a binary search tree, all elements in the left subtree _________ those in the right subtree
Precede
50
A binary search tree is an "________" tree, which never has to be sorted because its elements always satisfy the "________" requirement
ordered
51
When new elements are inserted (or removed) properly, the binary search tree _________ its property
maintains
52
The TreeSet class implements the Set interface by storing elements in a
balanced Binary Search Tree
53
As elements are added to / removed from the TreeSet, the class may __________ nodes so that the tree remains balanced
rearrange
54
A class of objects added to a ________ must provide a way to "compare" objects
TreeSet
55
Given an object to be added to a TreeSet or TreeMap , we must be able to determine if the new object is
* Equal to the object at the root * Less than the object at the root * Greater than the object at the root Therefore, the objects must be comparable
56
Classes (such as String) that implement the Comparable interface must define a ___________ method
compareTo
57
Method obji.compareTo (obj2) returns an integer with the following values
Negative if obj1 < obj2 Zero obj1=obj2 Positive if obj1>obj2
58
Implementing the __________ interface provides a way to compare objects during a search
Comparable