Final Flashcards

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
Q

Using a hash table enables us to find elements

A

as quickly as possible

26
Q

The basis of hashing is to transform the item’s key value into an _________________ which is then transformed into a table index

A

integer value (its hash code)

27
Q

The hash function calculation is simply:

A

int index = asciiChar;

28
Q

If you assume that on average 100 characters were used, you could use a table of 200 characters and compute the index by :

A

int index = uniChar % 200

29
Q

If two hashcodes are the same indices this is called

A

A collision

30
Q

To resolve collisions, ___________ can be used to store or access an item in a hash table

A

linear probing

31
Q

another way of solving collisions:

A

Chaining

32
Q

What is the calculations for load factor?

A

Load factor = number of filled cells / table size

33
Q

What does load factor percentage tell us?

A

Performance

34
Q

With load factor the lower it is the

A

better there performance as there is a smaller chance of collision

35
Q

In hash tables, If there are no collisions, items can

A

be added or retrieved without searching, regardless of table size

36
Q

With a hash table you cannot

A

traverse a hash table in a meaningful way since the sequence of stored values is arbitrary

37
Q

Unlike lists, trees are ________ and

___________

A

nonlinear

hierarchical

38
Q

Trees can represent hierarchical organizations of information:

A

class hierarchy disk directory and subdirectories

39
Q

Trees can be defined and processed ___________

A

recursively

40
Q

A binary tree consists of a collection of elements or nodes , with each node linked to _____________ successors

A

at most two

41
Q

What is the root of a tree hierarchy?

A

The node at the top of the tree

42
Q

The successors of a tree node called it’s

A

children

43
Q

Each node in a tree has exactly _____ parent except for the root node which has no parent

A

one

44
Q

node that has no children is called a

A

Leaf node

45
Q

In recursive fashion, the child of a node is considered the root of a ________ of that node

A

subtree

46
Q

Three common kinds of tree traversal

A

Inorder
Preorder
Postorder

47
Q

In a preorder traversal the first node we visit is always

A

The root

48
Q

In a postorder traversal the last node we visit is always

A

The root

49
Q

In a binary search tree, all elements in the left subtree _________ those in the right subtree

A

Precede

50
Q

A binary search tree is an “________” tree, which never has to be sorted because its elements always satisfy the “________” requirement

A

ordered

51
Q

When new elements are inserted (or removed) properly, the binary search tree _________ its property

A

maintains

52
Q

The TreeSet class implements the Set interface by storing elements in a

A

balanced Binary Search Tree

53
Q

As elements are added to / removed from the TreeSet, the class may __________ nodes so that the tree remains balanced

A

rearrange

54
Q

A class of objects added to a ________ must provide a way to “compare” objects

A

TreeSet

55
Q

Given an object to be added to a TreeSet or TreeMap , we must be able to determine if the new object is

A
  • 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
Q

Classes (such as String) that implement the Comparable interface must define a ___________ method

A

compareTo

57
Q

Method obji.compareTo (obj2) returns an integer with the following values

A

Negative if obj1 < obj2
Zero obj1=obj2
Positive if obj1>obj2

58
Q

Implementing the __________ interface provides a way to compare objects during a search

A

Comparable